RMI Communication Agreement
10.1 Overview The RMI protocol uses the other two protocols as its in communication format: Java object serialization and HTTP. Object serialization protocol is used to group calls and return data. The HTTP protocol is used for "transmission" remote method calls and returns data when cases allow. Each protocol has a special grammar document. Non-end symbols in the product rules may reference the rules managed by other protocols (object serialization or HTTP). The subsequent product will use the embedded protocol when crossing the protocol boundaries.
Description of the symbols We use similar symbols in the Java Language Norm (see Section 2.3 of JLS). The control code in the stream is represented by the text value of the hexadecimal form. Some non-final symbols in the syntax indicate values related to the application provided in the call. This definition of this non-end synonym consists of its Java type. The syntax is behind these non-terminating characters to the corresponding type of table. 10.2 RMI Transfer Protocol RMI communication format is represented by stream. The term used herein is from the perspective of the client. OUT refers to the output message, and IN fingers enter a message. The content of the transfer title is not formatted with object serialization.
Stream: Out in
The inputs and output streams used by RMI are paired. Each OUT stream has a corresponding IN stream. In the grammar, the OUT flows into the output stream (from the client angle). Inflow (in the grammatical) will match the input of the corresponding socket. Since the output and input stream are paired, the only header information in the input stream is a confirmation that represents whether to understand the protocol; other title information (such as magic numbers and version numbers) will be impossible to the context of the flow.
10.2.1 Output stream in the output stream format RMI consists of a message sequence after transmitting title information. In addition, the output stream can also include calls embedded in the HTTP protocol.
Out: Header Messages httpMessage
Header: 0x4a 0x52 0x4d 0x49 Version Protocol
Version: 0x00 0x01
Protocol: streamprotocol Singleopprotocol MultiplexProtocol
StreetProtocol: 0x4b
SINGLEOPPROTOCOL: 0X4C
MultiplexProtocol: 0x4d
Messages: Message Messages Message
Messages will be packaged in the specific protocol specified by Protocol. For SingleopProtocol, the HE ADER may have only one message, and the Message is not packaged in other data. Single Opprotocol is used in the HTTP request, where requests and responses can only be one.
For StreamProtocol and MultiplexProtocol, the server must use byte 0x4e (indicate support protocol) and EndPointIdentifier (including host name and port number, the server can see if they are used by the client). If this is not performed due to safety reasons, the client can use this information to determine its hostname. Subsequently, the client must respond with another EndPointIdentifier that contains default endpoints that accept the connection. For MultiplexProtocol, the server can use it to identify the client.
For streamprotocol, after this endpoint negotiation, Messages will be sent on the output stream without further packaging the data. For MULTIPLEXPROTOCOL, the socket will be used as a specific connection to multiplexed connections, as described in Section 10.6 "RMI Multiplex Protocol". The virtual connection initialized in this multiplexing connection is composed of a series of Messages, as described below. There are three output messages: Call, Ping and DGCACK. Call will encode method calls. PIN G is a transmission-level message for testing activity of remote virtual machines. DGCACK is a confirmation of a distributed garbage collector for a server indicating that the client has received a remote object in the server return value.
Message: Call Ping DGCACK
Call: 0x50 CallData
Ping: 0x52
DGCACK: 0x54 UniqueIdentifier
10.2.2 Input flow format The current input information has three: Returndata, httpreturn, and pingack. Returndata is the result of "Normal" RMI call. HTTPRETURN is the return result of embedded calls in the HTTP protocol. P IngAck is a confirmation for ping messages.
In: Protocolack Returns protocolnotsupported httpreturn
Protocolack: 0x4e
Protocolnotsupported: 0x4f
Returns: Return Returns Return
Return: Returndata pingack
Returndata: 0x51 ReturnValue
Pingack: 0x53 10.3 RMI Use the call and return data in the RMI call of the object serialization protocol to format the Java object serialization protocol. Each method called CallData is expressed as ObjectIdentifier (called target), Operation (representing the number to call the method), is HASH (check whether the client stub is used by the remote object SKELETON using the same Stub protocol), followed by the zero called the call Or list of multiple parameters.
In the JDK1.1 Stub protocol, the Operation represents the method number (allocated by the RMIC), and Hash is a STUB / SKELETON hash, which is the STUB interface hash. In the JDK1.2 Stub Protocol (using the RMIC generated JDK1.2 STUB with -V1.2 option), the value of Operation is -1 and hash represents the hash of the method to call. Hands will be described in the "Remoteref Interface" section.
CallData: ObjectIdentifier Operation Hash Argumentsopt
Objectidentifier: ObjectNumber UniqueIndifier
UNIQUEIDENTIFIER: NUMBER TIME COUNT
Arguments: Value Arguments Value
Value: Object Primitive
RETURNVALUE called by RMI is composed of UN iQUEIDentifier that indicates the return code that is returned by normal or exception, and is used to return the result of the following returns to the following returns to the following return results when necessary: returned or thrown.
ReturnValue: 0x01 UniqueIdentifier Valueopt 0x02 UniqueIdentifier Exc Eption
-------------------------------------------------- ---------------------------- Note - ObjectIdentifier, UNIQUEIDENTIFIER and EndPointIndifier are not written in default serialization, but each Using your own Write method (but not the WriteObject method used by the object serialization); the Write method of each identifier continuously adds its component data to the output stream.
-------------------------------------------------- ------------------------------
10.3.1 Class Note and Class Loading RMI covers the AnnotateClas S and ResolVeclass methods of ObjectOutputStream and ObjectInputStream, respectively. Each class uses the CodeBase URL (where the location of this class) is used. The Query of this class is loaded in the AnnotateClass method to obtain its CodeBase URL. If the class loader is non-empty and its CodeBase is also non-empty, the CodeBase is written in the stream using the ObjectOutputStream.wr IteObject method; otherwise use the WriteObject method to write a null value. Note: It is best not to annotate classes in the "Java" package because they are always available for recipients.
Class Note is parsed by ObjectInputStream.ResolVeclass method during serialization recovery. The resolveclass method first reads note using the ObjectInputStream.ReadObject method. If the CodeBase URL is non-empty, it gets the URL class loader and attempts to load the class. Using the Java.Net.urConnection to get the class byte, the class can be loaded (the same as the mechanism used to the web browser Applet class loader).
10.4 RMI The use of the HTTP POST protocol In order to call remote methods through the firewall, some RMI calls use HTTP protocols, especially HTTP POST. The URL specified in the transfer title can be one of the following:
http: //: / http: /// cgi-bin / java-rmi? Forward =
The first URL is used to communicate directly with the RMI server on a particular Host and Port. The second form of URL is used to invoke the "CGI" script on the server, which will forward the call to the server on the specified port.
HttppostHeader is a standard HTTP title for POST requests. HTTPRESPONSEHEADER is a standard HTTP response to the delivery process. If the response status code is not 200, it is considered not to return a value. Note You can only embed an RMI call in an HTTP POST request.
HttpMessage: httppostheader header message
Httpreturn: httpresponseheader return
-------------------------------------------------- ------------------------------
Note - Only SingleopProtocol appears in the title of HttpMessage. HTTPRETURN does not include bytes for confirming the protocol.
-------------------------------------------------- -------------------- ---------- 10.5 RMI's value related to the application of this table lists the representatives and applications used by RMI Non-final symbol of the value. This table maps each symbol to the corresponding type. Each symbol is used to format the protocol it embedded. Count Short
Exception java.lang.exception
Hash long
Hostname UTF
Number Int
Object java.lang.Object
Objectnumber Long
Operation Int
Portnumber Int
Primitive Byte, int, short, long ...
Time long
10.6 The purpose of the multi-channel multiplex protocol multi-channel multiplexing is to provide a model, two endpoints can open a plurality of full-duplex connections to the other endpoint, and in the same environment, use other tools (for example When the TCP connection is connected, only one endpoint can open such a two-way connection. With this simple multiplex protocol, RMI can allow customers to connect to RMI's server objects in the case where certain other protocols are unable to force. For example, some security managers of some applets do not allow the server that can be created to listen to to prevent this APPL ET from exporting RMI objects from direct sockets and providing remote call services. However, if the app LET can open the normal socket connection of its CodeBase host, it can use multiple multiplex protocols on this connection to allow the CodeBase host to call the role of the RMI object exported by the applet. This section describes the formats and rules of multiplex protocols.
10.6.1 Definition This section defines the terminology that will be used in the rest of the protocol.
Endpoint is one of two users connected to multiplex protocols.
The multiplex protocol must be on the existing two-way reliable byte stream, assuming that one endpoint is initialized to the other endpoint. In the current RMI usage, it is usually a TCP connection, which is created by the Java.NET.SOCK ET object. This connection is called a specific connection.
The multiplex protocol helps the virtual connection. The virtual connection itself is a two-way reliable byte stream that represents a specific session between two endpoints. A virtual connection set between two endpoints constitutes a multi-channel multiplex connection. Using multiple multiplex protocols, virtual connections can be opened and closed by any endpoint. The virtual connection relative to the status of the given end is defined by multiple multiplex protocol elements transmitted and received on a specific connection. This state involves the connection whether the actual data and related stream control mechanisms are turned on or off. If there is no specification, the rest in this section will use the term connection to the virtual connection.
The virtual connection within the given multiplexing connection is identified by a 16-bit integer identifier called a connection identifier. Thus, there may be 65,536 virtual connections in a multiplexed connection. Implementation may limit the number of virtual connections that can be used at the same time.
10.6.2 Connection status and flow control connection are controlled by various operations defined by multiplex protocols. Below is the operand defined by the protocol: Op En, Close, Closeack, Request, and Transmit. Accurate format and rules for all operations will be described in detail in Section 10.6.3 "Protocol Format".
Open, Close and Closeack operate the open and off, and the REQUEST and TRANSM IT operations are used to transmit data on the open connection in the limit of the flow control mechanism.
Connection state If the endpoint transmits the OPEN operation or the connected OPEN operation (and then there is no closed it), the virtual connection is turned on relative to the end point. The following describes different protocol operations.
If the endpoint sends a connection to the CLOSE operation, the CLOSE or CLOSE ACK operation is not received, the virtual connection is waiting to be closed relative to the endpoint. If the endpoint has never opened the connection or receiving the connected close or Closeack operation (and then no open), the virtual connection is closed relative to the endpoint.
Stream Control Multiplexing Protocol Use a simple packet flow control mechanism to allow multiple virtual connections to be connected to the same specific connection. Advanced requirements for stream control mechanisms are independent status of all virtual connections; a status of a connection does not affect other connections. For example, if the data buffer that processes data from a connection is full, the data transfer and processing of other connections should not be made. This will be critical if the connection continues to depends on the end of another connection (for example, when recursive RMI calls). Thus, its practical significance is that all multi-multiplexing agreements that must be intensive and processed in a specific connection (assuming it to follow this specification).
Each endpoint has two status values associated with each connection: the endpoint has requested but has not received the number of data bytes (input request) and the number of data bytes requested by the other endpoint but the endpoint has not provided (output Number of requests).
The output request of the endpoint will increase when receiving the Request operation from other endpoints, and will decrease when it sends a TR ANSMIT operation. The number of input requests for endpoints will increase when it sends a Request operation, and will decrease when it receives the Transmit operation. These values will violate the protocol if it is negative.
If the endpoint sends a request operation, its input request is increased and the number of bytes exceeds its currently no blocking process, it violates the protocol. However, if the connected user is waiting to read the data, make sure that its input request is greater than zero.
If the TRANSMIT operation sent by the endpoint contains more bytes than its output request, it violates the protocol. It can buffer external data until the user requests explicit refresh written to the connection to the connection. However, if the data must be transmitted on the connection because the explicit refresh or implementation of the input buffer, the connection user may be blocked until there is enough Transmit operation.
Under the premise of satisfying the above rules, implementation can be relatively free to send Request and Transmit operations. For example, if its input buffer is not empty, the endpoint can request more data of the connection.
10.6.3 The byte stream format of the protocol format multiplex protocol consists of a continuous variable length record sequence. The first byte recorded is an opcode that identifies the recorded operation and determines the format of its contents. We define the following legal opcode:
Value name
0xE1 Open
0xE2 Close
0xe3 Closeck
0xE4 Request
0xE5 Transmit
If the first byte of the record is not the defined opcode, the protocol is violated. The following sections describe the record format of each opcode.
Open operation below is the record format of the OPEN operation:
Size (byte) name description
1 OPCODE Operation Code (Open)
2 ID connection identifier
The endpoint will send the OPEN operation to open the specified connection. If the ID points to a connection that is now turned on or closes the send endpoint, it violates the protocol. After opening the connection, the input and request number status of the connection is zero on both endpoints.
The OPEN operation is received indicates that the other endpoint is opening the specified connection. Once the connection is opened, the output and request status of the connection are zero at both endpoints.
To prevent identifier between the two end points, the effective connection identifier space will be divided into two halves according to the value of the highest bit. Each endpoint only allows you to open a high level as a certain particular value. The endpoint that starts the specific connection must only open the connection in the nose as the identifier, and the other endpoint must only open the connection of zero. For example, if the RMI applet that cannot be created the server socket starts a multiplex connection to its CodeBase host, the applet can open the virtual connection of 0x8000-7FFF in the identifier range, and the server can open the identifier range of 0- 0x7FFF virtual connection. CLOSE Operation The following is a recording format of a Close operation:
Size (byte) name description
1 OPCode Operation Code (OPEN)
2 ID connection identifier
The endpoint sends a Close action to close the specified connection. If the ID points to the connection to the transmit endpoint, it is currently closes or closes (if it has transmitted the Close operation of this connection, it may be a connection to the receiving endpoint, the connection is closed, and the protocol is violated. After sending a Close, the connection is a connection to the sending endpoint is about to turn off. Therefore, the endpoint will not reopen the connection until it receives the CLO SE or Closeack from the other endpoint.
The reception of the Close operation indicates that the other end point has turned off the specified connection, so the connection has been turned off on the receiving endpoint. Although the receiving endpoint may no longer send other operations for this connection (until it is opened again), it should still provide data in the implementation input buffer for this connection. If the connection has been turned on (instead of being closed), the receiving endpoint must be actuated with a Closeack operation.
Closeack Operation The following is a record format of a Closeack operation:
Size (byte) name description
1 OPCode Operation Code (OPEN)
2 ID connection identifier
The endpoint sends a Closeack operation to indicate that a Close operation from the received endpoint has been received. If the connection pointing to the ID point is not the connection to the receiving endpoint, it violates the protocol.
Receiving a Closeack operation can change the status of the specified connection from soon as it is closed, so the connection can be reopyed later.
REQUEST Operation The following is a recording format of the request operation:
Size (byte) name description
1 OPCode Operation Code (OPEN)
2 ID connection identifier
4 count number of number of bytes requested
Endpoint sends a request operation to increase the number of input requests for the specified connection. If the ID does not point to the connection to the send end point, it violates the protocol. The number of input requests for endpoints are incremented by values. The value of count is 32-bit symbolic integers. If it is negative or zero, it violates the protocol.
The received request will increase the output request of the specified connection by count. If the receiving endpoint is about to close, the request operation will be ignored.
TRANSMIT Operation The following is a record format for Transmit operations.
Size (byte) name description
1 OPCODE Operation Code (Open)
2 ID connection identifier
4 counts of COUNT transmission
Count Data Transport Data
After the endpoint sends a Transmit operation, it is only true to transfer data on the specified connection. If the ID does not point to the connection to the send endpoint, it violates the protocol. The output request of the endpoint is decremented by value count. The value of count is 32-bit symbolic integers. If it is negative or zero, it violates the protocol. If the transmit operation causes the number of output requests to be negative, the protocol is also violated.
The byte queue read from the connection will increase the data of the count byte when the Transmit operation is received. The number of input requests for the receiving endpoint is decremented by value count. If this makes the number of input requests become zero, and the connected user attempts to read more data, then the endpoint applies another request operation as a response. If the receiving endpoint is about to turn off, the Transmit operation will be ignored. Violation of the protocol If the above violation of the protocol, or the communication error is detected in a specific connection, the multiplexed connection is turned off. The actual connection will be terminated, while all virtual connections are also closed immediately. The connected user can read the data that already read in the virtual connection.