• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Naming.lookup arguments

 
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to Java API:

The Naming class's methods take, as one of their arguments, a name that is a URL formatted java.lang.String of the form:
//host ort/name
where host is the host (remote or local) where the registry is located, port is the port number on which the registry accepts calls, and where name is a simple string uninterpreted by the registry. Both host and port are optional. If host is omitted, the host defaults to the local host. If port is omitted, then the port defaults to 1099, the "well-known" port that RMI's registry, rmiregistry, uses.
Binding a name for a remote object is associating or registering a name for a remote object that can be used at a later time to look up that remote object. A remote object can be associated with a name using the Naming class's bind or rebind methods.


I have a question here:
Considering the default port 1099:
1. If the lookup is in localhost, then the url would be:

rmi://localhost/name


where name is the server name binded to registry.
2. If the lookup is for the remote server, then the url would be:

rmi://remotehost/name


where name is the server name binded to registry.
But can someone explain what should be in the url for remotehost is it the ip address?
thanks,
sri
p.s: This post is in continuation with this post:
https://coderanch.com/t/182606/java-developer-SCJD/certification/Rmi-lookup-Class-Cast-Exception
 
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


But can someone explain what should be in the url for remotehost is it the ip address?


That would be an IP address or simply the name of the server, such as "fatBrain", "deepBlue", etc. To see what your computer name is on Windows, right click My Computer|Properties|Network Identification (this may be different on Windows 95/98/2000/NT/XP)
Eugene.
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Eugene Kononov:

That would be an IP address or simply the name of the server, such as "fatBrain", "deepBlue", etc. Eugene.


Thanks Eugene!
If host is just the name of the server, which is bound to registry, then can you please explain what is Name here:


Naming.lookup("rmi://"+host+"Name");


So, does this mean that the following code is correct:


FactoryInterface fi =(FactoryInterface)Naming.lookup("rmi://serverName");


where serverName is an instance of ServerFactoryImplementation class,
bound to registry like this:


Naming.rebind(serverName, new FactoryImpl());


thanks,
sri
 
John Smith
Ranch Hand
Posts: 2937
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


If host is just the name of the server, which is bound to registry, then can you please explain what is Name here:


No, the host is the name of the physical server, i.e, the name of the computer. As I recommended, look up the name of your computer so that you are not confused. What you bind to the registry is the remote object. For some reson, many people are confused with the concept of registry and binding to it. It couldn't be simpler, -- loosely speaking, the registry is just a block of memory where you make your objects available for everyone to see. The registry is organized as a map, where your key is the name of you object (any String, such as "my object"), and and the value is the actual object. Thus, to bind an object to registry, all you need to do is:
registry.bind("my object", myObject);
Notice that you don't need to specify the machine name or port, because the object is bound on this machine. Now, to retreve the object from another machine, you must specify the machine name (such as "fatBrain", or 170.3.133.169), the port (such as 1099), and the name to which the object is mapped ("my object"):
String service = "//" + "fatBrain" + ":" + 1099 + "/" + "my object";
myObject = (MyObjectInterface) Naming.lookup(service);
That's all there is to it, -- one line of code for bind(), two lines for lookup(). The client needs to know the server name to connect, of course.
Eugene.
[ April 01, 2003: Message edited by: Eugene Kononov ]
 
Sri Addanki
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Eugene, for that wonderful explanation!
Now, if i have just
Naming.lookup("rmi://"+remoteObject);
1. if i don't mention any hostname/ipaddress
2. and if its only the default port,
3. and i have the remote object bind to registry, then Naming.lookup will search in rmi://localhost, right?
If this is right, then in my code, i get classcast exception, why?
Can you please see my other post too, even Mark is trying to help me out.
thanks,
sri
 
Grow your own food... or this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic