Questions about a simple RMI example

J

John A. Bailo

I compiled and ran the code in:

http://www.comp.hkbu.edu.hk/~jng/comp3320/rmi.html


One question is: in order to run the client, it seems to need the
SampleServer.class (which contains the remoted method) in the same
directory.

How can I make it so that the SampleClient can run alone. I want to be
able to make changes to the SampleServer without having to copy a new
..class to the remote client with every change.
 
V

VisionSet

John A. Bailo said:
I compiled and ran the code in:

http://www.comp.hkbu.edu.hk/~jng/comp3320/rmi.html


One question is: in order to run the client, it seems to need the
SampleServer.class (which contains the remoted method) in the same
directory.

That is the remote interface.
How can I make it so that the SampleClient can run alone. I want to be
able to make changes to the SampleServer without having to copy a new
.class to the remote client with every change.

You must have the remote interface accessible on the client, because the
stub that is auto generated for you on the client will implement that
interface. There is no way round this.

Note it is just an interface the implementation is in the class
SampleServerImpl which can be left entirely serverside.

Also note the demo code you reference is very simple pattern and there are
better ways to decouple rmi from the business interface you want to provide.

My personal favorite way to do this is via what I call the mirrored
interface pattern:

http://i1.tinypic.com/xknpcz.png
 
J

John A. Bailo

VisionSet said:
That is the remote interface.

Ok, I see now.

So I can change the ...Impl.class to change the implementation, but I
always need the /stub/, SampleServer.class near the client.

Thanks!!!
Note it is just an interface the implementation is in the class
SampleServerImpl which can be left entirely serverside.

Also note the demo code you reference is very simple pattern and there are
better ways to decouple rmi from the business interface you want to provide.

My personal favorite way to do this is via what I call the mirrored
interface pattern:

http://i1.tinypic.com/xknpcz.png

WOW!

Is there a book that goes along with that UML ?

:D
 
V

VisionSet

WOW!

Is there a book that goes along with that UML ?

Well...

Remote is java.rmi.Remote
my DBRemote is your SampleServer
my DBRemoteImpl is your SampleServerImpl
my DBRemoteImpl_Stub is generated automatically by the RMI 'engine' as is
yours, you can't see it, but this is what you get when you do
Naming.lookup(), it is the object you get from this that implements your
remote interface (SampleServer) and this is why you need it on the client.
But, also the server too!
That just leaves my DBClient interface, DataAdapter and RemoteDBClient
classes that you don't have and these are specifically to decouple both
client and server side code from the RMI API. The classes implement
DBClient, which is a copy of the DBRemote, except no RMIExceptions are
thrown so therefore, it is not dependent on RMI code. The classes then wrap
a remote reference (stub or skeleton) one on the server side and one on the
client side. DataAdapter does the real server buisness work, while
DBRemoteImpl adapts this to RMI. RemoteDBClient wraps the stub and strips
out all the RMIExceptions and passes them to clients as some
IDontCareWhatCausedThisButThereWasSomeGeneralTransportException.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,680
Members
48,796
Latest member
Greg L.

Latest Threads

Top