SimpleMessageReceiver.java



/** MessageReceiver の実装の試作品のクラス */
import java.rmi.*;
import java.rmi.server.*;
public class SimpleMessageReceiver extends UnicastRemoteObject
                                   implements MessageReceiver {
  /** コンストラクタ */
    public SimpleMessageReceiver( String serverName, String myName )
                                              throws RemoteException {
        super();
        try {
            Naming.rebind( myName, this );
            TalkServer server = (TalkServer)Naming.lookup( serverName );
            server.addMessageReceiver( myName );
        }
        catch( RemoteException e ) {
            throw e;
        }
        catch( Exception e ) {
            System.out.println( "Error:" + e.toString() );
        }
    }

  /** 新しいメッセージを処理するメソッド */
    public void updateMessage( Message message )
                               throws RemoteException {
        System.out.println( message.getHeader()
                  + ">> " + message.getContent() );
    }
}