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?
This artifact is a lightweight RPC
(remote procedure call) toolkit (you may also call it an IPC
(inter process communication) toolkit). 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.
How do I get set up?
To get up and running, include the following dependency (without the three dots “…”) in your pom.xml
:
1
2
3
4
5
6
7
8
9
<dependencies>
...
<dependency>
<artifactId>refcodes-remoting</artifactId>
<groupId>org.refcodes</groupId>
<version>3.0.0</version>
</dependency>
...
</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.
Introduction
Publish an
instance
(just any Java object) on yourserver
, connect to it on yourclient
via aproxy
- voilà, you may do remote method calls via theproxy
on theinstance
… 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.
This toolkit can be attached to virtually any kind of connection (implement your own):
- 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 mayveto
the subscription in your listener) to aninstance
on yourserver
or when it unsubscribes.
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
3
4
5
...
List<String> theServerList = new ArrayList<String>();
RemoteServer theServer = new RemoteServerImpl();
theServer.publishSubject( theServerList );
...
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
3
4
5
6
7
...
ServerSocket theServerSocket = new ServerSocket( 5161 );
Socket theSocket = theServerSocket.accept();
InputOutputStreamTransceiverImpl<Serializable> theServerTransceiver = new InputOutputStreamTransceiverImpl<Serializable>();
theServerTransceiver.open( theSocket.getInputStream(), theSocket.getOutputStream() );
theServer.open( theServerTransceiver );
...
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
3
4
5
6
7
...
RemoteClient theClient = new RemoteClientImpl();
Socket theClientSocket = new Socket( "localhost", 5161 );
InputOutputStreamTransceiverImpl<Serializable> theClientTransceiver = new InputOutputStreamTransceiverImpl<Serializable>();
theClientTransceiver.open( theClientSocket.getInputStream(), theClientSocket.getOutputStream() );
theClient.open( theClientTransceiver );
...
Now you can invoke the methods provided by the theServerList
on your client
by retrieving the according proxy
:
1
2
3
4
5
6
...
// Iterator<Object> theProxies = theClient.proxies();
if ( theClient.hasProxy( List.class ) ) {
List<?> theProxyList = theClient.getProxy( List.class );
}
...
That’s it! Full examples tweaked to run as unit tests on a single machine you’ll find here:
Contribution guidelines
- Writing tests
- Code review
- Adding functionality
- Fixing bugs
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.