Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / May 2006

Tip: Looking for answers? Try searching our database.

Questions about a simple RMI example

Thread view: 
John A. Bailo - 08 May 2006 22:06 GMT
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.
VisionSet - 08 May 2006 22:11 GMT
> I compiled and ran the code in:
>
[quoted text clipped - 3 lines]
> 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

--
Mike W
John A. Bailo - 08 May 2006 22:25 GMT
> 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.
[quoted text clipped - 6 lines]
>
> http://i1.tinypic.com/xknpcz.png

WOW!

Is there a book that goes along with that UML ?

:D
VisionSet - 09 May 2006 00:59 GMT
> > My personal favorite way to do this is via what I call the mirrored
> > interface pattern:
[quoted text clipped - 4 lines]
>
> 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.

--
Mike W


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.