RMI specification (8)

zhaozj2021-02-11  198

Chapter 8

This chapter contains the interfaces and classes used by the RMIC STUB compile generated by STUB and Skleton.

Topic: Remotestub Class RemoteCall Interface RemoteRef Interface ServerRef Interface Skeleton Interface Operation Class

8.1 RemoteStub class java.rmi.server.Remotestub class is a general superclass for remote object stub. The Stub object is a proxy, which is the same as defined by the remote interface set and the actual implementation of the remote object.

package java.rmi.server; public abstract class RemoteStub extends java.rmi.RemoteObject {protected RemoteStub (); protected RemoteStub (RemoteRef ref); protected static void setRef (RemoteStub stub, RemoteRef ref);}

The first constructor of RemoteStub will create stub with empty remote reference. The second constructor will create stub with a given remote reference REF.

Use (and not supported) SetRef methods in JDK1.2.

8.1.1 The type of remote object and the Type of the Stub class can interact with the Stub (Agent) object, which is identical to the remote object class as defined by the remote object class. Since the STUB class is generated by the implementation class essence that implements one or more remote interfaces, the Stub class does not include the non-remote portion of the class level (the type of object of the object). For example, if c extension B is expanded A, but only b implements a remote interface, Stub will be generated by B, not C.

Since the STUB implements the same remote interface set as the remote object class, the Stub has the same type as the remote portion of the server object type map from the view of the Java system. In this way, the client can use the built-in Java operation to check the type of the remote object, and can also convert from a remote interface to another remote interface.

STUB is generated with the RMIC compiler. 8.1.2 Declaring Semantic Semantic Semantic Ways The following method is declared in the java.lang.object class as the final FINAL, so it cannot be overwritten by any implementation:

The default implementation of GetClass Notify NotifyAll Wait getClass is suitable for all Java objects (local or remote); for remote objects, this method does not require specialized implementation. The GetClass method is used on remote stub, which reports the exact type of the STUB object generated by the RMIC. Note that the Stub type only reflects the remote interface implemented by the remote object, not the local interface.

The WAIT and Notify methods of java.lang.object will process the waiting and notifications in the Java language thread model context. While using these methods for remote STUBs do not violate the Java thread model, the semantics of these methods will be different from the semantics used for local Java objects. In particular, when using these methods, it will be a client-specific object of remote objects, not the actual object of a remote site.

8.2 RemoteCall Interface RemoteCall is the abstract interface used by the Stub and Skeleton of the remote object to perform calls to the remote object.

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

Note - RemoteCall interface is not encouraged in JDK 1.2. The JDK 1.2 Stub protocol has no longer use this interface. Now, STUB uses a new Invoke method in JDK 1.2, which does not need to use RemoteCall as a parameter. -------------------------------------------------- ------------------------------

Package java.rmi.server; import java.io. *;

