Question

Hi everyone I am currently undertaking a project that involves extensive use of Java RMI and I was wondering if anyone is aware of any good resources about it.

The problem I am having with the material I am finding currently is that its usually quite out of date (like Java 1.3) and / or half complete. I would even be happy to buy a book on it but looking on Amazon all the books are like 7 years old.

So if anyone is aware of any good resources, books or good example implementations I would be very interested to hear about them. Thanks in advance for your help.

Was it helpful?

Solution

RMI Hello World looks nice for a start. Of course it's still a simple example, so maybe tips on RMI performance/scalability will be useful since you're already familiar with RMI.

OTHER TIPS

The Java.RMI has changed very little over the years, so most of the old documentation can still be referenced. Note that one significant change is the need to compile the RMI stubs if you are using a version of Java 5.0. Most people have moved away from RMI and have embraced River (previously called Jini) for distributed systems.

If you are still thinking of moving forward with RMI then I would suggest reading the Oracle documentation or posting your questions on their forums.

As for books… Java RMI by William Grosso or Java Network Programming by Elliotte Harold.

RMI hasn't changed that much. I think 1.3 era books will be just fine.

Thank you all for your answers I think what people said about RMI not having changed much is correct, however the tutorials could still be a bit better they gloss over some important points.

In the end the best book by far that I found, that covers some of the really good bits of RMI such as Activation was Java Network Programming and Distributed Computing.

I did look at the other O'reilly Java RMI book and in my opnion its not very good at all, for anything bigger than the smallest of RMI projects.

If you are going to make heavy use of RMI, I would suggest having a look at Spring Remoting. It helps a lot in abstracting the remoting protocol, help you switch remoting implementation later if you need to (for example switch to Hessian, or SOAP).

One thing to keep in mind if you use RMI or any other remote object protocol, is that you can generate a lot of traffic by calling methods on remote objects. It might not be obvious in your code that those objects are remote. It might generate performances problems.

If you can, I would advise you to have a architecture more or less service oriented, where you call remote services to get data object, but not to have too much behaviour on those objects ...

Have you tried Sun't RMI tutorial? The Sun tutorials are all very good, and they're usually the first place I start for learning anything about Java.

A book that we used in school that has good example code is J2EE Developer's Handbook. Bear in mind that this is a huge reference book of about 1500 pages with only one chapter (about 50 pages) on RMI.

The O'Reilly RMI book is pretty good. Go for it.

Absolutely invaluable article on multi homed RMI (hosts with multiple IPs) Explains RMI in a very easy to understand way and goes into the issues of hosting registries on machines with more than a single IP address and how private IPs can be dealt with too. Saved my bacon.

In addition to the ones already mentioned, the article Understanding Java RMI Internals was quite decent IMHO, going a little bit through the internals.

Here is another good example of remote method invocation with Redisson framework:

Let's assume YourServiceImpl contains method you need to invoke remotely and implements YourService interface.

YourServiceImpl should be registered in Redisson via RemoteService object:

YourService yourService = new YourServiceImpl();

RRemoteService remoteService = redisson.getRemoteService();
remoteService.register(YourService.class, yourService);

To invoke method remotely only service interface is needed:

RRemoteService remoteService = redisson.getRemoteService();
YourService service = remoteService.get(YourService.class);

MyObject result = service.myMethod(someParam1, someParam2);

Also it supports asynchronous calls.

// async interface for YourService
@RRemoteAsync(YourService.class)
public interface YourServiceAsync {

    RFuture<Long> someMethod1(Long param1, String param2);

    RFuture<Void> someMethod2(MyObject param);

}

RRemoteService remoteService = redisson.getRemoteService();
YourServiceAsync asyncService = remoteService.get(YourServiceAsync.class);

RFuture<Long> res = asyncService.someMethod1(12L, "param");
res.thenApply(r -> {
 ...
});

More details here

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top