0

I have a program in which there are these classes:
RMIServer,
RMIClient,
RMIImplementation,
RMIInterface

which are as follows:

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" ) ;
}

RMIInterface:

public interface RMIInterface extends Remote
{
  String issueLicense ( String name , int age ) throws RemoteException ;
}

RMIImplementation:

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. 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)
Mahdi
  • 251
  • 2
  • 12

1 Answers1

1

Your question goes all over the place, but your actual objective can be met with

-Djava.rmi.server.logCalls=true

at the server.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Thanks for the reply, but this command does not show any information about the calls made to the remote object. There must be a mechanism through which the server must be able to get a summary of the calls made from the client. I want an output like the example. – Mahdi Jan 03 '13 at 13:08
  • @mahdisaeedi I don't know what you're talking about. That system property does exactly what it is documented to do, which is exactly to 'show information about remote calls made to the remote object'. You have to set it in the server JVM. You may think there must be another mechanism designed according to your own preconceptions, and your own preconceived output format, but there isn't. There's nothing stopping you logging your own calls in that format, or any other. – user207421 Jan 04 '13 at 19:15