Why I don't like Java RMI and how I use it anyways

The Java Remote Method Invocation API is a great thing to have because it is available in almost every J2SE runtime environment without adding further dependencies. However there are some implications when using RMI and I just cannot get my head around them:

  1. Interfaces used as remote interfaces need to extend java.rmi.Remote. Interfaces should be clean and not contain any clutter introduced by a certain technology. This is even more true with modern frameworks and things like dependency injection.
  2. Remote methods need to declare java.rmi.RemoteException in their throws clause. This is basically a continuation of the first point. This point holds, even if you ignore the rant about checked exceptions, which I don’t want to comment on right now.
  3. Remote objects need to be exported explicitly. Even though one explicitly declared which methods should be accessible from a remote site with the above two points, one still needs to explicitly export every single instance of an object implementing those methods.

Don’t get me wrong, all those implications have their right to exist because the decisions leading up to them were made for a reason. But in some circumstances those reasons don’t apply. It is just not the one-to-rule-them-all solution for remote method invocation in Java.

There are ways around those problems. One could for instance duplicate the existing interfaces to fit the needs of RMI. But frankly speaking, I just don’t want to do that myself.

That being said, lets see if the task of separating the transportation layer based on RMI from your precious interfaces can be automated in some way, so it doesn’t have to be done by hand. The following are the key points of the approach:

  • Interfaces can explicitly be marked as remote interfaces at runtime without the need for recompiling them. All methods exposed by such an interface can be invoked from a remote site. All parameters which are subclasses of such interfaces, will be passed by-reference and will not be serialized. This is just the same behavior as if the interface would extend java.rmi.Remote in the RMI world. The actual remote interfaces are generated on-demand at runtime.
  • Provide a proxy factory which supports the rapid development of a transportation layer based on RMI for given clean interfaces. The interface classes do not need to be cluttered with specifics of the transportation implementation.
  • A proxy in this context is a transparent object implementing both, the local and the generated remote interface. Both interfaces are usable:
    • Cast the proxy to java.rmi.Remote and use it with any naming or registry service available to the RMI world. Every proxy implicitly is a remote object without the need for explicitly exporting it.
    • Cast the proxy to your local interface and don’t bother whether it actually targets a local or a remote site.
  • The decision how an invocation actually is dispatched can be solely based on whether the target object of a proxy is a remote or a local one. This decision is hidden inside the transportation layer.

Available as a download attached to this post you’ll find a first reference implementation of such a proxy factory as described above. Note that it is just a sketch to illustrate my point and will probably contain major flaws. Also it brings a dependency on Javassist, which kind of contradicts the very first sentence of this post. However it is capable of distributing this tiny example across several sites without modifying the given interfaces, which also represents my only test-case:

public interface Client {
	public void callback(String message);
public interface Server {
	public void subscribe(Client subscriber);
	public void notify(String message);
public class ClientImpl implements Client {
	public void callback(String message) {
		// ... do some important job ...
public class ServerImpl implements Server {
	public void subscribe(Client subscriber) {
		// ... remember "subscriber" in some fancy data structure ...
	public void notify(String message) {
		// ... invoke all "subscribers" like they were local ...

This is my attempt to show how I personally think that RMI should have been designed in the first place. Please feel free to comment, improve, ignore or flame.


Navigating through a new city

Navigating through a new city can be worrisome at times.
Clearly there's a lot of factors that influence the price
of a car service. All this is with the best professional drivers in the finest
vehicles. By offering such elite benefits, business organizations can retain their top officials.
Toyota has wisely observed that the livery and
chauffeured transportation market is an area of opportunity for the new 2013 Avalon.

I read this article

I read this article completely about the difference of hottest
and earlier technologies, it's awesome article.

good post

good post

I would like to thnkx for the

I would like to thnkx for the efforts you've put in writing this site.
I am hoping the same high-grade site post from you in the upcoming also.
In fact your creative writing skills has encouraged me to get my own site now.

Actually the blogging is spreading its wings quickly. Your
write up is a great example of it.

do not be surprised if beauty

do not be surprised if beauty products and skin care products sold in the market. Of the many cosmetic products on the market, http://www.crystalx-yogyakarta.com/2017/08/moreskin-day-cream.html became the choice of many women. Because the cosmetics are made of herbal ingredients of choice so it is safe to use both short and long term

Wonderful post!!! Genuinely

Wonderful post!!! Genuinely loved this kind of post. Although I want much more information on like precious subject matter.

An essay is a piece of

An essay is a piece of structured writing. Usually written in formal academic writing.Analysis of the title. Reason to do extra reading around your subject area Way to assess how well you understand a subject. Method to consolidate the information you acquire in lectures, away on placement or in seminars. Essay writing is a process and needs to be done in various stages. By following the steps of essay writing students can break down the task into manageable parts.