• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Rookie questions: RMI operation.

 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, guys.

When RMI protocol is implemented for the Assignment, I am curious about one thing: when client invokes a server-side method, how does it get the output? is the output automatically piped over to the client, or does the server need to provide some code?

If this question looks moronic, that's because it is, unfortunately Help needed.

Thanks.

Anton.
 
Hanna Habashy
Ranch Hand
Posts: 532
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi Anton:
When you create the RMI server, you must provide an interface that extends Remote interface. Also, you must provide a class that implements the provided interface and UniCastRemoteObject interface. RMI marsh (serialize) objects and send them over the wire; these object must implement Serializable interface. YOu don't need to write any other special code to marsh and unmarsh objects, unless you are using sockets and not RMI.
 
Jon Entwistle
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anton,


when client invokes a server-side method, how does it get the output? is the output automatically piped over to the client, or does the server need to provide some code?


OK - all of the code for the remote objects is on the server. The only thing needed on the client are what is called stubs which are generated by the rmic command from the compiled remote classes.

Technicaly what is happening is that the JVM on the client creates proxies for the remote objects from these stubs. (In fact the actual objects never leave the server, but the other objects on the client do not know need to know this).

Right, when you invoke a method on the remote object, the method name and arguments are sent back over the network to the server where the method is actually executed. The return from the method is then sent back to the client, again over the network.

Remember that if an object passed as a paremeter to, or which is returned by a remote method, then it must either implement Remote or be Serializable. (If it implements Remote, just a reference to the object is sent. If the object implements Serializable, then a copy of the object itself is sent).

Bear in mind that I am no master on RMI but is this enough to answer your question?


If this question looks moronic, that's because it is, unfortunately Help needed.


I would hazard a guess that most of the people doing the cert have had little prior experience in RMI, me included


Regards,

Jon
[ July 21, 2004: Message edited by: Jon Entwistle ]
 
Anton Golovin
Ranch Hand
Posts: 527
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, I was wondering about two things:

1) how do objects get fro; and

2) how to distinguish passing by reference and value.

Thanks for clarifying it for me!

Sincerely,

Anton.
 
Jon Entwistle
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Anton,


1) how do objects get fro; and


If they are serialized, then the state of the object is sent bit by bit over the network, a bit like the teleporter in start-trek . The marshal process works out what the other end of the connection needs to reconstitute the object, and sends it. WHat gets sent? The state of the object minus any static fields or fields marked as transient. Note that the definition of the object does not need to be sent as (as far as I underestand) it is contained in the stub.

If the object implements Remote, only a reference (called a handle) to the remote object is sent. In this case, the object is only in the JVM of the server, however the client can access this remote object from its handle.

Primitive values are copied directly from one JVM to the other.


2) how to distinguish passing by reference and value.



Pass by reference means just that - a reference to an object is passed. This happens in all method calls involving objects in Java (in a single JVM). Pass by value means making a copy of the argument object (not just a reference to the object) and sending that.

Regards,

Jon
 
Ben Ritchie
Ranch Hand
Posts: 98
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Anton - try running rmic with the -keep option. This keeps the stub and skeleton source code, rather than just generating .class files. It's not very nice code to look at (a C- for code style!) but you can see how it all works.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic