File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Developer Certification (SCJD/OCMJD) and the fly likes Intermediate RMI interface Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Developer Certification (SCJD/OCMJD)
Bookmark "Intermediate RMI interface" Watch "Intermediate RMI interface" New topic

Intermediate RMI interface

Robin van Riel

Joined: May 04, 2012
Posts: 20

Hi all,

While documenting my OCMJD code I noticed I'm using an empty interface combining the Remote interface defined in java and the SubcontractorService interface I wrote:
public interface RmiSubcontractorService extends Remote, SubcontractorService {}

This combined interface is used by my RmiServer class, which is used to register and unregister the SubcontractorService:
public class RmiServer extends UnicastRemoteObject implements RmiSubcontractorService {

This works just fine, but I wanted to see if the RmiServer class would still work as expected when implementing the combined interfaces directly:
public class RmiServer extends UnicastRemoteObject implements Remote, SubcontractorService {

I was surprised to find this broke the RMI functionality.
That is, the service can be registered, but my RMI client is suddenly unable to find it.

OO wise it doesn't make much sense to me.
Does anyone know if this is an RMI related issue?

Thanks in advance.
Jelle Klap

Joined: Mar 10, 2008
Posts: 1948

A remote object has to implement an interface that extends the Remote interface, and it's true that from the perspective of the remote object it doesn't make a difference whether the interface it implements extends Remote or whether it implements Remote itself as a second interface. However, from the perspective of the remote interface it does make a difference, because that interface is also used to generate stubs, either via rmic or dynamically via java.lang.reflect.Proxy. If the interface didn't extend the Remote interface there would be no way of determining whether it could be used to invoke remote methods. The Remote interface is used as a marker interface.

Edit: just to clarify, Remote interface with the uppercase 'R' refers to java.rmi.Remote and remote interface with the lowercase 'r' refers to the interface that extends java.rmi.Remote.

Build a man a fire, and he'll be warm for a day. Set a man on fire, and he'll be warm for the rest of his life.
Robin van Riel

Joined: May 04, 2012
Posts: 20

I see.
Thanks for clearing that up, Jelle!
I agree. Here's the link:
subject: Intermediate RMI interface
It's not a secret anymore!