- Run Server.Main
- Run Client.Main
-
Should extends Remote each remote method should throws RemoteException, example Service.java
-
Control flow can be changed using annotations on remote method interfaces
@OneWayRemoteCall
mark method as one way (not waiting for an answer),AsyncRemoteCall
returns the result in a Java Future.
-
Configuration of LRMI is done using the class
NIOConfiguration
this configuration is passed in when the Exporter is created and from there it passed on to the clientsExporter exporter = new GenericExporter(NIOConfiguration.create());
. -
The GenericExporter is used to export implementation of remote, it is doing couple of things:
-
Save the handled object in an LRMI map to be used when invoked from network (or embedded)
-
Index all the method for fast access.
-
Create and return an Remote object that when serialized save the address and Id to the original object, this is actually the proxy that can passed to the clients, it can passed serialized as a sequence of bytes throw a global repository in the network or as in our example in a file.
-
-
The Proxy Generation
The idea is to use Java DynamicProxy and provide an InvocationHandler that know how to call back to the server using local LRMI.
Our Invocation handler is the class DynamicSmartStub it is serailized so it can be sent to remote clients as blob and handle the calls back to the server using its invoke method.
It is wrapped inside a Dynamic proxy it implements all the Interfaces that marked as Remote in the exported Object.
It uses the writeExternal / readExternal trick to execute code when deserialize, the local LRMI node is created from this class if needed.
Initialization is triggered by call on proxy method Connection to the server is done using the class CPeer The main method to send a request to the server is invoke The class uses Reader and Writer to send and read bytes to the other side. Using handshake to prevent buffer overflow when receiving broken messages. And write bytes
Pivot is the class that manage the socket at the server side handleRequest is the method that get the RequestPacket dispatch it to the remote object and send the result replyPacket [consumeAndHandleRequest] is where the Pivot forward the invoke to the RMI Runtime Each ReadSelectorThread holds an internal Pivot that being used whenever there are some bytes in the channel (socket)
The first 4 bytes contains the message size, the next bytes are serialized RequestPacket / ReplyPacket
- The protocol does not support pipeline therefore it uses lots of system resources under load.
- The protocol does not enable custome serialization.
- It is not possible to negotiate connection filters/setting upon opening.
- does not allow different filters stack per message.