wood burning stoves 2.0*
The moose likes Distributed Java and the fly likes RMI from start to finish Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Distributed Java
Bookmark "RMI from start to finish" Watch "RMI from start to finish" New topic
Author

RMI from start to finish

Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Originally posted by Marilyn deQueiroz:
It's interesting that although I'm starting the server with
start java -classpath %HOME% -Djava.rmi.server.codebase="http://localhost:9999/" mfe.servers.WorkhorseDriver

my output is
rmi://localhost:1099/Processor->Workhorse

rather than
rmi://localhost:9999/Processor->Workhorse

This is correct behavior. The string you're getting back tells you what services are available from rmiregistry, and not from the web server that makes the stub available. rmiregistry by default runs on port 1099.
...I didn't by chance happen to say the result should be "9999"...did I?


Make visible what, without you, might perhaps never have been seen.
- Robert Bresson
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Originally posted by Marilyn deQueiroz:
Well, it seems that the ClientList NEVER notices that the server has gone down.

So, how do we tell the rmiregistry that the server is no longer available?

Indeedy, I think rmiregistry should know, sooner of later, if it's advertising an unavailable service. However, since rmiregistry isn't required to contact the server, and the server code itself isn't re-binding on a periodic basis, there's no way with what we currently have to set this up -- or is there? I mean, you'd think you could tell rmiregistry to "time out" after a certain interval, and force the service to bind again as a way of advertising its aliveness, don't you think? Hmmmmm....
That questions aside for the moment, notice that the Naming class supports an unbind() method. Instead of rudely interrupting our server program with an interrupt, we could bind(), sleep for some amount of time, then call unbind(). Some time after that, we should see no mention of this same service when ClientList goes. That's all there is to it.
I leave it to y'all to play with this on your own. Gotta find me a hotel and rental car in Minneapolis before the night gets too far along.
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
Originally posted by Michael Ernest:
... not from the web server that makes the stub available.

...I didn't by chance happen to say the result should be "9999"...did I?

I don't think you said one way or the other. So the whole purpose of the web server is to make the stub available? I was wondering why we needed one.


JavaBeginnersFaq
"Yesterday is history, tomorrow is a mystery, and today is a gift; that's why they call it the present." Eleanor Roosevelt
Marilyn de Queiroz
Sheriff

Joined: Jul 22, 2000
Posts: 9044
    
  10
So I should be able to give a client at another location just one class (like ClientList) and they can type "java ClientList" and get the list of services from the registry, right?

My understanding is that the webserver has the Stub and the Interface while the rmiserver has the RemoteObject implementation of the interface. So it seems that the webserver is necessary for communication between the client and the rmiserver. Or is that true only in this particular case?

And the webserver doesn't have to be on the same box as the rmiserver, right?
[ February 23, 2002: Message edited by: Marilyn deQueiroz ]
Abdul Salam
Greenhorn

Joined: Feb 25, 2002
Posts: 10
Michael,
This is a humble suggestion about the name of the remote service.
QUOTING YOUR WORDS.
"We would rather use a lookup service, or name-for-service translator, and relax our need to know these things at compile-time. Furthermore, a well-named lookup might do a better job of suggesting a service's uses. When we want a service, the argument goes, we usually know what capability we're looking for (like Processor), but we don't always know the exact implementation name it goes by (Workhorse)."

It's about implementing the service name as a public static final String variable(say SERVICE_NAME)inside the remote interface(service).As RMI requires the remote interface present on client side
lookup can rely on service.SERVICE_NAME


Knowledge Xchange. SCJ2P.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Originally posted by Abdul Salam:

QUOTING YOUR WORDS.
"We would rather use a lookup service, or name-for-service translator, and relax our need to know these things at compile-time. Furthermore, a well-named lookup might do a better job of suggesting a service's uses. When we want a service, the argument goes, we usually know what capability we're looking for (like Processor), but we don't always know the exact implementation name it goes by (Workhorse)."
It's about implementing the service name as a public static final String variable(say SERVICE_NAME)inside the remote interface(service).As RMI requires the remote interface present on client side
lookup can rely on service.SERVICE_NAME

