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 havi
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
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 ...
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.
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.
Here is the article with Images from the way back archive.
The O'Reilly RMI book is pretty good. Go for it.