commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From (alvin schur)
Subject [PATCH] AltRMI Sample documentation with code skeletons
Date Fri, 01 Mar 2002 15:09:50 GMT

  Sorry about the missing attachment.
  Hopefully the file is attached this time.
  I am including the file in the body as well.
  I am not subscribed to commons-dev.
  BEGIN file --------------------
  See AltRMI proposal for a list of features and goals.

Classes a client uses to connect to a server

          provides host name (IP address), port for connecting to the server
          defines location of generated Proxy class (either on server or client)

Example code from SocketClientTest:

      // connect to localhost, port 1234
      AltrmiHostContext arhc = 
        new SocketObjectStreamHostContext("", 1234);

      // put generated Proxy class on client side
      AltrmiFactory af = new ClientClassAltrmiFactory(false);


      String[] listOfPublishedObjectsOnServer = af.list();
      TestInterface ti = (TestInterface) af.lookup("Hello");

      // now use ti as a local object with method calls sent to the server for
      // execution.

Classes a server uses

          listens for connections from a client and processes the request

Example code from SocketServerTest

      // listen on port 1234
      AbstractServer as = new CompleteSocketObjectStreamServer(1234);

      // create an object to publish
      TestInterfaceImpl ti = new TestInterfaceImpl();

      as.publish(ti, "Hello", new PublicationDescription(TestInterface.class,

      // start the server listening on the socket for client connections

Minimum run loop on server

          reads requests from the client stream and writes the response to the 
client stream
          interprets and executes the client request

Note: this example ignores all error handling, start, stop, kill niceties. See:,
AbstractServer (and subclasses) for error handling examples.

Maybe this code snippet can be embedded in a Servlet (non Http) service method.

      // choose the desired read/writer from the ServerStreamReadWriter
      // subclasses
      ServerStreamReadWriter readWriter;
      readWriter.setStreams( inputStream, outputStream );

      InvocationHandlerAdapter handler = new InvocationHandlerAdapter();

      AltrmiRequest request = null;
      AltrmiReply reply = null;

      while( true ) {
        // get a request 
        // if reply is null then
        //   writeReplyAndGetRequest writes nothing to the client
        // endif
        request = readWriter.writeReplyAndGetRequest(reply);
        reply = handler.handleInvocation(request);
END file -----------------------------

View raw message