[英]Remote Method Invocation(RMI) - how the server knows what the client invoked?
我有一個程序,其中包含這些類:
RMIServer,
RMIClient,
RMII實施
RMI接口
如下:
RMIServer:
public static void main ( String args[] ) throws Exception
{
System.out.println( "RMI Server started" ) ;
String codebase = "http://localhost:8080/rmi/" ;
String name = "RMIInterface" ;
System.setProperty ( "java.rmi.server.codebase" , codebase ) ;
RMIImplementation obj = new RMIImplementation() ;
RMIInterface stub = (RMIInterface) UnicastRemoteObject.exportObject( obj , 0 ) ;
LocateRegistry.getRegistry().bind( name , stub ) ;
System.out.println( "Done!" ) ;
}
RMIClient:
public static void main ( String args[] ) throws Exception
{
String host = "localhost" ;
String name = "RMIInterface" ;
Registry registry = LocateRegistry.getRegistry( host ) ;
RMIInterface i = (RMIInterface) registry.lookup( name ) ;
System.out.println("RMI service call result:");
for(Candidate c : list){
if(c.status == Candidate.Eligibility.ELIGIBLE ){
System.out.println( " Issued a license to " + i.issueLicense(c.name, c.age) ) ;
}
}
System.out.println( "License Server finished" ) ;
}
RMI接口:
public interface RMIInterface extends Remote
{
String issueLicense ( String name , int age ) throws RemoteException ;
}
RMII實施:
public class RMIImplementation implements RMIInterface {
public RMIImplementation() {
System.out.println("RMIImplementation instance created and ready to serve");
}
@Override
public String issueLicense(String name, int age) {
return name + " (" + age + ")";
}
}
(該程序用於測試。測試在一台機器上完成。)
好吧,客戶端調用遠程對象,發送一些參數。
我希望RMIServer打印出從客戶端到遠程對象的調用摘要。 我應該怎么做才能獲得這些信息?
我希望輸出看起來像這樣:
RMI Server started
RMIImplementation instance created and ready to serve
RMI service called for :
tonny (30)
john (26)
您的問題無處不在,但可以滿足您的實際目標
-Djava.rmi.server.logCalls=true
在服務器上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.