RMI specification (3)

zhaozj2021-02-11  210

RMI specification - Chapter 3

Topic: Stub and Skeleton Remote Method Calling Threads Using Remote Objects Garbage Collection Dynamic class loading through the proxy server through the firewall RMI

3.1 STUB and Skeleton In the communication process of remote objects, RMI will use standard mechanisms (for RPC systems): Stub and Skeleton. The Stub of the remote object acts as a client representative or agent role of a remote object.

The calling program will call the local STUB method, and the local Stub will be responsible for performing a square method for the remote object. In RMI, the STUB of the remote object is the same as the remote interface set implemented by the remote object.

When you call the STUB method, the following will be performed:

Initialize the connection to a remote virtual machine containing a remote object. Multiple call results to solve the result method to solve the result of the returned value or the returned exception to the call to the call to the calling program to display the call to the calling program to the calling program to display a relatively simple call mechanism to the calling program. Serialization and network-level communications have hidden.

In a remote virtual machine, each remote object can have the corresponding SKELETON (Skeleton in a pure JDK1.2 environment). Skeleton is responsible for assigning calls to actual remote objects. It performs the following operations when the access method is received:

Decoding (read) The parameter of the remote method calls the actual remote object implementation method to group the result (return value or exception) group (write and transfer) to the calling program due to the JDK1.2 and the additional Stub protocol, make it There is no need to use Skeleton in pure JDK1.2 environments. Instead, you should use the general code instead of Skeleton in JDK1.1 to fulfill its duties. Stub and Skeleton are generated by the RMIC compiler.

3.2 Remote Method Calling The method of using the RMI runtime assignment to a remote object-implemented method may not be executed in a separate thread. The RMI runtime will not guarantee the mapping relationship of the remote object and the thread. Because the remote method call of the same remote object may be executed at the same time, the remote object implementation needs to make sure that its implementation is a thread.

3.3 Waste collection of remote objects is the same in the local system, and automatically deletes those remote objects that are no longer referenced by any client in the distributed system are satisfactory. This can free the programmer from tracking the remote object client in order to terminate. RMI uses a garbage collection algorithm similar to the Modula-3 network object (see May 1994 Digital Equipment Co., Ltd. System Research Center Technical Report 115 Birrell, Nelson and Owicki "Network Object").

To implement a reference count garbage collection, RMI is running to track all live references in each Java virtual machine. When an activity reference enters a Java virtual machine, its reference count will add 1. The "Reference" message will be sent to the server's server for the first time. This number will be reduced when the discovery activity reference is not referenced in the local virtual machine. When the last reference is given, the message that is not referenced will be sent to the server. There are many subtle things in the agreement, most of which are related to the order of maintenance references or uncolved messages, ensuring that objects are not prematurely collected.

When a remote object is not referenced by any client, the RMI is running a weak reference. If there is no other local reference to the object, the weak reference will allow the java virtual machine's garbage collector to abandon the object. The distributed garbage collection algorithm can be interactively interact with the local Java virtual machine's garbage collector with the local Java virtual machine.

As long as there is a local reference to the remote object, you cannot collect remote objects as garbage, and the remote object can also be transferred or returned in remote calls. Passing a remote object will also add the target virtual identifier to the referenced set. Remote objects that need not reference notifications must implement java.rmi.server.unreferenced interface. The unreferenced method will be called when these references no longer exist. When the reference set is discovered, unreferenced will also be called. Therefore, UNREFERENCED methods may be called multiple times. Remote objects can only be collected only if there is no local and remote references. Note that if there is a network partition between the client and the remote server object, you may be collected, the remote object (because the transfer may be considered to be invalid). The remote reference will not guarantee the integrity of the reference because there may be premature collection. In other words, the remote reference can actually point to the object that does not exist. The RemoteExcepti ON that must be processed by the application will be thrown when using this class.

3.4 Dynamic Class Loading RMI Allows Parameters, Return Values, and Anomusions in the RMI call to any sequentialized object. RMI uses an object serial mechanism to transfer data from a virtual machine to another while calling the stream with the corresponding location information notes to load the class definition file on the receiving end. When the parameters and return values ​​called by the remote method are solved, all types of objects in the stream require class definitions when they become a valid object in the virtual machine. The solving process will first try to parse the name in the name of the context (current thread). RMI also provides a means of dynamically loaded as a class definition of a class definition of the actual object type transmitted by the parameter and the return value (the parameters of the remote method call and the return value come from the network location specified by the transfer end). This includes dynamic downloads of remote STUB classes - this class corresponds to any other type of other types transmitted by a specific remote object implementation class (for remote reference) and RMI calls, such as in the decoder's class loading context is not available. , A subclass of a declared parameter type.

