What must the Remote object and the stub have in common?

How does the client know which methods to call?

How does the stub know which methods the Remote object has?

Remember, if the stub is pretending to be the Remote object, the stub must have the same methods as the Remote object.

Of course you know the answer to this.

An interface.

The way all methods in a distributed environment should be exposed to a client.

We call this the business interface because it has the business method(s) the client wants to call. Technically, the business interface for a Remote object must be, surprisingly, a Remote interface.

It all begins with a Remote interface. Both the Remote object and the stub implement the same interface... the one with the methods the client wants to call.

A Remote interface must extend java.rmi.Remote and every method must declare a RemoteException.

To be Remote, an interface must follow three rules:

  • it must extend java.rmi.Remote

  • each method must declare a java.rmi.RemoteException

  • arguments and return types must be shippable (Serializable, primitive, etc.)

image with no caption

Get Head First EJB now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.