RMI specification (4)

zhaozj2021-02-11  272

RMI specification - Chapter 4

The client interface programmer requires a visual interface available in the Java.rmi package when writing an Applet or application using a remote object.

4.1 Remote Interface

Package Java.rmi; Public Interface Remote {}

Java.rmi.Remote interface is used to identify all remote interfaces; all remote objects must implement this interface directly or indirectly.

Implementation class can achieve any number of remote interfaces and extend other remote implementations. RMI provides some remote object implementation that can be extended, which helps to create a remote object. These classes are java.rmi.server.unicastRemoteObject and java.rmi.activation.activatable.

For more information on how to define the remote interface, see the "Java.rmi.Remote Interface" (2.4.1) section.

4.2 RemoteException Class Java.rmi.RemoteException is many universal supercles related to communication when performing remote method calls. Each method in the remote interface (also an interface) must list RemoteException (or its superclars, such as java.ioException or java.lang.ioException) in its throws clause.

package java.rmi; public class RemoteException extends java.io.IOException {public Throwable detail; public RemoteException (); public RemoteException (String s); public RemoteException (String s, Throwable ex); public String getMessage (); public void printStackTrace (); public void printstacktrace (java.io.printStream PS); Public void PrintStackTrace (Java.io.PrintWriter PW);}

RemoteException can be constructed with detailed messages (ie s) and a nested exception (ie, ex, throwable). Nested exception EX is designated as a parameter in the third form of constructor, usually the basic I / O exception that occurs during the RMI call.

GetMessage method Returns an exception's detailed message, including the message in nesting exception (if any). The PrintStackTrace method will be overwritten in class java.lang.Throwable to print the neatly frequent stack tracking.

4.3 Naming class java.rmi.naming class provides storage and obtaining methods for reference to remote objects in the Remote Object Registration Server. The method in the Naming class is in the following form, the URL format java.lang.string

As a parameter:

// Host: port / name where Host is the host (remote or local) of the registered service program, Port is the port number that the registration service is received, and the Name is a simple string that the registry is not explained. Host and Port are optional. If HOST is omitted, the host default is the local host. If you have omitted Port,

The port default value is 1099, that is, the "All" of the "Komelli" port used by the RMI system registration service RMIREGISTRY. The remote object binding name is a remote object associated or registered with a later use, which can be used to query the remote object. The remote object can be associated with the name using the BIND or Rebind method of the Naming class. When the remote object has been registered (bind) on the local host with the RMI Registration Server, the caller on the remote (or local) host can query the remote object by name, then get a reference, and then call remotely on the object. method. When necessary, the server running on a host can share a registered service program. The servers can also create and use their own registered service (detailed, see the java.rmi.registry.locateRegistry.createRegistry method).

package java.rmi; public final class Naming {public static Remote lookup (String url) throws NotBoundException, java.net.MalformedURLException, RemoteExceptio n; public static void bind (String url, Remote obj) throws AlreadyBoundException, java.net.MalformedURLException, RemoteExce ption; public static void rebind (String url, Remote obj) throws RemoteException, java.net.MalformedURLException; public static void unbind (String url) throws RemoteException, NotBoundException, java.net.MalformedURLExce ptio n; public static String [] list (String URL) THROWS RemoteException, java.net.malformedurlexception;}} The Lookup method returns a remote object associated with the file part of the name. If the name is not bound to the object, throws notboundexception. The Bind method will bind the specified name to the remote object. If the name is bound to a certain object,

Then throw AlreadyBoundException.

The Rebind method always binds the name to the object, regardless of whether the name is bound. The original binding will be lost.

UNBIND methods will cancel the binding between names and remote objects. If there is no bind, throw the Notbound Exception.

The List method returns an array of String objects that contain snapshots that bind URLs in the registration service. In order to query its content list to the registration service program, only the hostname and port information on the URL; therefore, the "file" section of the URL will be ignored.

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

Note - these methods may also throw java.rmi.accessException. AcceptException table shows privileges for specific operations. For example, only a local client on the host running a registration service program allows Bind, Rebind, and UNBIND operations. However, any non-local clients can be called to operate.

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

New Post(0)