Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between classes java.rmi.registry.Registry and java.rmi.Naming

What is the difference between the Registry class and Naming class.

In my application I am using Registry class. But I want to know about Naming class and its uses ?

like image 696
Shew Avatar asked Sep 02 '10 19:09

Shew


People also ask

What is naming class in RMI?

Java. rmi. Naming class contains a method to bind, unbind or rebind names with a remote object present at the remote registry. This class is also used to get the reference of the object present at remote registries or the list of name associated with this registry.

What is the difference between using bind () and rebind methods of naming class?

What is the difference between using bind() and rebind() methods of Naming Class ? The bind method bind is responsible for binding the specified name to a remote object, while the rebind method is responsible for rebinding the specified name to a new remote object.

What is Java RMI registry?

A Java RMI registry is a simplified name service that allows clients to get a reference (a stub) to a remote object. In general, a registry is used (if at all) only to locate the first remote object a client needs to use.

What are the different types of classes that are used in RMI?

There are two kinds of classes that can be used in Java RMI. A Remote class is one whose instances can be used remotely. An object of such a class can be referenced in two different ways: Within the address space where the object was constructed, the object is an ordinary object which can be used like any other object.


1 Answers

The difference is that Naming is a utility class with static methods, while Registry is a remote interface. Unsurprisingly, Naming calls Registry internally. Note that the name arguments you pass to java.rmi.Naming are in URL format, and include the location of the registry, whereas with java.rmi.registry.Registry, the name is just the name.

For example, you would call something like this:

Naming.rebind("//host/objName", myObj);

whereas with Registry, you need an existing handle on the registry object, and you'd call:

Registry registry = LocateRegistry.getRegistry("host");
registry.rebind("objName", myObj);

So Naming is really just a convenience class that saves you having to look up the Registry manually - it performs the registry lookup and rebind in one step.

like image 175
skaffman Avatar answered Oct 03 '22 04:10

skaffman