RMI specification (6)

zhaozj2021-02-11  201

Registered service program interface ---------------------------------------------- ----------------------- ---------- Chapter 6

The RMI system uses the java.rmi.registry.registry interface and the Java.rmi.registry.locat EREGISTRY class to provide a well-known bootstrap service in name retrieval and registration objects.

Registry is a remote object that maps the name to the remote object. All server processes support your own registration service program or a single registration service that can be used for the host.

The LocateRegistry method is used to enable the registration service program to run in a specific host or host from the port. The Java.rmi.naming class method is used to call a remote object that implements the Registry interface with the appropriate Locat EREGISTRY.GETREGISTRY method.

Topic: Registry interface LocateRegistry class RegistryHandler interface

6.1 Registry interface java.rmi.registry.registry Remote interface provides a method of providing queries, binding, re-binding, unbinding, and listing registered service programs. The java.rmi.naming class provides a URL-based naming with the Registry remote interface.

Package java.rmi.registry;

public interface Registry extends java.rmi.Remote {public static final int REGISTRY_PORT = 1099; public java.rmi.Remote lookup (String name) throws java.rmi.RemoteException, java.rmi.NotBoundException, java.rmi.AccessException; public void bind (String name, java.rmi.Remote obj) throws java.rmi.RemoteException, java.rmi.AlreadyBoundException, java.rmi.AccessException; public void rebind (String name, java.rmi.Remote obj) throws java.rmi. RemoteException, java.rmi.AccessException; public void unbind (String name) throws java.rmi.RemoteException, java.rmi.NotBoundException, java.rmi.AccessException; public String [] list () throws java.rmi.RemoteException, java. Rmi.accessException;

Registry_port is the default port of the registered service.

The Lookup method returns a remote object that is bound to the specified Name, while the remote object implements a set of remote interfaces. The client can convert remote objects to the desired remote interface type (this mandatory type conversion may fail with its common failure in the Java language).

Bind method associates the NAME with the remote object OBJ. If the name is bind to an object, throw AlreadyBoundExcepton. Rebind method associates NAME with the remote object OBJ. All bindings before the name will be discarded. UNBIND method Removes the binding between Name and Remote object OBJ. If the name is not binding to an object, throws notboundexception.

The List method returns a strings array that contains snapshots that are tied in the registration service. This return value contains a snapshot of the registered service program content. The client can access the registration service program using the LocateRegistry and Registry interfaces or the URL-based Java.rmi.n Aming class. The registration service program only supports Bind, Unbind, and Rebind with clients located on the same host. All hosts can perform query operations. .2 LocateREGISTRY JAVA.RMI.REGISTRY.LOCATEREGISTRY Class is used to get a reference to a specific host (including local host), a reference (creating stub), or create remote object registration services that can be called at specific ports. program.

The registration service program implements simple naming method associated with the remote object name (string) with the remote object reference. The server restart does not remember the binding between these names and remote objects.

Note that getRegistry call does not act with a remote host connection. It simply establishes local reference to the remote note service, and even if there is no registration service in the remote host, it will succeed. Therefore, when the method is called as a remote registration service program returned by the return value, it may result in failure.

Package java.rmi.registry;

public final class LocateRegistry {public static Registry getRegistry () throws java.rmi.RemoteException; public static Registry getRegistry (int port) throws java.rmi.RemoteException; public static Registry getRegistry (String host) throws java.rmi.RemoteException; public static Registry getRegistry (String host, int port) throws java.rmi.RemoteException; public static Registry getRegistry (String host, int port, RMIClientSocketFactory csf) throws RemoteException; public static Registry createRegistry (int port) throws java.rmi.RemoteException; public static Registry CreateRegistry (int port, rmiclientsocketfactory csf, rmiserversocketfactory ssf) throws remoteexception;}

The first four getRegistry methods returned to the current host, specifying the current host, specified HO ST, or a registration service program reference for specific ports specified by Host. The returned remote STUB is a registration service program with a specified host and port information.

The fifth GetRegistry method (RMICLIENTSOCKETFACTORY) returns a local Created Remote Stub, which corresponds to the remote object Registry on Port and Port. When communicating with the remote registration service program for constructing STUB with this method, the supplied RMICLIENTSO CKETFAACTORY, CSF is used to create a Socket connection to the registration service program for the remote host and port.

-------------------------------------------------- ------------------------------

Note - The registration service that is returned from the getRegistry method is a special constructed STUB containing known object identifiers. At present, it is still not supported to pass the registration service STUB from a virtual machine to another virtual machine (its validity will depend on the implementation). Use the LocateRegistry.getRegistry method to get the host's respective registration service. -------------------------------------------------- ------------------------------

CreateRegistry method creates and exports a registration service program for local hosts for specific ports.

The second CreateREGISTRY method is more flexible when communicating with the registration service program. This call will create and export registry in the local host, and the local host uses a custom socket factory for communications with the registration service. The created registration service program uses the ServerSocket listening from the RMISERVERVERSO CKETFACTory on a given Port. The client receiving the registration service program reference will use the socket created from RMICLIENTSOCKETFACTORY.

-------------------------------------------------- ------------------------------

Note - Starting the registration service using the CreateRegistry method cannot keep the server process activity.

6.3 RegistryHandler interface

-------------------------------------------------- ------------------------------

Note - The RegistryHandler interface is not encouraged in JDK1.2. In JDK1.1, it is only used internally by the RMI, and cannot be used for applications.

-------------------------------------------------- ------------------------------

Package java.rmi.registry;

public interface RegistryHandler {Registry registryStub (String host, int port) throws java.rmi.RemoteException, java.rmi.UnknownHostException; Registry registryImpl (int port) throws java.rmi.RemoteException;}

Method RegistrySTUB returns a Stub that is coupled to the remote registration service program located at the specified host and the port.

Method RegistryImpl will construct and export the registration service program located at the specified port. The port must be non-zero.

转载请注明原文地址:https://www.9cbs.com/read-4728.html

New Post(0)