[英]Remote Method Invocation(RMI) - how the server knows what the client invoked?
I have a program in which there are these classes: 我有一个程序,其中包含这些类:
RMIServer, RMIServer,
RMIClient, RMIClient,
RMIImplementation, RMII实施
RMIInterface RMI接口
which are as follows: 如下:
RMIServer: 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: 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" ) ;
}
RMIInterface: RMI接口:
public interface RMIInterface extends Remote
{
String issueLicense ( String name , int age ) throws RemoteException ;
}
RMIImplementation: 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 + ")";
}
}
(This program is for a test purpose. The test is done in one machine.) (该程序用于测试。测试在一台机器上完成。)
Well, the client makes calls to the remote object, sending some parameters. 好吧,客户端调用远程对象,发送一些参数。
I want the RMIServer to print out the summary of the calls made from the client to the remote object. 我希望RMIServer打印出从客户端到远程对象的调用摘要。 What should I do to have access to such information?
我应该怎么做才能获得这些信息?
I want the output to look like this: 我希望输出看起来像这样:
RMI Server started
RMIImplementation instance created and ready to serve
RMI service called for :
tonny (30)
john (26)
Your question goes all over the place, but your actual objective can be met with 您的问题无处不在,但可以满足您的实际目标
-Djava.rmi.server.logCalls=true
at the server. 在服务器上。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.