refcodes-remoting: Face-to-face lightweight remote method calls

refcodes-remoting: Face-to-face lightweight remote method calls

README

The REFCODES.ORG codes represent a group of artifacts consolidating parts of my work in the past years. Several topics are covered which I consider useful for you, programmers, developers and software engineers.

What is this repository for?

The refcodes-remoting artifact is a lightweight RPC (remote procedure call) framework; you may also call it an IPC (inter process communication) tool-kit. On your server you publish any instance (any Java object), on your client you may access this instance via a proxy object which looks and feels exactly as the remote instance on the server.

Publish an instance (just any Java object) on your server, connect to it on your client via a proxy - voilà, you may do remote method calls via the proxy on the instance … just with a few lines of code …

This proxy provides your client exactly the same methods as the instance offers on the server. Invoking any of them methods on the proxy at the client actually causes the according method on the remote instance at the server to be processed. Voilà, there is your remote procedure call!

Neither stubs nor skeletons to be generated anywhere, no need for you to generate any code.

The refcodes-remoting can be attached to virtually any kind of connection (implement your own! See refcodes-connection …):

  • Loopback connection: Direct object access on the same JVM (see LoopbackRemoteTest source codes)
  • Input-/OutputStream: Anything which is a Java InputStream/OutputStream can be used (see IoStreamRemoteTest source codes)
  • Socket: Use Java’s ServerSocket / (Client-)Socket mechanism (see ObservableSocketRemoteTest source codes)

The refcodes-remoting-ext-observer provides an observable implementation (as of the refcodes-observer artifact) of the refcodes-remoting tool-box.

Yes, it’s observable: You get events when a client subscribes (you may veto the subscription in your listener) to an instance on your server or when it unsubscribes …

How do I get set up?

To get up and running, include the following dependency (without the three dots “…”) in your pom.xml:

1 <dependencies>
2   ...
3   <dependency>
4     <artifactId>refcodes-remoting</artifactId>
5     <groupId>org.refcodes</groupId>
6     <version>1.1.7</version>
7   </dependency>
8   ...
9 </dependencies>

The artifact is hosted directly at Maven Central. Jump straight to the source codes at Bitbucket. Read the artifact’s javadoc at javadoc.io.

How do I get started?

First setup your server; we start off with a socket based example; using streams is even simpler. Create your server and publish the object you’d like to be invoked remote by a client:

1 ...
2 List<String> theServerList = new ArrayList<String>();
3 RemoteServer theServer = new RemoteServerImpl();
4 theServer.publishSubject( theServerList );
5 ...

Then you wait for your client to connect to your ServerSocket. From the Socket created upon connection you create an InputOutputTransceiver which is used to open your Server:

1 ...
2 ServerSocket theServerSocket = new ServerSocket( 5161 );
3 Socket theSocket = theServerSocket.accept();
4 InputOutputStreamTransceiverImpl<Serializable> theServerTransceiver = new InputOutputStreamTransceiverImpl<Serializable>();
5 theServerTransceiver.open( theSocket.getInputStream(), theSocket.getOutputStream() );
6 theServer.open( theServerTransceiver );
7 ...

Next you setup your client. You create a Socket to your server from which you produce an InputOutputTransceiver which is used to open your Client

1 ...
2 RemoteClient theClient = new RemoteClientImpl();
3 Socket theClientSocket = new Socket( "localhost", 5161 );
4 InputOutputStreamTransceiverImpl<Serializable> theClientTransceiver = new InputOutputStreamTransceiverImpl<Serializable>();
5 theClientTransceiver.open( theClientSocket.getInputStream(), theClientSocket.getOutputStream() );
6 theClient.open( theClientTransceiver );
7 ...

Now you can invoke the methods provided by the theServerList on your client by retrieving the according proxy:

1 ...
2 // Iterator<Object> theProxies = theClient.proxies();
3 if ( theClient.hasProxy( List.class ) ) {
4   List<?> theProxyList = theClient.getProxy( List.class );
5 }
6 ...

That’s it! Full examples tweaked to run as unit tests on a single machine you’ll find here:

Contribution guidelines

  • Implement other connection types (state-less HTTP, XML-over-stream)
  • Provide some ServerSocket based server which you just start for it to serve the objects to be published. For example some wrapper service could create new server instances upon new client connections or the server could be extended to handle more than one open connections …
  • Writing tests
  • Code review
  • Other guidelines

Who do I talk to?

  • Siegfried Steiner (steiner@refcodes.org)

Terms and conditions

The REFCODES.ORG group of artifacts is published under some open source licenses; covered by the refcodes-licensing (org.refcodes group) artifact - evident in each artifact in question as of the pom.xml dependency included in such artifact.

comments powered by Disqus