-
Notifications
You must be signed in to change notification settings - Fork 8
Home
Dirmi is replacement for Java RMI which supports bidirectional remote objects and many more features, including:
- Asynchronous methods
- Remote call timeouts
- Customizable remote exceptions
- Callbacks
- Streams
- Completion queues
- Batched methods
- Disposable objects
- Closeable sessions
- Thread pool constraints
- Custom class loaders
- Download Dirmi and download Cojen
- Dirmi Concepts
- Javadocs
- Coding Patterns
- GitHub project
- FAQ
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
Dirmi is a high performance RMI replacement, outperforming it and other similar frameworks. Results can be found on the Performance page.