public interface RemoteCall {ObjectOutput getOutputStream () throws IOException; void releaseOutputStream () throws IOException; ObjectInput getInputStream () throws IOException; void releaseInputStream () throws IOException; ObjectOutput getResultStream (boolean success) throws IOException, StreamCorruptedException; void executeCall () throws Exception; Void done () throws oException;

Method GetputstReam returns the output stream. Stub will group parameters to group, or Skeleton will group the result.

Method ReleaseoutputStream releases the output stream. In some transmissions, this will result in release flow.

Method GetInputStream Returns INPUTSTREAM. STUB solves the result, or Skeleton is interpreted from the parameters.

Method ReleaseInputStream releases the input stream. This will allow some to transfer the input of the connection in advance.

Method GetResultStream returns the output stream (after writing the title information related to the call success). Each remote call will only get a result stream. If SUCCESS is true, the result to group is normal to return; otherwise the result is exception. If the result stream of the remote call has been obtained, StreamCorruptedException is thrown.

Methods EXECUTECALL does the invocation that can be performed.

The method DONE allows clearance after completing the remote call. .3 RemoteRef interface server Remoteref represents the handle of the remote object. Each STUB includes an instance of RemoteRef, including specific representation of references. This remote reference will be used to perform remote modes on its representative remote objects.

Package java.rmi.server;

Public interface remotref extends java.io.externalizable {Object Invoke (Remote Obj, java.lang.reflect.Method Method, Object [] params, long opnum).

RemoteCall newCall (RemoteObject obj, Operation [] op, int opnum, long hash) throws RemoteException; void invoke (RemoteCall call) throws Exception; void done (RemoteCall call) throws RemoteException; String getRefClass (java.io.ObjectOutput out); int Remotehashcode (); Boolean Remoteequals (RemoteRef obj); String RemoteTString ();} The first INVOKE method calls the method to call the remote reference of Stub (OBJ), and allows the reference to establish a connection to the remote host, will Method and parameters PARAMS's representation of the group, then use the method call to communicate with the remote host. This method returns the method of the method calling the remote object on the remote host, or throws RemoteException when the call fails, and throws the application-level exception when the remote call is thrown out. Note that the operation number OPNUM represents a hash method signature to encode the method to be transmitted.

OPNUM's method has a 64-bit (long) integer, which is based on the security hash algorithm (SHA-1) of the National Standard Technology Bureau (SHA-1), calculated using the first two 32-bit values ​​of the word current flow message. Come. The byte stream contains a UTF encoding of a string composed of a remote method descriptor (see a description of the method descriptor, see Section 4.3.3 of the Java Virtual Machine Specification). The hash value will be worth it from the first and second 32-bit of the SHA-1.

Long Hash = SHA [1] << 32 SHA [0]

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

Note - NewCall, Invoke, and Done methods are not encouraged in JDK 1.2. These methods are not used by RMICs to use the JDK 1.2 Stub Protocol version. The call sequence consisting of NewCall, Invoke, and D One has been replaced by the new INVOKE method, which makes the Method object as a parameter.

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

Method NewCall will create a corresponding call object to a new remote method on the remote object OBJ. The operating array OP contains an available operation on the remote object. The operation number OPNUM is an index of an operator array, which specifies the specific operation of the remote call. Transfer Operation Arch and Index Enables the STUB generator to assign an operation index and explain. Remote references may require an operation instructions to encode in the call.

Method INVOKE is responsible for performing remote calls. Invoke will produce "users" exceptions that can be passed through and not captured by Stub. If an exception is generated during the remote call, INVOKE should be noted to clear the connection before generating "user exception" or RemoteException.

Method DONE allows remote reference to clear (or reuse) connections. DONE should only be called only when the Invoke call has been successfully (non-abnormal) returns Stub.

Method GetRefClass returns a full name that will be serialized to the reference type of the reference type of OUT.

Method RemoteHashCode returns the hash code of the remote object. Two remote objects of the same remote object will have the same hash code (to support the remote object as a key value) in the hash table). Remote Object will forward the call to its HashCode method to the remote reference RemoteHashCode method. Method Remoteequals compares the equivalence of two remote objects. If the two remote objects reference the same remote object, they think they are equivalent. For example, if the two stub references the same remote object, they are considered to be equivalent. RemoteObject will forward the call to its equals method to the R Emoteequals method for remote references.

Method RemoteTString returns a String that represents the reference to the remote object.

8.4 ServerRef interface interface serverRef represents the server-side handle implemented by the remote object.

Package java.rmi.server;

Public interface serverref extends remotref {

Remotestub ExportObject (java.rmi.remote obj, object data) throws java.rmi.remoteException;

String getClientHost () throws serverNotactiveException;}

Methods ExportObject will implement OBJ lookup or create a client St UB object for the Remote object provided. Parameter data contains information required to export objects (such as port numbers).

Method getClientHost returns the host name of the current client. When it is currently handling thread calls that are handled by the remote object, the client host name that is executed is returned. Call ServerNotActiveException if the current remote method call is not in service.

8.5 The Skeleton interface interface Skeleton can only be implemented by the RMIC compiler. The SKE LETON of the remote object is an entity of the server, which will assign allocation calls for actual remote objects.

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

Note - The Skeleton interface is not encouraged in JDK1.2. This interface is implemented for each 1.1 (and the Skeleton) SK Eleton class generated by the RMIC STUB compiler (and the default RMIC -VCompat generated by default RMIC -VCompat). The JDK1.2 compatible version is assigned a remote method call will no longer need Ske Leton. To generate STUB compatible with JDK1.2 or higher, use the command RMIC with option -V1.2.

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

Package java.rmi.server;

Public interface skeleton {

Void Dispatch (Remote Obj, RemoteCall Call, INT OPNUM, Long Hash) THROWS EXCEPTION; Operation [] getOperations ();

The Dispatch method will decnation parameters in the input stream obtained in the CALL object, call the method on the actual remote object real OBJ (represented by the operation number OPNUM), and then group the return value. If an abnormality occurs during the transfer process, the exception is thrown.

The GetOperations method returns an array of operation descriptors that contain remote object methods. 8.6 Operation Class Operation contains a description of the Java method for the remote object. -------------------------------------------------- ------------------------------

Note - The Operation interface is not encouraged in JDK 1.2. The JDK 1.2 Stub protocol no longer uses the original, with Operation as the parameters of the Remoteref.invoke method. Stub uses a new Invoke method in JDK 1.2, which no longer requires Operation as a parameter.

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

Package java.rmi.server;

Public class operation {

Public operation (String OP);

Public String getoperation ();

Public String toString ();

It usually has a method signature when constructing an Operation object.

Method GetOperation returns the content of the operation descriptor (the value used when initialized).

Method TOSTRING also returns a string representation of the operation descriptor (usually a method signature).

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

New Post(0)