Skip to content
Brian S. O'Neill edited this page Jun 2, 2013 · 16 revisions

Dirmi is replacement for Java RMI which supports bidirectional remote objects and many more features, including:

Dirmi is designed for high performance, and it exceeds the performance of Java RMI. Unlike RMI, Dirmi does not have any firewall restrictions. Only one port needs to be opened for accepting sockets, and both client and server can export remote objects through it.

Links

Sample

Dirmi is superficially similar to Java RMI in that it requires interfaces to define remote objects. Like RMI, the interface must extend java.rmi.Remote, and each method must declare throwing the checked exception, java.rmi.RemoteException. Dirmi does allow alternate exceptions to be declared however.

Here's a simple example interface, which is defined exactly the same as for RMI:

 public interface RemoteExample extends Remote {
     String talk(String name) throws RemoteException;
 }

Everything else looks different from RMI. The server implementation of the interface looks like so:

 public class RemoteExampleServer implements RemoteExample {
     public static void main(String[] args) throws Exception {
         Environment env = new Environment();
         RemoteExample server = new RemoteExampleServer();
         env.newSessionAcceptor(1234).acceptAll(server);
     }
 
     public String talk(String name) {
         return "Hello " + name;
     }
 }

The Environment is a sharable object containing open sessions and pooled threads for executing them. The example is accepting any session on port 1234, and then sending a shared instance of the server to it. Sessions remain open as long as both endpoints are alive and have not explicitly closed it. The client code for establishing the session and receiving the remote object looks like:

 public class RemoteExampleClient {
     public static void main(String[] args) throws Exception {
         Environment env = new Environment();
         String host = args[0];
         Session session = env.newSessionConnector(host, 1234).connect();
         RemoteExample example = (RemoteExample) session.receive();
 
         String response = example.talk("Dirmi");
         System.out.println(response);
 
         env.close();
     }
 }

Like the server, the client needs an Environment for managing sessions. Upon establishing a session, it receives the object sent by the server and casts it to the expected type. The last line in the example explicitly closes the environment, which is required for the JVM to exit promptly. Running the client example produces this output:

 Hello Dirmi

Performance

Dirmi is a high performance RMI replacement, outperforming it and other similar frameworks. Results can be found on the Performance page.

Clone this wiki locally