Similar to Map's idea that you could reflect on a stub and determine at run-time what services are available, I don't find fault with this technique other than to ask what the point of it is.
On a design level, hard-coding a name in the class counters the benefit of dynamic discovery. With an intermediary lookup service, you can name services as you wish at binding time, instead of stub-compilation time. Natural language being what is, I contend that it's better to leave such naming agreements until the last minute, instead of compiling them into the service code itself.
[ March 14, 2002: Message edited by: Michael Ernest ]
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Amazing how many distractions can come up in two weeks' time.
Anyway, I'm going to assume now among readers that we're comfortable so far with invoking a method on a remote process. The common bond, to review, is knowledge on both communicating processes of a common interface -- something that describes the form in which mutually-understood communication takes place.
We really have a lot of directions we can go right now, but the place I want to take you is a place where only RMI goes: dynamic stub downloading. Here's the concept:
JVM A (we'll call it Andersen for mnemonic purposes) wants to run a job and track its progress. Andersen is a management thread, so it doesn't want to actually do the work itself; it wants someone else to do the work so it just writes the report, since everyone knows that reporting is just like doing the work, only it pays better.
JVM I (we'll call it IT) processes jobs all day long. It's efficient by virtue of being single-minded and armed with a formidable complex of abilities. However, it also poses the burden of only taking requests that follow a correct, uncompromising and sometimes mysteriously detailed protocol. It hopes to excel by virue of its technical excellence. The IT JVM works harder because hard work means more money. The IT JVM is going to learn a hard lesson one of these days.
Andersen knows once it learns how to ask IT a question, it can get a useful set of answers back. But now Andersen wants to be able to submit a job -- any job -- and have IT process it with results. Andersen, being Andersen, doesn't know much about the job except that it's coming and that he can make money by getting IT to do the work while he takes the credit. Andersen also knows that IT is very particular about protocol. How, oh how, do we solve this problem?
As with all things, all the answers lie not-so-hidden in well-formed questions. If Andersen can establish a general protocol, and promise IT that all subsequent requests will adhere to it, and guarantee that any missing details will also be provided to IT on an as-needed basis, can we do business?
For example, let's say Andersen and IT define the idea of a Job. A Job is any implementing class that contains process(). process() requires an argument, in the form of a Runnable, and returns a Runnable representing the job in post-process form.
The beauty of this arrangement for Andersen is simple; if he can get IT to sign off on the protocol, he's pretty sure he can get IT to do anything the protocol can encapsulate. Something that is Runnable is in fact a pretty general requirement.
Making sense so far?
Thomas Fly
Ranch Hand

Joined: Sep 09, 2002
Posts: 164
Originally posted by Michael Ernest:
That means you need an HTTP server, for our purposes a very light one. So here you go! Don't say I never gave ya nuthin'. This is the same class server offered in Sun's RMI tutorial by Ann Wolrath and Ken Arnold, by the way.

Resurrected the dead link for you- don't say I never gave ya nuthin' hehe.


Fly by Night Consultants<br /> <blockquote><font size="1" face="Verdana, Arial">quote:</font><hr><i>I climbed on the back of a giant albatross<br />which flew through a crack in the cloud<br />to a place where happiness reigned...<br />all year 'round<br />the music played ever so loudly!</i><p><a href="http://thomasfly.com/songs/Traffic/Hole_in_my_Shoe_qt.htm" target="_blank" rel="nofollow">Hole in My Shoe</a><hr></blockquote>
Ellen Zhao
Ranch Hand

Joined: Sep 17, 2002
Posts: 581
Bringing this up to the top so students like me can find it easily.
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Seriously, I never thought the stuff I wrote here was all that good. I'd love to say I'm pleased so many people found it useful, but I don't understand what you're all getting out of it.
Leslie Chaim
Ranch Hand

Joined: May 22, 2002
Posts: 336
Originally posted by Michael Ernest:
Seriously, I never thought the stuff I wrote here was all that good. I'd love to say I'm pleased so many people found it useful, but I don't understand what you're all getting out of it.

Well, now that you know that people find it lot's of use of this why don't you complete this thing. If you really want, I can assist you in finding excuses BTW, I am not sure if you could link to a specific post in a given thread but with the previous link, I refer to the ninth post and your guilty feeling.
Really, I think what people like is your style and liveliness of conversation which gives a class-like-feel learning environment. You should consider writing a book on the topic, I know you like the Pitt book. But I found it very terse and sometimes dull. It is a good book but you must force yourself to read it to get into it. I like to see some humor and some more examples better dissected and more verbose. I think your book would be a hit :roll: and very
Anyway, if you do write a book please let me know I will be the first to get it and I will not wait for a chance to win it at a javaranch promo
hhhhh, the real reason for my post.. There's an article you have written in the Apr 2002 newsletter which is very good.
At the end there's a bad link to this thread:
http://www.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=4&t=000596
It should be:
http://www.coderanch.com/t/208759/java/java/RMI-start-finish
Cheers,
Leslie
[ March 12, 2003: Message edited by: Leslie Chaim ]

Normal is in the eye of the beholder
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

lol, I'd forgotten I even wrote that.
Someone said to me in a class the other week, "done right, it ain't easy" while discussing a certain refactoring method. I looked at him for a second and he just sorta looked back at me. Had no idea I was being quoted...
Actually what I think I should do is start over. Once I have my apartment set up and all that, it should be a little easier to concentrate.
Helen Crosbie
Greenhorn

Joined: Mar 11, 2003
Posts: 26
Hi Michael,
This was really great and I learnt a lot from it. Thank you.
Could you now add something about security policy and RMI as well?
Michael Ernest
High Plains Drifter
Sheriff

Joined: Oct 25, 2000
Posts: 7292

Oooh, a fan! And she's a lady!
Sure, I can say a few things on policy stuff. I'll re-read this thread first, as I've been promising to do for eons now, and then compose some thoughts.
I'm very pleased you found this useful. Thank you for saying so.
Helen Crosbie
Greenhorn

Joined: Mar 11, 2003
Posts: 26
Whoa! I've been feeling smug all day that someone thinks I'm a lady!
That aside, I've worked right through this example and got it working, but I'm having problems getting a client to work on another machine. I've put in the RMI Security Manager and tried to lookup the service, but keep getting an Unmarshalling exception with a ClassNotFound one inside.
I've read lots of threads from people who have also had this problem but none of them have helped me fix it.
As you can see, the next instalment of this thread is eagerly awaited!
Amer Khan
Ranch Hand

Joined: Apr 05, 2003
Posts: 163
This thread deserves to be on the top ALWAYS!


<i>Dare to dream - everything that exists today,was once a figment of someone's imagination, nobody says tomorrow can't be a figment of your today.</i>
Chris Shepherd
Ranch Hand

Joined: Jun 27, 2000
Posts: 286
Helen, post your problems(not in this thread tho, its already crowded... and maybe we can help you out.
Chris
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: RMI from start to finish
 
Similar Threads
where to turn next? need help with model layer talking to the database
RMI client-side SQL and File I/O
Instant Messaging In Java
equals hashcode
If Statement Problem