Package org.cojen.dirmi
package org.cojen.dirmi
Dirmi is a framework for supporting bidirectional remote method invocation. For launching a
server,
The server-side implementation looks like this:
And here is the client-side implementation:
create
an Environment
, export
a remote object, and start accepting
connections. For
connecting a client, create an Environment
, connect
to
the server, and obtain the root
object. Here is a very simple example,
starting with the remote interface:
import org.cojen.dirmi.Remote;
import org.cojen.dirmi.RemoteException;
public interface HelloDirmi extends Remote {
void greetings(String name) throws RemoteException;
}
import java.net.ServerSocket;
import org.cojen.dirmi.Environment;
public class HelloDirmiServer implements HelloDirmi {
public static void main(String[] args) throws Exception {
Environment env = Environment.create();
env.export("main", new HelloDirmiServer());
env.acceptAll(new ServerSocket(1234));
}
@Override
public void greetings(String name) {
System.out.println("Hello " + name);
}
}
import org.cojen.dirmi.Environment;
import org.cojen.dirmi.Session;
public class HelloDirmiClient {
public static void main(String[] args) throws Exception {
Environment env = Environment.create();
String host = args[0];
int port = 1234;
Session<HelloDirmi> session = env.connect(HelloDirmi.class, "main", host, port);
HelloDirmi client = session.root();
client.greetings("Dirmi");
env.close();
}
}
- See Also:
-
ClassDescriptionDesignates a remote interface as supporting automatic disposal when the client-side object is reclaimed by the garbage collector.Designates a remote method as being batched, which can be used to reduce transport overhead.Defines a custom class loading scheme.Generic exception indicating that a resource is closed.Defines a function which is called whenever client-side socket connections need to be established.Designates a remote method which is just data, which is serialized whenever the remote object is transported over the session.Thrown when calling a
@Data
method when the data isn't available for some reason.Exception which indicates that a session is disconnected, but a reconnect is in progress.Thrown when attempting to invoke a method against a disposed object.Designates a remote method as being aRemote
object disposer, allowing memory to be freed on the remote side.Sharable environment for connecting and accepting remote sessions.Represents an established connection between two endpoints.Designates a remote method which doesn't block reading a reply or acknowledgment.Thrown when attempting to invoke a method against an object that is unknown to asession
.A pipe is a bidirectional stream which supports basic object serialization.Pipe.Decoder<T>Support for efficiently reading complex objects from a pipe.Pipe.Encoder<T>Support for efficiently writing complex objects to a pipe.Marker for designating a remote interface.Defines the default exception for indicating a remote call failure.Annotate a remote method or interface to specify what exception is to be used for indicating a remote call failure.Designates a remote method which returns a remote object which should be restored when a session reconnects.Indicates that a remote method should use Java object serialization for the parameters and return value.Supports writing and reading of object instances to/from a pipe.Session<R>Manages a client-side or server-side remote session, which establishes new socket connections as needed.Indicates the session's current connection state.Remote objects implementing this interface are notified when they are attached and detached from sessions.Designates a remote method which should never be included in abatched
request.Thrown when attempting to invoke a method which is unimplemented on the remote side.