Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem with registry.lookup()

 
Kevin Cao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try to test on 2 boxes, right now is on single machine.
On server:

On client:

I know my computer's name by using "ping localhost". And I ran this application using
It only works if I omit -D options, otherwise it won't. Any suggestions are very appreciated.
Kevin
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

registry.rebind("//localhost/Factory", factory);

You need to understand that the first parameter to Registry.rebind() is not a URL. Instead, it is just a simple String that maps to your object in the registry. For example:


The confusion comes from the fact that Sun's java doc for Registry.rebind() was wrong up to 1.4.0.
Once you accept this fact, everything else will fall into place.
Eugene.
[ March 26, 2003: Message edited by: Eugene Kononov ]
 
Kevin Cao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eugene,
Thanks so much for your response. I used to using Naming.rebind() and Naming.lookup(), which uses URL-formatted name. So if I want to test on 2 boxes, I have to use Naming instead of Registry. Otherwise the hostname will always be passed as String, and it is not bound that way.
The only way to use Registry is pass hostname whenever starts the server(binding), and pass the same hostname when starts client, so they will have the same "STRING" name. Do I understand it correctly.
Kevin
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

So if I want to test on 2 boxes, I have to use Naming instead of Registry. Otherwise the hostname will always be passed as String, and it is not bound that way.

I am not sure what you mean. I also tested on two different machines, and it worked fine. The server binds to Registry, and the client looks up the remote object using Naming. No problem.

The only way to use Registry is pass hostname whenever starts the server(binding)

No, you don't need to pass hostname, -- the server already knows its hostname, and you don't need to specify it when binding an object to registry. Try it exactly as in the code that I posted above, -- it will work.
Eugene.
 
Kevin Cao
Ranch Hand
Posts: 55
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eugene,
After your previous post. I checked javadoc, the java.rmi.Registry.rebind/lookup takes String, and java.rmi.Naming.rebind/lookup takes URL-formatted name, exactly like you said. So I changed to java.rmi.Naming and tested on 2 machines, it works fine.
Again, thanks for your help.
Kevin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic