RMI specification (7)

zhaozj2021-02-11  234

Remote object activation ----------------------------------------------------------------------- --------------------------------

Chapter 7

Topic: Overview Activation Protocol "Activable" Realization Model Activation Interface

.1 Overview The distributed object system is designed to support long-term persistent objects. Suppose these systems will consist of thousands (also Xu Ge) such objects, and the implementation of the object is activated in an indefinite period of time and keeps the activity state is unreasonable. This will occupy valuable system resources. In addition, the client needs to save the ability to persist in the object, so that the communication between the objects can be re-established after a system crash, as the reference to a distributed object is only valid when the object is active when the object is active.

Object activation is a mechanism for providing implementation of the object's persistent reference and management object. In RMI, activation allows objects to start executing as needed. When the "Activated" remote object is activated, if the remote object is currently not executed, the system will start execution of the object in the appropriate Java virtual machine.

7.1.1 Termatic objects are remote objects that are instantiated and exported in some systems's Java virtual machines. Non-active objects have not been instantiated (or export) in the virtual machine, but can become a remote object of the active state. Activation is the process of transforming non-active objects into active objects. Activation requires objects associated with a virtual machine, which will likely need to load the objects of the object into the virtual machine, while the object also restores its persistent state (if any).

In the RMI system, we use inert activation. The inert activation is to delay an activation of an object to the client machine (that is, when the first method is called).

7.1.2 inert activation The inert activation of the remote object is achieved with imperfect remote references (sometimes called incomplete blocks). Improvement of remote objects When the remote reference is a reference to the active object, "Perfect" is a reference to the active object. Each imperfect reference maintains a persistent handle (activation identifier) ​​and transient remote reference to the target remote object. The activation identifier of the remote object contains sufficient information to activate the third part. Transient reference is a "activity" reference for active remote objects that can be used to perform the execution object.

In the imperfect reference, if the live reference to the remote object is empty, the target object is not considered active. In the method call, the unbaptive reference (the object) will be added to the activation protocol to obtain "live" reference, which is a remote reference for newly activated objects (such as a remote reference) of the Unicast). Once the reference is not perfect, the unbained reference will call the method to pass the remote reference to the underlying, and the remote reference is transmitted to the remote object.

Specifically, the Stub of the remote object contains a "imperfect" remote reference type, including:

The activation identifier of the remote object includes "live" reference (possibly empty), which contains a "active" remote reference type of the remote object (for example, a remote reference type with single transmission semantic).

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

Note - The RMI system retains "up to one" semantic to remote calls. In other words, the call to active or single-channel transmission remote object will be sent once. Therefore, if the call to the remote object fails (by throwing RemoteException exception), the client will get the following guarantee: the execution of the remote method will not exceed once, or even at all.

7.2 Activation Protocol During the remote method call, if the "live" reference of the target object is unknown, the activation protocol is not perfected. Activation protocols include the following entities: the activation group in the Java virtual machine is not perfected, the activation of the activated remote object. Activator (usually one of each host) is an entity, responsible for activation, it is:

The activation identifier is mapped to the information required for the activation object (the class, the location-URL path - loaded from which the object may need to be used for specific data for bootstrap), etc.). Java Virtual Machine Manager, it launches virtual machine (if necessary) and transfer the object activation request (and the necessary information) to the correct activation group in the remote virtual machine. Note: The activator always saves the current mapping of the active identifier to the active object in the cache, so there is no need to query the group for each activation request.

Active group (one of each Java virtual machine) is such an entity that receives the request to activate the object in the Java virtual machine and return the activated object to the activator.

The activation protocol is as follows. Do not improve the reference to activate the identifier to activate the object associated with the identifier. The activation descriptor (previously registered) activation descriptor (previously registered). The descriptor of the object includes:

The object's group identifier (specifying the virtual machine in which the object is activated), the object's class name, URL path, the class code of the object is loaded, the object-specific initialization data (for example, the initialization data may be The name of the file containing the target persistent state). If the activation group of the object should be accommodated, the activator transmits the activation request to the group. If the activation group does not exist, the activator will start the virtual machine to perform the activation group, and then transfer the activation request to the group.

The activation group will load the class's class and instantiate the object with a specific constructor. This constructor has multiple parameters, including previously registered activation descriptors.

When the object is activated, the activation group will reference the group object reference to the active, then the activator records the activation identifier and the activation reference pair, and the active (live) reference will not be referred to. Subsequently, it is not perfected (in STUB) to pass the method call to the remote object directly through the activity reference.

-------------------------------------------------- ---------------------------- Note - In JDK, the RMI provides the implementation of the activation system interface. To use activation, you must first run the system daemon (daemon) RMID.

7.3 "Activated" Remote Object Implementation Model In order to make the remote object accessible by activating the identifier are not subject to time, the developer must do:

Registering a activation descriptor for this remote object In the class, a dedicated constructor is included, which will call it when the RMI system activates the active object.

The following methods can be used to register the activation descriptor (ActivationDesc):

Calling class ACTIVATABLE The Static Register method is used to create a "activatable" object with the first or second constructor of the Activatable class. This process can be implemented with the first or second EXPO RTOBJECT method of Activatable, which is the implementation and port number of ActivationDesc, Remote object.

For a particular object, only one of the three methods described above can be used to register the activation object. For examples of how to implement an activatable object, see the "Constructure Activated Remote Object" later.

7.3.1 ActivationDesc class ActivationDesc Contains information needed to activate the object. It contains an object's activation group identifier, object's class name, and a CodeBase path (or URL) of the load object code (or URL), and MarshalledObject (which can contain object specific initialization data used during each activation). The descriptor registered in the activation system is queried during the activation process to obtain relevant information to re-create or activate the object. The MarshalledObject in the descriptor of the object will be transmitted to the constructor of the remote object as the second parameter for use in the activation process.

Package java.rmi.activation;

public final class ActivationDesc implements java.io.Serializable {public ActivationDesc (String className, String codebase, java.rmi.MarshalledObject data) throws ActivationException; public ActivationDesc (String className, String codebase, java.rmi.MarshalledObject data, boolean restart) throws ActivationException; public ActivationDesc (ActivationGroupID groupID, String className, String codebase, java.rmi.MarshalledObject data, boolean restart); public ActivationDesc (ActivationGroupID groupID, String className, String codebase, java.rmi.MarshalledObject data); public ActivationGroupID getGroupID () Public string getclassname (); public string getLocation (); public java.rmi.marshalledObject getdata () public boolean getrestMode ();

ActivationDesc's first constructor constructs an object descriptor of an object. The class of this object is classname (which can be loaded from a CodeBase path), its initialization information (group form) is D ATA. If this form of constructor is used, the group identifier of the object defaults to the current identifier of the virtual machine Activa TionGroup. All objects with the same ActivationGroupID will be activated in the same virtual machine. If the current group is active or unable to create a default group, the Activat IONEXCEPTION will be thrown. If GroupID is NULL, IllegaAralgumentException will be thrown. ?

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

Note - as a sub-effect that creates ActivationDesc, if the virtual ActivationGrou P is not currently not active, the default ActivationGroup will be created. The default activation group will use java.rmi. RMISecurityManager as the security manager and set the properties in the activation group virtual machine to the current attribute in the virtual machine during reactive. If the application needs to use a different security manager, you must set the group of the virtual machine before creating the default ActivationDesc. For more information on how to create an ACT IVATIONGROUP for a virtual machine, see Method ActivationGroup.createGroup. -------------------------------------------------- ------------------------------

The ActivationDesc second constructor constructor descriptor is the same as the first constructor, but must provide additional parameter restart. If the object requires restart service, this means that the object will automatically restart when the activator is newly activated (the inert activation is reversed as needed). At this point, RESTART should be True. If restart is false, the object will only be activated (passing the remote method) when needed.

The third constructor of ActivationDesc constructs an object descriptor for an object. The group identifier of this object is GroupID, and its class name is classname (which is loaded from the CodeBase path), its initialization information is DATA. All objects with the same groupID will be activated in the same Java virtual machine.

The ActivationDesc Fourth Constructor Construction Object Descriptor is the same as the third constructor, but it allows the specified restart mode. If the object needs to be restarted (defined above), RESTART should be true.

The getGroupID method returns the group identifier of the object specified by the descriptor. The group can provide a method of polymerizing an object to a single Java virtual machine.

The getClassName method returns the class name of the object specified by the activation descriptor.

GetLocation method Returns the CodeBase path for downloading the class.

The getData method returns a "group object" that contains data for initialization (activation) the object specified by the description.

The GetrestartMode method returns true when the restart mode of the object is enabled, otherwise false.

7.3.2 ActivationID class Activation protocol utilizes an activation identifier to indicate an activated remote object that is not subject to time. Activate identifier (instance of class ActivationID) contains several information required to activate the object:

The unique identifier of the remote reference object of the object activator. The active identifier of the object can be obtained by registering an object to the activation system. Registration can be accomplished with one of the following methods (as described above):

Through the first or second ActivATable constructor (all of which are registered with three parameters and export objects) through the Activatable.Register method (them to activate the descriptor, the object implementation and port " For parameters, and register and export objects).

Package java.rmi.activation;

public class ActivationID implements java.io.Serializable {public ActivationID (Activator activator);. public Remote activate (boolean force) throws ActivationException, UnknownObjectException, java.rmi RemoteExcep tion; public boolean equals (Object obj); public int hashCode (); } ActivationID constructor accepts parameter Activator, which specifies a remote reference for the actuator (responsible for activating the object associated with the activation identifier). An instance of ActivationID is the only one. The Activate method activates the object associated with the activation identifier. If the Force parameter is True, the activator will treat any cache references of the remote object as outdated, so that the activator is in contact with the group when activating the object. If force is false, return an acceptable cache value. If the activation fails, throw an ActivationException. If the activator cannot identify the object identifier, the method will throw unknownObjectException. If the remote call of the activator fails, it throws RemoteException. The equals method can achieve equivalent comparison based on content. If all domains are equal (exactly the same or from Object.equals semantics in various domains), it will return True. If P1 and P2 are examples of class ACT IVATIONID, the HashCode method returns the same value when p1.equals (p2) returns TRUE.

7.3.3 Activatable class Activatable class provides support for remote objects that require persistent access, while being activated by the system. Class Activatable is a major application interface for developers to implement and manage activatable objects. Note that the activation system daemon RMID must be run first before you can register and / or activate the object.

package java.rmi.activation; public abstract class Activatable extends java.rmi.server.RemoteServer {protected Activatable (String codebase, java.rmi.MarshalledObject data, boolean restart, int port) throws ActivationException, java.rmi.RemoteException;

protected Activatable (String codebase, java.rmi.MarshalledObject data, boolean restart, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws ActivationException, java.rmi.RemoteException;

Protected active (activationid id, int port) throws java.rmi.remoteexception;

Protected Activatable (ActivationID ID, INT Port, RMICLIENTSOCKETFAACTORY SSF) throws java.rmi.RemoteException;

Protected activationid getId ();

public static Remote register (ActivationDesc desc) throws UnknownGroupException, ActivationException, java.rmi.RemoteException; public static boolean inactive (ActivationID id) throws UnknownObjectException, ActivationException, java.rmi.RemoteException;

Public Static Void Unregister (ActivationID ID) THROWS UNKNOBJECTEXCEPTION, ACTIVATIONEXCEPTION, JAVA.RMI.RemoteException;

Public Static ActivationId ExportObject (Remote Obj, String Codebase, MarshalledObject Data, Boolean Restart, Int port) throws activationException, java.rmi.RemoteException;

public static ActivationID exportObject (Remote obj, String codebase, MarshalledObject data, boolean restart, int port, RMIClientSocketFactory csf, RMIServerSocketFactory ssf) throws ActivationException, java.rmi.RemoteException;

Public Static Remote ExportObject (Remote Obj, ActivationID ID, INT Port) throws java.rmi.RemoteException;

Public Static Remote ExportObject (Remote Obj, ActivationID ID, INT Port, RMICLIENTSOCKETFAACTORY CSF, RMISERVERSOCKETFACTORY SSF) THROWS JAVA.RMI.RemoteException;

Public Static Boolean UnexportObject (Remote Obj, Boolean Force) THROWS JAVA.RMI.NOSUCHOBJECTEXCEPTION;

The implementation of the remote object can be activated may expand or do not extend class Activatable. The remote object implementation of the ActivATAB LE class will inherit the corresponding definition in the Hashco DE and Equals methods from the superclass java.rmi.server.RemoteObject. Therefore, the two remote references that reference the same ActiVATable remote object are equal (the Equals method returns TRUE). Similarly, the example of class Activatable will "equals" the corresponding STUB object of the instance (ie, if the Object.Equals method is called as a parameter with the implementation of the STUB object, it will return True. Virtue).

The first constructor of the Activatable class method Activatable class is used to register and export objects on the specified port (if the P ORT is zero, select an anonymous port). The URL path of the downloaded class code object is CODBASE whose initialization data is DATA. If restart is True, the object will automatically restart when the activator restarts or group failure. If restart is false, the object will be activated as needed (by calling the remote method of the object). The specific subclass of the ACTIVATABLE class must call the constructor to register and export the object during the initial construct. As the sub-efficiency when constructing the active object, the remote object will be "registered" to the activation system and "export" (if the port is zero, then exported at anonymous port) to the RMI run, so that it can accept from the client The arrival call.

If the registration object to the activation system failed, the constructor will throw an ActivationException. If you fail to export objects to RMI runtime, RemoteException will be thrown.

The second constructor is the same as the first ActivATable constructor, but it allows the client and server set factory specification to communicate with the activable object. For more information, see "RMI Socket Factory".

The third constructor is used to activate the object and export it from the specified port (with ActivationID, ID). When the object itself is activated by its dedicated "activation" constructor, the specific subclass of the ACTIVATABLE class must call the constructor. The parameters of the "activation" constructor must be:

The object's activation ID and the initialization / bootstrap data of the object (MARSHALLEDOBJECT). As the sub-effects of the configuration, the remote object will be "exported" to the RMI runtime (from the specified port) and accept calls from the client. If the object is derived to the RMI runtime, the constructor will throw RemoteException.

The fourth constructor is the same as the third constructor, but it allows the client and server socket factory specification to communicate with the activable object.

GetID method Returns the activation identifier of the object. This method is protected, so only subclasses can obtain the identifier of the object. The object's identifier is used to report the non-active state of the object or the activation descriptor of the logout object.

The REGISTER method is an activatable remote object to the activation system registration object descriptor DESC, so that the object can be activated when needed. This method can be used to register activaneous objects without creating this object first. It returns the Remote Stub that activates objects, so it can be saved and called in the future to force the first time to create / activate the object. This method will throw unknownGroupException if the group identifier in the DESC is not activated. If the activation system is not running, the ActivationException is thrown. Finally, if the remote call of the activation system fails, the RemoteException is thrown.

The Inactive method is used to notify the system that has the object with the corresponding activation ID is currently non-active. If this object is currently active, the object will be exported from the RMI runtime environment (only when there is no call or executed), so that the call can no longer receive. This call will also notify the virtual machine A CTINGROUP that is inactive; and the group will notify its ActivationMonito R. If the call is successful, then the activation request for the activator will result in reactivation of the object. If the object is prevented from successively (meaning that it does not pend or performs calls), the INACTIVE method returns true; if the object is called in the process, it cannot block the object from being exported, then the Fa LSE is returned. If the object is unknown (it might be non-active), the method will throw unknownObject Texception; if the group is inactive, throw an ActivationException; if the notification display fails, throw RemoteException. This operation will still be successful if the object is considered to be active but has prevented itself. The Unregister method is used to undo the previous registration of the activation descriptor associated with the ID. Objects cannot be activated with this ID. If the object ID is unknown for the activation system, you will throw unknownObje CTexception. If the activation system is not in a running state, the ActivationException is thrown. If the remote call of the activation system fails, it throws RemoteException.

The first ExportObject method can be "activated" but does not extend an object explicit call of the Activatable class, its purpose is: a) To activate the activation descriptor DESC to activate the system, constructed by the supplied COD EBASE and DATA configuration (so The object can be activated); b) Export remote object OB J (if the port is zero, the anonymous port) is selected from the specified port. Once the object is exported, it can be received.

The ExportObject method returns the activation identifier obtained when the system registration descriptor DESC is activated. If the activation group is not active in the virtual machine, throw an ActivationException. If the object registers or exports, it throws RemoteException.

If the OBJ extension Activatable, this method is not required because the first ActivAtable constructor will call the method.

The second ExportObject method is the same as the first, but it allows the client and server socket to communicate with the activatable object.

The third ExportObject method exports the "activatable" remote object (not necessarily a ctivatable type) of the identifier ID to the RMI runtime, so that the object OBJ can receive calls. If the Port is zero, the object will be exported at an anonymous port.

When activated, the "activation" object that does not extend the Activatable class should explicitly call this ExportObje CT method. It does not need to call the Activatable class to call the method directly; it will be called by the third constructor above (the subcategory should be called from its dedicated activation constructor).

The ExportObject method will return Remote STUB that activatable object. If the export of the object is lost, the method will throw RemoteException.

The fourth ExportObject method is the same as the third, but it allows clients and server sockets to communicate with this activaneous object. UNEXPORTOBJECT method makes the remote object OBJ cannot receive calls. If the parameter force is true, the object will also be forced to block the export even if there is a call to the remote object to be called or the remote object is called in the process. If the parameter force is false, it is only blocked only when there is no call to the object's pending call or in the process. If the export of the object is successfully blocked, the RMI will delete it from its internal table. Using this mandatory approach to delete objects from the RMI may enable the client's overtime remote reference. If the object is not previously exported to the RMI runtime, the method will throw java.rmi.nosuchobjectException.

Constructing an active remote object To enable object activation, "Activable" object implements the class regardless of whether or not the ACTIVATABLE class must define a special public constructor. The common constructor has two parameters: Activate identifier (type ActiVationID) and activation data java.rmi.marshalledObject (provided in the activation descriptor used in registration). When an activation group activates a remote object within its virtual machine, it will use this special constructor to construct the object (later will be described in detail). Remote object implementation can be initially used with activation data. Remote objects may also want to retain their activation identifiers so that the activation group can be notified when it becomes non-active (by calling the ACTIVATABLE. Inactive method).

The first and second form of the ACTIVATABLE constructor is used to register with the specified port and export activatable objects. This constructor should be used when constructed the object; the third form of the constructor will be used when reactive objects.

The specific subclass of ACTIVATABLE must call the first or second constructor during the initial construct to quench and export objects. The constructor first creates an activation descriptor (ActivationD ESC), the CodeBase and Data (the activation group for the virtual machine) provided by the object. The constructor will then register the descriptor to the default ActivationSystem. Finally, the constructor is on a particular port (if the port is zero, select anonymous port) to export the active object to the RMI run, and report the object as an ActiveObject to the local ActivationGroup. If an error occurs during registration or export, the constructor throws RemoteException. Note that the constructor also initializes its ActiVationID (obtained by registering), so the call to the protected method GetID will return the activation identifier of the object.

The third form of the Activatable constructor is used to export objects from the specified port. The third constructor must be called when the specific subclass of the ActivATAB LE is activated by the object's own "activation" constructor. This "activation" constructor is two parameters:

The initialization data of the object's ActivationID object, a MARSHALLEDOBJECT object This constructor only exports the active object from a particular port (if the Port is zero, select anonymous port) to export to the RMI runtime, and does not notify ACTIVATIONGROUP This object is already an active Object. Because it is activationGroup to activate the object, it naturally knows that the object is active.

Below is an example of implementing ServerImpl for remote object interface Server and extended Activatable classes: package example;

Public Interface Server Extends Java.rmi.Remote {Public Void Doimportantstuff () THROWS JAVA.RMI.RemoteException;

public class ServerImpl extends Activatable implements Server {// initial configuration, constructors public ServerImpl (String codebase, MarshalledObject data) at the time of registration and export throws ActivationException, java.rmi.RemoteException {// activate the system to register the object, and then in // Export Super (CodeBase, Data, False, 0) on anonymous port;

// Activate and export constructor. This constructor is called during the activation process by // ActivationInstantiator.newinstance / / method to construct the object public serverImpl (ActivationID ID, MarshalledObject Data "throws java.rmi.RemoteException {// call the parent class constructor's constructor to // Object exports to RMI runtime. Super (ID, 0); // Initialize the object (for example, using data)}

Public void doimportntsTUFF () {...}}

Objects will be responsible for exporting yourself. The constructor of the Activatable is responsible for exporting objects to RMI runtime with active reference type UnicastRemoteObject, so the object to extend Activatable does not have to care about explicitly export objects (not calling the corresponding superclass constructor) specific details. If the object is not extended class Activatable, the object must explicitly export the object by calling an Activatable.exp ORTObject static method.

In the following example, ServerIMPL does not extend Activatable, but an extension of another class. Therefore, Serveri MPL is responsible for exporting themselves during initial constructing and activation. The following class definition gives the initial constructor of ServerIMPL and its special "activation" constructor, and corresponding calls for exporting objects in each constructor:

Package examples;

public class ServerImpl extends SomeClass implements Server {// constructor public ServerImpl (String codebase, MarshalledObject data) throws ActivationException, java.rmi.RemoteException {// register and export the object Activatable.exportObject (this, codebase, data at the time of initial creation, False, 0);

// Activated constructor PUBLIC ServerImpl (ActivationID ID, MarshalledObject Data) throws java.rmi.RemoteException {// Export Object Activatable.ExportObject (this, ID, 0);}

Public void doimportntsTUFF () {...}}

If the registration activation descriptor is registered without creating an object, the programmer is registered to activate the remote object without creating an object, and the programmer only needs to activate the object of the object (instance of class ActivationDesc). The activation descriptor contains all the information required, so the system can activate the object if necessary. The following method can be used to register the activation descriptor (ignore the exception handling): Server Server; ActivationDesc Desc; string codebase = "http: // zaphod / cod ebase /";

MarshalledObject Data = New MarshalledObject ("Some Data"); Desc = New A CTINVATIONDESC ("Examples.ServerImpl", CodeBase, DATA); Server = (Server) Activatable.Register (DESC);

The Register call returns a Remote Stub (which is the S TUB of the Examples.serverImpl object) and implements a set of remote interfaces that are implemented with Examples.serverImpl (ie, Stub implementation Remote Interface Server). The STUB object (the object of the forced type conversion and assignment to the Server) can be called as a parameter to be transmitted to any method of the object that implements an object of an Examples.server remote interface.

7.4 Active Interface In the RMI Activation Protocol, in order to make the system are operating normally, the activator must ensure that the following two points:

Like all system daemons, the activator must keep the active state activator when the computer is in an open state. The activator will maintain a corresponding information database for groups and objects it want to activate.

7.4.1 Activator Interface Activator is one of the entities involved in the activation process. As mentioned earlier, the imperfection reference in STUB will obtain "live" references to activate remote objects by calling the activator's Activate method. After the activator is connected to the activation request, the activation descriptor of the activation identifier ID is started to determine which group to activate the object, and then call the NewInstance method of the instantifier of the activation group (ActivationGROUP will be behind Description). The activator will start the execution process of the activation group as needed. For example, if the activation group of the resulting group descriptor has not yet run, the activator will generate a sub-virtual machine for the activation group to establish the group in the new virtual machine.

The activator will be responsible for monitoring and detecting when the activation group failed to remove the outdated remote reference from its internal table.

Package java.rmi.activation;

public interface Activator extends java.rmi.Remote {java.rmi.MarshalledObject activate (ActivationID id, boolean force) throws UnknownObjectException, ActivationException, java.rmi.RemoteException;}

Activate method activates the object associated with the activation identifier ID. If the actuator knows that the object is already an active object, and the force parameter is false, it will immediately contain the "live" references to the call to the call; if the activator does not know the corresponding remote object is the active or Force parameter is True, The activator will utilize activation descriptor information (previously registered with the ID) to determine which group (virtual machine) should be activated in which group (virtual machine) should be activated. If the corresponding activation of the object group already exists, the activator will call the NewInsta NCE method of the activation instantiator by passing the ID and an activation descriptor. If the active instantifier (group) of the object group descriptor is not existed, the actuator will initiate a new Activ ATIONInstantiator avatar implementation process (eg, by generating a sub-process). When the activator rebuilds ActivationInstantiator for a group, it must increase the number of the avatar of the group. Note that the number of avatars starts with 0. Activate the system used to detect the later Activationsystem.ActiveGroup and ActivationMonitor.inActiveGroup calls. The activation system will discard the call of the current number of the avatar than the group. -------------------------------------------------- ------------------------------

Note - Activator must communicate with the identifier, descriptor and avatar of the activation group when starting a new activation group. The actuator will generate an activation group in a separate virtual machine (e.g., as a separate process or child process). Therefore, it must pass the information to specify the information required to create the group with the ActivationGroup.createg Roup method. The activator does not specify how this information is transmitted to the generated process. This information can be sent to the standard input of the child process in the form of a group object.

-------------------------------------------------- ---------------------------- When the activator receives the callback of the activation group (via the ActivationSystem.activeGroup method, the callback can be indicated When the number of activation groups and the number of avatars can call the N E-EWInstance method of the activation instance device to forward each pending activation request to the activation instantiator, and will result (a packet remote object Quote, a stub) returns to each call.

Note that the activator receives the MarshalledObject object rather than the Remote object. Therefore, the activator does not need to load the code of the object, nor does it need to participate in distributed garbage collection of the object. If the activator retains a strong reference to the remote object, the activator will prevent the object from being treated as garbage under normal distributed garbage collection mechanism.

If the activation fails, the Activate method will throw an ActivationException. Activation may fail because of the following reasons: can't find the class, can not get in touch with the activation group. If you have not previously registered to the activation descriptor for the activation identifier ID, the Activate method will throw unknownObject Exception. If the remote call to the activator fails, the RemoteException is thrown.

7.4.2 ActivationSystem Interface Activationsystem provides a method for grouping and activatable objects (these objects will be activated in these groups). ActivationSystem and Activator and ActivationMonitor work closely together. The former is responsible for activating the objects registered by ActivationSystem; the latter is responsible for obtaining information about the activity object, the non-active object, and the non-active group. Package java.rmi.activation;

Public interface activationsystem extends java.rmi.remote {public static final int system_port = 1098;

ActivationGroupid RegisterGroup (ActivationGroupDesc ​​DESC) THROWS ACTIVATIONException, Java.rmi.RemoteException;

ActivationMonitor ActiveGroup (ActivationGroupid ID, ActivationInstantiator Group, Long Incarnation) throws unknownGroupException, ActivationException, Java.rmi.RemoteException;

Void UnregisterGroup (ActivationGroupid ID) Throws ActivationException, UNKNOWNGROUPEXCEPTION, JAVA.RMI.RemoteException;

ActivationID RegisterObject (ActivationDesc Desc) throws ActivationException, UNKNOWNGROUPEXCEPTION, JAVA.RMI.RemoteException;

Void UnregisterObject (ActivationID ID) Throws ActivationException, UNKNOWNOBJECTEXCEPTION, JAVA.RMI.RemoteException;

Void shutdown () throws java.rmi.remoteexception;

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

Note - As a security measures, all of the above methods (RegisterGroup, ActiveGroup, UnregisterObject, and shutdown) are called by the client, and the host is different from the host and the activation system, will throw Java. Rmi.accessex Ception. This exception is the subclass of java.rmi.RemoteException.

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

The RegisterObject method is used to register the activation descriptor DESC and also obtain the activation identifier for the activated remote object. ActivationSystem creates an Activative NID for the object specified by the descriptor DESC, and records the activation descriptor and its identifier in a stable repository for future use. When Activator receives an Activate request of a particular identifier, it looks for the activation descriptor of the specified identifier (previously registered), and uses this information to activate the object. If the group referenced in D ESC does not register to the system, the method will throw unknownGroupexcepti ON. If registration fails (for example, database update fails, etc.), throw ActivationException. If the remote call fails, it throws the RemoteException. The UnregisterObject method is used to delete an active identifier ID and a related descriptor that previously annotated to the Activationsystem. After this call is completed, the object cannot be activated again. If the ID of the object is unknown (not registered), the method will throw unknownObjectExce Partion. If the logout failed (for example, the update failed by the database, the method will throw Activa TionException. If the remote call fails, it throws the RemoteException.

The RegisterGroup method is used to activate the activation group specified to the activation system registration group descriptor DESC and return to the ActivationGroupID assigned to the group. The activation group must be registered with the Activationsystem to register the object in this group. If the group's registration fails, the method will throw an Activati ​​Onexception. If the remote call fails, it throws the RemoteException.

The ActiveGroup method is a callback from ActivationGroup (with identifier ID) to notify the activation system: The group is now active, and also the virtual machine ActivationInstant Iater. This callback is performed inside the ActivationGroup.createGroup method to get ActiVationMonitor. The group will use the ActivationMonitor to update the system on the status of objects and groups (ie, groups and objects in this group have become non-active). If the group is not registered, you will throw unknownGroupexception. If the group is already active, the ActivationException is thrown. If the remote call of the activation system fails, the RemoteException is thrown.

The UnregisterGroup method will delete the activation group with the identifier ID from the activation system. The activation group will make this callback to notify the activator to destroy the group. If this call is successfully completed, you will not be able to register and activate the object in this group. All information about this group and its related objects will be removed from the system. If the group is not registered, the method will throw unknownGroupexception. If the remote call fails, it throws the RemoteException. If the logout failed (such as database update fails, etc.), throw an ActivationException.

The shutdown method will terminate the activation system and all related activation processes (activators, monitors, and groups) in an appropriate asynchronous manner. All groups generated by the activation daemon will be destroyed, and the activation daemon will also exit. To turn off the activation system daemon RMID, execute the command: rmid -stop [- port number]

This command will turn off the activation daemon on the specified port (if not specified port, turn off the daemon on the default port).

7.4.3 ActivationMonitor class ActivationMonitor is ActivationGroup unique, which can be obtained by calling ActivationSy Stem.ActiveGroup to report a group (this call is performed inside the ActivationGroup.crea tegroup method). The activation group is responsible for notifying Activationmon ITOR: its objects have become an active object, non-active object, or the group has become non-active.

Package Java.rmi.Activation; Public Interface ActivationMonitor Extends Java.rmi.Remote {

Public Abstract Void InactiveObject (ActivationID ID) THROWS UNKNOBJECTEXCEPTION, RemoteException;

Public void ActiveObject (ActivationID ID, Java.rmi.MarshalledObject Mobj) throws unknownObjectException, java.rmi.RemoteException;

Public void inactivegroup (activationgroupid ID, long incarnation) throws unknownGroupException, java.rmi.remoteexception;}

When an object in the activation group becomes a non-active (deactivated), the activation group will call the INA CTINBJECT method of its monitor. The activation group discovered whether objects in its virtual machine (this object participated in activation) were inactive by calling its InactiveObject method.

InactiveObject Call will notify the ActivationMonitor that the remote object reference with the object with the activation identifier ID is no longer valid. The monitor will treat the reference to the ID as outdated. Since this reference is cited as an outgoing reference, the ACTIVAT E calls performed after the same activation identifier will cause remote objects to be reactivated. If the object is unknown to the ActivationMonitor, this method will throw unknownObjectException. If the remote call fails, the RemoteExce Ption is thrown.

ActiveObject call Notification ActivationMonitor and ID The object is now active. Parameter OBJ is a group representation of the STUB of the object. If an object in the group is activated through other methods, not by the system (that is, the object is registered and "activating" yourself), the ActivationGroup must notify the monitor. If the identifier of the object is not registered, the method will throw unknownObjectException. If the remote call fails, it throws the RemoteException.

InactiveGroup call notification Monitor The group specified by ID and Incarnation is now inactive. Once the next request appears in the request of the active object in this group, the group will be renovated with a larger avatar. When all objects in the group report that they have been inactive, the group becomes a non-active group. If the ID is not registered, or the number of body is smaller than the current number of inclusions of the group, the method will throw unknownGroupexception. If the remote call fails, the RemoteExcepti ON is thrown. 7.4.4 ActivationInstantiator class ActivationInstantiator is responsible for creating an instance of an active object. The specific subclasses of ActivationGroup implements the NewInstance method to control the process of creating objects within the group.

Package java.rmi.activation;

Public Interface ActivationInstantiator Extends Java.rmi.Remote {Public MarshalledObject NewInstance (ActivationID ID, ActivationDesc Desc) Throws ActivationException, Java.rmi.RemoteException;}

In order to recreate an object with an activation identifier ID, a descriptor DESC, the activator needs to call the NewInstance method of the instantifier. The instance is responsible:

Use the getClassName method of the descriptor to determine the class of the object; the class (with getLocation method) is loaded from the CADEBase path obtained by the descriptor; the instance of this class is created by the special "activation" constructor of the class class. . This special constructor has two parameters: one is an object's ActivationID, and the other is a MARSHALLEDOBJECT containing an object-specific initial data; returns a MarshalledObject that contains the remote object it creates. The instance device is also responsible for reporting when it created or activated is no longer an active object, so it can perform the corresponding INACTIVEOBJECT call (details, see the ActivationGroup class) on its ActivationMonitor.

If the activation of the object fails, the NewInstance method will throw an ActivationException. If the remote call fails, the method will throw RemoteException.

7.4.5 ActivationGroupDesc ​​Class Activation Group Descriptor ActivationGroupDesc ​​The information you need to create or recreate the activation group (which will activate the same Java virtual machine on the activation group).

This descriptor contains:

The class name of the group, the group's CADEBase path (location of the group), "Group" object, which can contain object-specific initialization data. The class of objects must be a specific subclass of ActivationGroup. ActivationGroup subclasses are created or recreated with an ActivationGroup.createGroup static method, which will call special constructors containing the following two parameters:

The group's ActivationGroupId, the initialization data of this group (in java.rmi.marshalledObject)

Package java.rmi.activation;

Public Final Class ActivationGroupDesc ​​imports java.io.serializable {

public ActivationGroupDesc ​​(java.util.Properties props, CommandEnvironment env) ;; public ActivationGroupDesc ​​(String className, String codebase, java.rmi.MarshalledObject data, java.util.Properties props, CommandEnvironment env);

Public string getclassname ();

Public string getLocation ();

Public java.rmi.marshalledObject getdata ();

Public commandenvironment getcommandenvironment ();

Public Java.util.properties getPropertiesoverrides ();

} The first constructor will create a group descriptor that uses the default value of the system to the implementation and code location. Each property specifies the Java environment overlay (it will override the system properties in the virtual machine). The command environment can control the exact commands / options used when the promoter virtual machine can also be NULL to accept the default value of the RM ID.

The second constructor is the same as the first, but it allows the specified Properties and Commandenvironm Ent.

GetClassName method returns the group name.

GetLocation method Returns the CADEBASE path to load the class of the group.

The getData method returns the initialization data of the group in group form.

The getcommandenvironment method returns the command environment (possibly null).

The GetPropertiesoverrides method returns the properties of the descriptor (possibly null).

7.4.6 ActivationGroupDesc.comMandenvironment class Commandenvironment class Allows overwriting the default system properties and can specify options defined by the implementation for ActivationGrou P.

Public Static Class Commandenvironment

implements java.io.Serializable {public CommandEnvironment (String cmdpath, String [] args); public boolean equals (java.lang.Object); public String [] getCommandOptions (); public String getCommandPath (); public int hashCode (); }

The constructor will create Commandenv Ironment with the give command cmdpath and another command line option args.

Equals implement the content equivalent operation of the command environment object. Appropriate implementation of the HashCode method can be stored in the hash table when necessary.

GetCommandOptions method Returns the command line option for the environment object.

GetCommandPath method Returns the command string of the environment object.

7.4.7 The identifier of the activation group registered by the ActivationGroupID class can have the following uses:

The unique identifier of the group is uniquely identified in the activation system contains references to the group's activation system, and thus the component can contact it to activate the system. ActivationGroupID will be returned while calling Activationsystem.RegisterGroup and is used to identify the group within the activation system. When creating or recreating activation groups, the group identifier will be made as a special constructor for the active group.

Package java.rmi.activation;

Public class activitygroupid item java.io.serializable {public activity intersystem; public activationsystem getSystem ();

Public Boolean Equals (Object Obj);

Public Int hascode ();

The ActivationGroupID constructor creates a unique group identifier. The Activationsys Tem of this identifier is System.

GetSystem method returns to the group's activation system.

The HashCode method returns the hash code of the group identifier. Two group identifiers to the same remote group will have the same hash code.

The equals method compares the equivalence of the contents of the two group identifiers. If the following two conditions are established, the method will return TRUE: 1) Two unique identifiers are equivalent to the content. 2) The activation system specified in each identifier is referenced by the same remote object.

7.4.8 ActivationGroup class ActivationGroup is responsible for creating a new instance of the "Activated" object in its group, and notifies its ActivationMonitor when the following is the following: The object is turned into activity or non-active, or the entire group becomes non-active.

ActivationGroup was originally created by one of the following methods:

As the departure of the "Default" ActivationDesc, a "default" ActivationDesc, creating an explicit call to the ActivationGroup.createGroup method, is created as a deputy efficiency when the first object is activated in the group (which is only ActiVationGroupDesc ​​registered). create. Only the activator can recreate ActivationGroup. If necessary, the actuator will generate a separate virtual machine (e.g., as a sub-process) for each registered activation group and direct the active request to the corresponding group. The way to generate virtual machines is related to implementation. The activation group is created by the ActivationGroup.createGroup static method. The CreateGroup method has two requirements for the upcoming group: 1) This group must be a specific subclass of ActivationGroup; 2) This group must have a constructor that takes the following two parameters:

The ActivationGroupId of the group, the initialization data (included in MarshalledObject) is created, and the default implementation of ActivationGroup will set the system properties to force system properties when creating the group's ActivationGroupDesc, and set the security manager to Java. Rmi.rmisecu RityManager. If the application requires some specific properties when the object is activated in the group, the application should set these properties before creating ActivationDesc (before the default ActivationGroupDesc ​​created).

Package java.rmi.activation;

Public Abstract Class ActivationGroup Extends UnicastRemoteObject Implements ActivationInstantiator {Protected ActivationGroup (ActivationGroupid GroupID) THROWS JAVA.RMI.RemoteException;

Public Abstract MarshalledObject NewInstance (ActivationID ID, ActivationDesc Desc) Throws ActivationException, Java.rmi.RemoteException;

public abstract boolean inactiveObject (ActivationID id) throws ActivationException, UnknownObjectException, java.rmi.RemoteException; public static ActivationGroup createGroup (ActivationGroupID id, ActivationGroupDesc ​​desc, long incarnation) throws ActivationException;

Public static activationgroupid currentGroupId ();

Public Static Void Setsystem (ActivationSystem System) Throws ActivationException;

Public static activationsystem getSystem () throws activityException;

Protected Void ActiveObject (ActivationID ID, Java.rmi.MarshalledObject Mobj) Throws ActivationException, UNKNOWNOBJECTEXCEPTION, JAVA.RMI.RemoteException;

Protected void inactivegroup () throws unknownGroupException, java.rmi.RemoteException;

Activation activates an object with activation descriptor DESC by calling the NewInstance method of the activation group. The activation group is responsible:

The class of the object is determined by the getClassName method of the descriptor; load this class from the URL path obtained in the descriptor by the getLocation method; instance of this class is created by calling the special constructor of the object class. This constructor takes two variables: object's ActivationID and MarshalledObject containing object initialization data; the serialization version of the remote object that will be created is returned to the activator. If you cannot create an instance of the descriptor, the method will throw an ActivationException.

The call to the inactiveObject method for this group is indirect by calling the active.inactive method. When the remote object is deactivated (this object is considered non-active), the implementation of the object must call the Activatable INact. If the object does not call Activatable.i Nactive when non-active, the object will never be collected as garbage because the group will reserve strong references to the object it created.

The group's INACTIVEOBJECT method prevents the remote object associated with the ID from the RMI runtime (only when there is no call to the object to be determined or being executed). Make the object will not be able to receive the RMI call. If the object is currently available or being called, INACTIVEOBJECT will return false and do not take any action.

If UNEXPORTOBJECT operations success, it means that the object does not have a call to be determined or being executed. This time group will notify its ActivationMonitor that the remote object is currently non-active by the monitor's INACTIVEOBJECT method so that the activator will re-activate the remote object when receiving the next activation request. If the operation is successful, INACTIVEOBJECT will return True. If the object is considered active by ActivationG Roup but has been prevented from being exported, the operation will still be successful.

If the activation group does not know the object (for example, the object has previously reported to be non-active, or if the activation group is not active, the inactiveObject method will throw unknownObjectEx Ception. If the non-active operation fails (for example, the remote call of the actuator or activation group fails), the RemoteException will be thrown. The CreateGroup method will create and set up the activation group for the current virtual machine. It is only possible to set it only if the activation group is currently not set. When Activator starts a recreation process of an activation group in order to perform the Activate request, the activation group is set by the CreateGroup method. The group must first register a descriptor to the Activationsystem, and then you can create the group with this method (passing the ActivationID to it).

The group specified by ActivationGroupDesc ​​(ie DESC) must be the specific subclass of ActivationGroup and has a common constructor. The common constructor takes two parameters: one is a group's Activative NGroupID; the other is MarshalledObject, which contains the group's initialization data (obtained from the group's Activ atGroupDesc). Note: If the application wants to create its own custom activation group, the group must set the security manager in the constructor. Otherwise, the object will not be activated in this group.

After creating a group, the ActivationSystem This group has been activated by calling the ActiveGroup method (this method will return the ActiVationMonitor). Applications do not have to be called alone because the CreateGroup method will be responsible for this call.

Once the group is created, subsequent calls to the currentgroupID method will return the identifier of the group until the group becomes a non-active group. At that time, the currentgroupid method returned NULL.

Parameters incarnation indicates the current grouping, that is, the number of times the group is activated. Once the group is created, the avatar is used as a parameter of the ActiveGroup method. The number of avatars starts with 0. If the group already exists, the CreateGroup method will throw an ActivationE Xcection.

Setsystem method is used to set up ActivationSystem (System) of the virtual machine. The activation system can be set to the activation system only if there is currently no grouping event group. If you do not have an activation system by explicitly calling SetSystem, the getSystem method will try to get a reference to Activationsystem by checking the name java.rmi.activation.activationsystem in an Activator's registration service program. By default, the port number used to find the activation system will be defined by ActivationSystem.SYST EM_PORT. This port can be overwritten by setting the properties java.rmi.activation.port. If you call SetSystem, the activation system has been set, then the method will throw an ActivationExce Ption.

The GetSystem method returns the activation system of the virtual machine. The activation system can be set by the setsystem method (aforementioned).

The ActiveObject method is a protected approach. Subclasses will use it to make an Active Object callback to the group monitor to notify the monitor with a remote object that specifies the activation ID and its stub is now active. This call just forwards the ActivationMonitor to the group. The InactiveGroup method is a protected approach. Subclasses use it to notify the group monitor This group has become non-active. When the objects that activate the activity in the group in the group become non-active, the subclasses are called.

7.4.9 MARSHALLEDOBJECT class MarshalledObject is a container for an object, which allows the object as a parameter when the RMI call is performed, but it delays the sequence recovery of the object in the receiving end until the application explicitly requests This object (by calling the container object). The sequential object contained in this MarshalledObject is serialized and serially recovered (requests when transmitting parameters in the RMI call) (request). That is, any of the remote objects in MarshalledObject can be shown as a serialization example of its STUB. The objects included in MarshalledObject can be a full graphic for remote objects, non-remote objects, or remote objects and non-remote objects.

When the object is placed in the Wrapper of MarshalledObject, the sequence form of the object will be commented as CADEBASE URL (which can be loaded); also, when the object is removed from the Wrapper from the object's MarshaledObject, if the local does not The code of the object is used to locate and load the byte code of the object class using the URL (serialized).

Package java.rmi;

Public Final Class MarshalledObject Implements Java.io.Serializable {Public MarshalledObject (Object Obj) THROWS JAVA.IOEXCEPTION;

Public Object Get () throws java.io.ioException, ClassNotFoundException

Public int hashcode ();

Public Boolean Equals ();

The constructor of MarshalledObject will serve as a single parameter, and store the group of objects in the byte stream. The object's group indicates the semantics that the object is transmitted when the object is transmitted during the RMI call:

Each class in the stream is annotated as its CADEBASE URL to find the byte code of each class when reconstructing the object (by calling the GET method); the remote object is replaced by their proxy server stub. When the instance of the class MarshalledObject is written in java.io.ObjectOutputStream, the group form (created in the configuration) is also written in the stream. Therefore, only word throttle is serialized.

When you read MarshaledObject from Java.io.ObjectInputStream, the included object sequence is not returned to a specific object; the object will always maintain its group representation until the GET method of the set group object is called.

The GET method always uses the form of the object contained to reconstruct the object. The internal representation will be serialized with the semantics used in the decnation parameter (for RMI call). Therefore, the sequence of sequence represented by the object will be loaded with the URL annotation in the stream of the target (if there is no code). The HashCode represented by the object group is the same as the object passed to the constructor. If the group representation of the comparison object is equivalent, the Equals method will return true. The equals method is annotated than the CADEBASE of the ignored class, that is, in addition to the CADEBASE of each class in serialization, only two objects have the same serialization, the two objects are equivalent.

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

New Post(0)