Any server process can support its own registry or a single registry can be used for a host. The methods of LocateRegistry are used to get a registry operating on a particular host or host and port. The methods of the java. Naming class makes calls to a remote object that implements the Registry interface using the appropriate LocateRegistry. The java. Naming class provides methods for storing and obtaining references to remote objects in the remote object registry.
The Naming class's methods take, as one of their arguments, a name that is URL formatted java. String of the form:. 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 , 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. Once a remote object is registered bound with the RMI registry on the local host, callers on a remote or local host can lookup the remote object by name, obtain its reference, and then invoke remote methods on the object. A registry may be shared by all servers running on a host or an individual server process may create and use its own registry if desired see java.
The lookup method returns the remote object associated with the file portion of the name. The NotBoundException is thrown if the name has not been bound to an object. The bind method binds the specified name to the remote object. It throws the AlreadyBoundException if the name is already bound to an object. The rebind method always binds the name to the object even if the name is already bound. The old binding is lost. The unbind method removes the binding between the name and the remote object.
It will throw the NotBoundException if there was no binding. The list method returns an array of String objects containing a snapshot of the URLs bound in the registry. Only the host and port information of the URL is needed to contact a registry for the list of its contents; thus, the "file" part of the URL is ignored.
Note - The java. AccessException may also be thrown as a result of any of these methods. The AccessException indicates that the caller does not have permission to execute the specific operation. For example, only clients that are local to the host on which the registry runs are permitted to execute the operations, bind , rebind , and unbind.
A lookup operation, however can be invoked from any non-local client. Registry remote interface provides methods for lookup, binding, rebinding, unbinding, and listing the contents of a registry. Naming class uses the registry remote interface to provide URL-based naming. Remote; import java. RemoteException; import java.
LocateRegistry; import java. Registry; import java. Skip to content. Change Language. Related Articles. Table of Contents. Save Article. Improve Article. Like Article. Once a remote object is registered bound with the RMI registry on the local host, callers on a remote or local host can lookup the remote object by name, obtain its reference, and then invoke remote methods on the object. A registry may be shared by all servers running on a host or an individual server process may create and use its own registry if desired see java.
Since: JDK1. Methods inherited from class java. Parameters: name - a name in URL format without the scheme component obj - a reference for the remote object usually a stub Throws: AlreadyBoundException - if name is already bound MalformedURLException - if the name is not an appropriately formatted URL RemoteException - if registry could not be contacted AccessException - if this operation is not permitted if originating from a non-local host, for example Since: JDK1. Any existing binding for the name is replaced.
Parameters: name - a name in URL format without the scheme component obj - new remote object to associate with the name Throws: MalformedURLException - if the name is not an appropriately formatted URL RemoteException - if registry could not be contacted AccessException - if this operation is not permitted if originating from a non-local host, for example Since: JDK1.
The names are URL-formatted without the scheme component strings.
0コメント