Flow Diagram of Infrastructure’s Operation
Notes:
The figure above shows the general operation of the infrastructure for code mobility. Assume that a chunk of mobile code is about to be sent from one network component (the sender) to another (the receiver). Through the MCD’s migration facility (either via UDP or TCP connections) the sender sends the signed and compressed code (i.e., bytecode), the parameters and the persistent state obtained from serializing the instance of the mobile code. The receiver will receive and store them in the designated space for that particular mobile code. After the transmission is completed, the receiver verifies the code for authentication and data integrity. If the code passes the checks, it will be instantiated (subject to standard JVM security checks); otherwise, it will be discarded by the MCD. The mobile code may or may not have persistent state. If it has a persistent state, then the state will be restored by de-serializing it. That process will then be followed by calls to the methods onRestore() and onStart(). Otherwise, the mobile code will be instantiated and the methods onInit() and onStart() will be called. At this point, the mobile code is up and running as a thread. To access the managed resources, the agent obtains a handle to the VMCs from a so-called Mobile Code Manager (MCM). The methods in the agent’s code are called in an event-driven mode triggered by the MCD, other agents or the agent itself.
When an agent’s migration is requested by the manager, another agent, or the agent itself, the MCD calls method onMigrate() of the associated agent. This notifies the agent that it is about to be transported to the next destination. Therefore, the agent will have time to finish up its task and notify the MCD whether or not it wants to keep its persistent state or it refuses to migrate. If the agent really wants to migrate, the MCD will start shipping the agent with the associated persistent state as necessary. When the migration has completed, the agent is destroyed and removed from the MCD. On destroying the agent, the MCD calls the method onDestroy() to ensure that the agent stops its tasks and perhaps releases its memory space, acquired resources, etc.