0

これらのクラスがあるプログラムがあります:
RMIServer、
RMIClient、
RMIImplementation、
RMIInterface

次のとおりです。

RMI サーバー:

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

}  

RMI クライアント:

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

RMI実装:

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

(このプログラムはテスト用です。テストは 1 台のマシンで行われます。)

クライアントはリモート オブジェクトを呼び出し、いくつかのパラメーターを送信します。

クライアントからリモート オブジェクトへの呼び出しの概要を RMIServer に出力させたいと考えています。そのような情報にアクセスするにはどうすればよいですか?

出力を次のようにしたい:

RMI Server started
RMIImplementation instance created and ready to serve
RMI service called for : 
  tonny (30)
  john (26)
4

1 に答える 1

1

あなたの質問はいたるところにありますが、実際の目的は満たすことができます

-Djava.rmi.server.logCalls=true

サーバーで。

于 2013-01-01T22:12:44.507 に答える