Transports

Overview

JRemoting has a number of 'transports' to connect clients to servers. Some of the work over the internet, some are for more local situations.

Socket Transport

This will work over the internet or an intranet, between two different machines.  It will also work between two different processes on the same machine.

Server side usage

server = new SocketServer(new ConsoleServerMonitor(), 
                          new InetSocketAddress(portNum));

Client side usage

serviceResolver = new ServiceResolver(new SocketTransport(new ConsoleClientMonitor(), 
                                                          new SocketDetails("somehost.com", portNum)));

Secure Socket Transport

As above, but using SSL.  You need to set the keyStore and/or trustStore for the VM in question.

Server side usage

Pass these to java as env vars:
-Djavax.net.ssl.keyStore=/path/to/keyStore 
-Djavax.net.ssl.keyStore=/path/to/trustStore 
-Djavax.net.ssl.keyStorePassword=yourPassword

server = new SSLSocketServer(new ConsoleServerMonitor(), new InetSocketAddress(portNum));

Client side usage

serviceResolver = new ServiceResolver(new SSLSocketTransport(new ConsoleClientMonitor(), 
                                                             new SocketDetails("somehost.com", portNum)));

Piped Transport

Using Java's built-in pipes, this transport will join two parts of the same application with RPC.  Interestingly you could have a large hierarchy of clasloaders with the objects to be serialized duplicated in the tree (once for client side, once for server side) and it would work. Perhaps even if they were different versions of the same jar.  Pipes offers some natural threading to the two sides of the application.

Usage

PipedServer server = new PipedServer(new ConsoleServerMonitor(), new InetSocketAddress(portNum));

PipedInputStream in = new PipedInputStream();
PipedOutputStream out = new PipedOutputStream();
server.makeNewConnection(in, out);

serviceResolver = new ServiceResolver(new PipedTransport(new ConsoleClientMonitor(), in, out));

Direct Transport

Directly wiring a JRemoting server to a client mostly serves as a quality/development consideration for us.  The transport is very fast as no serialization is taking place.  If you can find a use for it, you will note that you can't have a complex classloader design for this.

Usage

server = new DirectServer((ServerMonitor) mockServerMonitor.proxy());
serviceResolver = new ServiceResolver(new DirectTransport(new ConsoleClientMonitor(), server));

Direct Transport - marshaled

As above, but with a deliberate serialize/deserialize step.  Again of marginal use for the end user compared to sockets/pipes. This one could leverage a hierarchy of classloaders. Specifically, the things that would be serialized and/or the facade in question could be duplicated within the app, as long as they are are not in the same branch of a classloader tree.

Usage

server = new DirectMarshalledServer((ServerMonitor) mockServerMonitor.proxy());
serviceResolver = new ServiceResolver(new DirectMarshalledTransport(new ConsoleClientMonitor(), server));

Over RMI

This is just like the Socket based transports, except that it leverages classic RMI for the transport.

Server side usage

server = new RmiServer(new ConsoleServerMonitor(), 
                          new InetSocketAddress(portNum));

Client side usage

serviceResolver = new ServiceResolver(new RmiTransport(new ConsoleClientMonitor(), 
                                                          new SocketDetails("somehost.com", portNum)));

Using Apache Mina for NIO on the server side

This is just like the Socket based transports, except that it on the server side Apache Mina is used to leverage NIO. This does not have as fast throughput as plain sockets, it is just able to scale to more concurrent connections

Server side usage

server = new MinaServer(new ConsoleServerMonitor(), 
                          new InetSocketAddress(portNum));

Client side usage

serviceResolver = new ServiceResolver(new SocketTransport(new ConsoleClientMonitor(), 
                                                          new SocketDetails("somehost.com", portNum)));

Servlets

Todo

Comparative speeds

On a single MacBook Pro (2.16Ghz Core2Duo) with server and client on the same machine.

JRemoting Transports

ByteStream or ObjectStream Piped types - 4,500 reqs/sec
ByteStream or ObjectStream over Socket types (incl SSL) - 2,800 reqs/sec
ByteStream or ObjectStream with Mina server - 2,100 reqs/sec
XStream over Sockets - 1,800 reqs/sec
Over classic RMI - 2,100 reqs/sec
Direct - 120,482 reqs/sec
Direct Marshalled - 6,906 reqs/sec

Non RPC (for comparison)

Dynamic proxy - 7 million reqs/sec
Hand-coded proxy - 109 million reqs/sec
Directly wiring client to server (no proxy, no nothing) - 551 million reqs/sec