Chapter 2
The interfaces and classes in this chapter are used for the distributed garbage collector (DGC) of RMI ).
Subject:
Interface DGC
Lease class
Objid class
UID class
Vmid class
9.1 interface DGC
DGC abstraction for distributed garbage collectionAlgorithm. This interface contains two methods: dirty and
Clean. When Remote Reference is performed on the client (represented by vmid), dirty is called.
. When the client no longer has a reference to remote reference, the client will clean up the call accordingly. Failed d
The irty call must be scheduled for one strong (strong) Clean call to retain the call sequence number from
Unordered calls received by the distributed garbage collector after detection.
A reference to a remote object will be rented by the client that owns the reference for a period of time. Lease period from
It starts when a dirty call is received. The client must be stored on the remote reference before the lease expires.
Call dirty for renewal. If you do not renew your subscription before it expires, the distributed garbage collector will
The client no longer references the remote object.
Package java. RMI. DGC;
Import java. RMI. server. objid;
Public interface DGC extends java. RMI. Remote
{
Lease dirty (objid [] IDs, long sequencenum, lease)
Throws java. RMI. RemoteException;
Void clean (objid [] IDs, long seqnum, vmid, Boolean strong)
Throws java. RMI. RemoteException;
}
Method dirty requests remote object references associated with object identifiers in array parameter IDS
. Lease contains the unique Virtual Machine identifier (vmid) of the client and the lease period requested. The Garbage Collector
Reserve a reference list (Reference List) for the remote objects exported from each local virtual machine )--
Save the list of referenced clients. If lease is allowed, the garbage collector adds the client vmid to I
The reference list of each remote object indicated in DS. Sequencenum is used to detect and discard post-garbage.
The sequence number of the collector call. The sequence number increases every time the spam collector is called.
Some clients cannot generate a unique vmid. This is because only when vmid contains a true host
Is a common unique identifier. Due to security restrictions, some clients will not be able to obtain the location
Address. In this case, the client can use an empty vmid. The distributed garbage collector is assigned to the client.
Vmid.
The dirty call will return the lease object, which contains the vmid used for remote reference and the allowed lease period.
(The server can decide to authorize a lease period shorter than the client request ). The client must use the garbage collector.
The vmid used to make a clean call when the client releases the remote object reference.
The customer Virtual Machine only needs to make an initial dirty call to the remote reference referenced in each Virtual Machine (even if
It references the same remote object multiple times ). In addition, the client must call the Dir
Ty. When the client has no reference to a specific remote object
A clean call must be scheduled for the Object ID associated with the reference.
The Clean call deletes the vmid from the reference list of the remote object specified by IDs. Sequence number used for detection
Subsequent cleanup operations. If the strong parameter is true, it indicates that the clean call is a failed di.
The result of the rty call. Remember the sequence number of the client vmid.
9.2 lease class
The lease contains a unique Virtual Machine identifier and a lease period. The lease object is used to request and grant permissions
Lease of remote object reference.
Package java. RMI. DGC;
Public final class lease implements java. Io. serializable
{
Public lease (vmid ID, long duration );
Public vmid getvmid ();
Public long getvalue ();
}
The lease constructor creates a lease with a specific vmid and lease period. Vmid can be null.
The getvmid method returns the client vmid associated with the lease.
The getvalue method returns the lease period.
9.3 objid class
Class objid is used as the unique identifier of the remote object in the virtual machine. Each identifier contains an object
And a unique address space identifier on a specific host. Object Identifier
To this object.
The objid consists of the object number (long) and the unique identifier (UID) of the address space.
Package java. RMI. server;
Public final class objid implements java. Io. serializable
{
Public objid ();
Public objid (INT num );
Public void write (objectoutput out) throws java. Io. ioexception;
Public static objid read (objectinput in)
Throws java. Io. ioexception;
Public int hashcode ()
Public Boolean equals (Object OBJ)
Public String tostring ()
}
The first form of the objid constructor generates a unique object identifier. The second constructor has been generated
Known object identifier (such as registration serviceProgramAnd the identifier used by the distributed garbage collector), and
A known object number is used as a parameter. The known object ID and default constructor generated by the second Constructor
The generated Object ID does not conflict. To enforce this, the Object ID of the objid will be set to construct
The "known" number provided in the function, and all uid fields are set to zero.
Method write: groups the representation of the Object ID into the output stream.
The read method constructs an object ID, and its content will be read from the specified input stream.
The hashcode method returns the object number as hashcode.
If OBJ and objid are the same, the equals method returns true.
The tostring method returns a string containing the Object ID representation. Only when the Object ID comes from a non-local
The address space identifier is included in the string representation.
. 4 uid class
UID is an abstract class used to create a unique identifier of the host that generates it. It will be identified by the address space
In the objid format. UID is composed of a unique number (INT) and time (long) on the host)
And the count (short ).
Package java. RMI. server;
Public final class uid implements java. Io. serializable
{
Public UID ();
Public UID (short num );
Public int hashcode ();
Public Boolean equals (Object OBJ );
Public String tostring ();
Public void write (dataoutput out) throws java. Io. ioexception;
Public static uid read (datainput in) throws java. Io. ioexception;
}
The first form of the constructor creates a unique pure identifier of the host that generates it. This uid must meet the following conditions:
Uniqueness: a) the computer needs more than one second to restart, B) the computer clock
It will never be adjusted forward. To construct a globally unique uid, you only need to separate the UID and inetaddress
Pairing.
The second form of the constructor creates a known uid. It is known that IDs are 216-1 possible. This
The ID generated by the constructor does not conflict with the ID generated by the default uid constructor. Default Structure
The function generates a unique identifier on the host.
The hashcode, equals, and tostring methods are defined by uid. If the two UIDs
If the capacity is the same, the two are equivalent.
Method write writes the UID to the output stream.
the read method constructs a UID and its content is read from the specified input stream.