To support dynamic class loading, the RMI runs should be used for grouping, solving RMI parameters, and returning groups, a specific java.io.ObjectOutputStream and Java.io.ObjectInputStream subclasses. These subclasses cover the AnnotateClass method of ObjectOutputStream and the RESOLVECLASS method of ObjectInputStream so that you can locate the class file exchange information that contains class definitions corresponding to the class descriptor.

For each class descriptor that writes the RMI group stream, the AnnotateClass method will call the class object to call Java.rmi.Server.rmiclassLoader.getClassanNotation to the stream. This result may be empty, or it may be a String object indicating the CodeBase URL path (separated by a space). With this CodeBase URL path, the remote endpoint can download the definition files given.

For each class descriptor read from the RMI group stream, the ResolVeclass method reads a single object from the stream. If the object is string (and the java.rmi.server.usecodebaseonly property is not true), resolveclass will return the result of calling the RMICLASSLOADER.LOADClass, and as the first parameter of the annotated String object, in the descriptor Class name as the second parameter. Otherwise, ResolVeclass will return the result of calling RMiclassLoader.LoadClass, and as a unique parameter with the desired class name.

See "RMICLASSLOADER Class" (5.6) section for more information on RMI. 3.5 RMI RMI transport layers through the proxy server through the firewall usually attempt to open the direct socket on the interface of the Internet. However, many intranet firewalls are not allowed to do so. Therefore, the default RMI transmission provides two HTTP-based mechanisms that make the clients after the firewall have a remote object method that resides outside the firewall.

3.5.1 How to Pack the RMI Call in the HTTP protocol through the firewall, the transport layer can embed RMI calls within the HTTP protocol of the firewall. When the RMI call data is sent as the main body of the HTTP POST request, the feedback information will return to the HTTP response main body. The transport layer can construct a POST request by following two methods:

1. If the firewall proxy server can direct the HTTP request to any port of the host, the HTTP request will be forwarded directly to the port of the RMI server is listening. The default RMI transport layer on the target computer can be listened by identifying and decoding the server socket called RMI calls within the POST request.

2. If the firewall proxy server can only direct the HTTP request to a known HTTP port, the call will be forwarded to the HTTP server that is listening over the host port 80, and will execute the CGI script to forward the target on the same computer. The call to the RMI server port.

3.5.2 Default Socket Factory RMI Transport Extension Java.rmi.Server.RmisocketFactory class to provide the default implementation of a socket plant as a client and server socket source provider. The default socket factory creates a socket to transparently providing a firewall channel mechanism, as shown below: The client sleeve text will automatically try to HTTP connection with the host that cannot contact the direct socket. The server socket will automatically detect if the newly received connection is HTTP POST request. If so, only the requested body is sent to the transport layer while the output format is converted to an HTTP response. The factory's java.rmi.server.rmisocketFactory.createsocket method will provide client-side sockets with this default behavior. The factory's java.rmi.server.rmisocketFactory.CreateSerVersocket method will provide server-side sockets with this default behavior.

3.5.3 Configuring the client does not require a special configuration, allow the client to send RMI calls through the firewall.

However, if the boolean value of java.rmi.server.disablehttp attribute is set to "True", the customer can disable the RMI call to the HTTP request.

3.5.4 Configuring Server

-------------------------------------------------- ---------------- Note - The host name should not be the host's IP address, because some firewall proxy servers do not transmit this host name. -------------------------------------------------- ------------

1. The server must be found in the server's client's approach to the client's remote object. Therefore, the remote reference of the server must contain the full name of the server host. This information can be used to run the server's Java virtual machine, depending on the server platform and network environment. If you are not available, you must specify the full name of the host through the java.rmi.rver.hostname property when starting the server. For example, you can start the RMI Server Class ServerImpl on chatsubo.javasoft.com:

Java -djava.rmi.server.hostname = chatsubo.javasoft.com serverImpl

2. If the server does not support the firewall, the RMI client can be transferred to the free port, you can use the following configuration: a. HTTP server listens on port 80. b. The location of the CGI script is an alias URL path /ci-bin/java-rmi.cgi

This script: - Call the local Java interpretation program to perform the internal class of the transmitting layer that can be transmitted to the appropriate RMI server port. - In the Java virtual machine, the properties are defined in the same name and value as the CGI 1.0 environment variable. A sample script is provided in the RMI distribution version of Solaris and Windows 32 operating systems. Note that the script must specify the full path to the Java interpreter on the server.

3.5.5 Performance issues and limitations In the case where the proxy server is not considered, the transfer call from the HTTP request is at least a number of orders that are slower than the direct sleeve. Because the HTTP request can be initialized in one direction through the firewall, the host outside the firewall cannot call the client's method call, so the client cannot guide its own remote object to the firewall.

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

New Post(0)