What about arguments and return values?

Note

The stub and skeleton are in it for the whole round trip. They’re both responsible for packing and unpacking the values shipped over the wire.

But it won’t work if the arguments and return values aren’t shippable.

Shippable values must be one of these:

  • Primitives

  • Serializable objects

  • An array or collection of primitives or Serializable objects

  • A Remote object

Remote method calls are just like local method calls, except for the RemoteExceptions. And what good would a method call be if you couldn’t pass arguments or get a return value? You might as well be doing RPC[5], the way your parents did.

This brings us to one of the key jobs for the stub and the skeleton (or whatever is doing the skeletonish things)—packing and unpacking values shipped over the wire.

Remember, the client is really calling a method on the stub, and the stub is local to the client (i.e. in the same heap). So, from the client’s perspective, there’s nothing special about sending arguments with the method. It’s the stub that does all the dirty work. The stub has to package up the arguments (through a process known as marshalling) and send them in the output stream, through the Socket connection with the server.

The skeleton-thing on the server has to process the stream from the stub, unpack the arguments, figure out what to do with everything (for instance, which method to call on which object), and then invoke the method (a local call) on the Remote object, with the arguments. ...

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.