Summary of the invention:
At the problems referred to above, the purpose of this invention is to provide a kind of dynamic migration method based on the EJB member.This method makes that on the J2EE application server EJB member can dynamically be moved to another node from a node in the time of running, does not interrupt the service to the client in the middle of transition process, and after migration is finished, member will continue to provide service on new node.
For solving the problems of the technologies described above, technical scheme of the present invention is as follows:
A kind of dynamic migration method of EJB member, with the EJB member dynamically from the source node server migration to the destination node server, comprise the steps:
(1) start the destination node server, the transmission member code is to the destination node server, disposes automatically and starts container;
(2) the destination node server is that agents document is called in the member generation, and the member container of destination node server blocks the request of client, calls agents document to the source node transmission;
(3) the source node server receive all call agents document after, beginning is to destination node server migration member example, the renewal that Enterprise Java Bean container on the source node calls the agency to client, client will newly ask to send to destination node automatically, and block buffer memory at destination node;
(4) after migration finishes, all member container operate as normal on the destination node, order is carried out the client-requested be buffered, accepts and carries out new client-requested, begins service.
The dynamic migration method of above-mentioned EJB member, in the described step (3), the source node server is when destination node server migration member, for the state session member is arranged, the source node server is operated the EJB example, the state that the member container is set is frozen state and extracts session status that the source node server sends the session status file that extracts to the destination node server.On destination server, locate the container of this EJB, recover the ready queue in the instance management device;
The dynamic migration method of above-mentioned EJB member, in the described step (3), the source node server is when destination node server migration member, and for the stateless session means, the source node server directly state of member container is set to frozen state.
The dynamic migration method of above-mentioned EJB member, in the described step (3), the source node server is when destination node server migration member, for entity component: the state that the member container is set is a frozen state, submits the state of current entity component to database.After finishing, migration from database, reads the state of this entity component.
The frozen state of described source node member container is meant, container is accepted client-requested, does not carry out client-requested, but the new agents document that calls is written in the result object that returns to client, and notify this member of client to be moved, request this time will not be performed.
Technique effect of the present invention is: method of the present invention has guaranteed that the state of member is consistent before and after the migration, guaranteed that the client requests in the transition process can access correct processing, do not lose, needn't stop to finish the transition process of member, make member under the situation that does not stop to serve, to move to another node from a node to client's service.This method can be so that member being reconstructed of the internodal distribution freedom and flexibility of difference, solves load balance, and member far call network overhead is excessive, to problems such as not transportable device resource conduct interviews.
Embodiment:
Accompanying drawing 1 has been illustrated the migration flow process of an EJB member.On source node and destination node, start 2 J2EE application server PKUAS respectively.PKUAS1 on source node and the destination node, PKUAS2 finish whole transition process under the control of management platform.
At first, start the PKUAS2 on the target node b, earlier the code packages of using is sent on the PKUAS2, PKUAS2 is with automatic application deployment, and for each EJB member is created corresponding Enterprise Java Bean container, this moment, PKUAS2 was in original state.After application and component deployment finished, management platform sent to PKUAS2 and begins migration (startload) instruction, and signal begins migration work and begins.PKUAS2 calls agents document for each member generates, and the state that the member container is set after the end is a frozen state.
Afterwards, PKUAS2 sends to send to PKUAS1 and calls agents document (send stubs) instruction, signal PKUAS1 begins to accept to call agents document, the agents document that calls that generates is sent to PKUAS1, treat all call agents document send finish after, PKUAS2 sends to management platform and calls agents document and send (sendstubs done) instruction that finishes.
Afterwards, management platform sends to PKUAS 1 and begins migration (start migration) instruction.After PKUAS1 receives this instruction, carry out different operations for different EJB: (1) for the state session member is arranged, the state that the member container is set is a frozen state, and the EJB example is operated, and extracts session status etc.Afterwards, PKUAS1 sends transmit status file (send session) instruction to PKUAS2, and sends the session status file that extracts.(2) for the stateless session means, owing to there is not session status, directly the state of member container is set to frozen state.(3) for entity component: the state that the member container is set is a frozen state, submits the state of current entity component to database.
After different EJB were finished above operation, PKUAS1 sent the session status file to management platform and is sent completely (send sessions done) instruction, finishes with the signal state of operation.Management platform sends migration to PKUAS2 and finishes (Load Finished) instruction, and the state that all member containers on the PKUAS2 are set is an active state.
Gordian technique wherein is as follows:
(1) treating method of the session status of EJB member example:
For the state session member is arranged, in the transition process, all current active instance that comprise in the ready queue of freezing container are to obtain the status information of whole examples; By the example of freezing, then directly from file system, extract its status information file for those.In the transition process, in PKUAS 2 deploy and after having started member, cell therefor is created automatically and is finished.The session status data transmission behind PKUAS2, on PKUAS 2, is located the container of this EJB, recover the ready queue in the instance management device.In this process, safeguard example session status ID, and session state data.Must guarantee the unanimity of the session status ID of example before and after the migration, prevent that the client from will lose session status before.
For no attitude session means, call all at every turn and from the example pond, to take out an example, call and put back to the example pond after finishing.
For entity component, example ID is the major key of the record that obtains when calling establishment (create) method.For the dynamic migration of entity component, the consistance of its state is finished by the persistence of database, before migration state is delivered in the database, reads from database after migration finishes.
(2) to the control of container state
The state of container is used to retrain the behavior of control container in the migration different phase.Source node and destination node have state separately respectively.
The container of source node has two states: active state (Active) and frozen state (Frozen).Original state (Initial) is an active state.
Active state: the container operate as normal, accept and carry out client-requested.When the Autonomic Migration Framework thread was opened, application server transmits on this state can the receiving target node new called agency (Stub).
Frozen state: container is accepted client-requested, does not carry out client-requested, but return results object (InvocationResponse, the encapsulation class of return results among the PKUAS).When container is in this state, container is written to the new agents document that calls in the result object that returns to client after receiving the request that client is sent, and this member of notice client moved, and request this time will not be performed.The container that enters behind this state will exist as the transfer mechanism of client requests, and is in this state after migration always.In the migration that the attitude session means is arranged, container just allows to send session state information to destination node after entering this state.
The container of destination node has three states: original state (Initial), active state (Active) and frozen state (Frozen).Specific as follows:
Original state (Initial): after container is created startup, be in this state, this state allows to generate automatically to call agents document.After generation is called agents document and finished, will transfer frozen state to.
Active state (Active): the container operate as normal, accept and carry out client-requested.Migration end (LoadFinished) can make container enter this state, and this moment, container was carried out the client requests that is buffered with order.
Frozen state (Frozen): container is accepted client-requested, does not carry out client-requested, also return results object not, but client-requested is blocked in the formation.In the migration that the attitude Session EJB is arranged, the session state information that just allows the reception sources node to send when container is in this state.
(3) to moving the disposal route that the back client requests takes place:
Adopt passive renewal client call agency's method, make client at the automatic linking objective node in request failure back.Before migration, the calling the agency and will be changed into byte stream by sequence of EJB on the destination node is transferred on the source node in the initial work of migration, for the container of source node the client that has connected upgraded.To destination node, the client requests obstruction that takes place in all transition processes also is buffered in destination node to client after the renewal with re-send request may.Client requests is not lost before and after having guaranteed migration.As shown in Figure 2, the EJB member in transition process, different migration phase, the method for the Request Processing that client is sent.1) before the migration (client was asked source node in the time period shown in the left oblique line), source node is in the activity attitude, and return results will be normally carried out in request.2) in transition process (client is in the request of sending of time period shown in the grid), source node is in frozen state, and the request of mailing to source node will not carried out, and bundle in the return results and call proxy information.Ask retransmitted (dotted line), and mail to destination node, destination node is in frozen state, so request is buffered, finishes up to migration, and the destination node state that reactivates is carried out again.Return results.3) after migration is finished (client is in the request of sending of time period shown in the right oblique line), the request of mailing to source node will not carried out, and bundle in the return results and call proxy information.Ask retransmitted (dotted line), and mail to destination node, destination node is in active state, and request is performed at destination node.Return results.
Method of the present invention is not moved member executing state data, by control migration opportunity, and the code data and the session state data of migration member.Method of the present invention is by freezing and recover to have the session state data of attitude EJB member example to guarantee the state consistency of member example before and after migration; No attitude EJB member example guarantees the state consistency of member example before and after migration by the persistence of database.In the method for the present invention, when source node EJB member moves, the agency (stub) that calls to client upgrades by former container, when asking the last time, returns the member information of having moved, and will call the agency and be transferred to client.After source node EJB member moves, and the agency is called in the client renewal, will transmit automatically and ask not finish as transition process to destination node, then block buffer memory and should ask at destination node, after the migration end, return to the client call result.
It below is a detailed process that the moving method of state session member is arranged.This EJB provides simple tally function, and current quantity (val) will store in the EJB example, and each subsequently client requests quantity of all will setting out adds one (val+1).When calling ejbCreate (), ejbRemove (), ejbPassivate (), ejbActive (), during operational approach count (), to screen output " ejbCreate () ", " ejbRemove () ", " ejbPassivate () ", " ejbActive () ", " count () ".
The first step: on 2 computer nodes of LAN (Local Area Network), start 2 PKUAS application server instance PKUAS1, PKUAS2.In client, search the Home interface, create 30 EJB objects by the Home interface, and give 30 EJB example initial values and be respectively 0-29.And call an operational approach count (), this moment, the val value of 30 examples was respectively 1-30.These 30 examples exist in the array, and input digit n is to call the count () method of n example of an order.Middle during this period of time client is communicated by letter with PKUAS1 always.The client-side program operation result is as follows:
Client:
Instantiating?beans...
1
2
29
30
Calling?count()on?beans...
Input digit: 0
The 0th EJB example val is: 2
Input digit: 1
The 1st EJB example val is: 3
Source node application server programs PKUAS1 operation result is as follows:
PKUAS1:
ejbCreate()
count()
ejbCreate()
count
count()
count()
Second step: access control platform, the member that appointment will be moved, migration beginning.Operation result is as follows: the process that can see PKUAS1 and PKUAS2 swap data.
PKUAS1:
15:29:29[Thread-41]MigrationThread(DEBUG)start?migrationServer..
15:29:49[Thread-41]MigrationThread(DEBUG)get?stub?from?client
15:29:49[Thread-41]MigrationThread(DEBUG)get?stubCount_stub.ser
15:29:49[Thread-41]MigrationThread(DEBUG)get?stub?done
15:29:49[Thread-41]MigrationService(DEBUG)startMigration()
ejbPassivate()
ejbPassivate()
ejbPassivate()
15:29:49[Thread-41]MigrationThread(DEBUG)send
session:3864058007490920451.ser
15:29:49[Thread-41]MigrationThread(DEBUG)send
session:3864058007490920452.ser
15:29:50[Thread-41]TestSvc(DEBUG)send?session:3864058007490920479.ser
15:29:50[Thread-41]TestSvc(DEBUG)send?session:3864058007490920480.ser
15:29:50[Thread-41]TestSvc(DEBUG)send?session?done
PKUAS2:
15:28:31[Thread-42]MigrationThread(DEBUG)start?migrationClient:
15:28:31[Thread-42]MigrationThread(DEBUG)connected
15:28:31[Thread-42]MigrationService(DEBUG)LoadStart()
15:28:31[Thread-42]MigrationThread(DEBUG)generated?stubs?done
15:28:31[Thread-42]MigrationThread(DEBUG)send?stub:Count_stub.ser
15:28:31[Thread-42]MigrationThread(DEBUG)send?stub?done
15:28:32[Thread-42]MigrationThread(DEBUG)get?session:
3864058007490920451.ser
15:28:32[Thread-42]MigrationThread(DEBUG)get?session:
3864058007490920452.ser
15:28:32[Thread-42]MigrationThread(DEBUG)get?session:
3864058007490920479.ser
15:28:32[Thread-42]MigrationThread(DEBUG)get?session:
3864058007490920480.ser
15:28:32[Thread-42]MigrationThread(DEBUG)get?session?done
15:28:32[Thread-42]MigrationService(DEBUG)LoadFinish()
The 3rd the step: client input digit 0 (calling the count () method of the 0th EJB), then this moment the 0th EJB example val be: 3, state is consistent, and this moment with client communication be PKUAS2.On PKUAS2, demonstrate recalls information.Expression member and all member instance migration complete successfully.
Client:
Instantiating?beans...
1
2
29
30
Calling?count()on?beans...
Input digit: 0
The 0th EJB example val is: 2
Input digit: 1
The 1st EJB example val is: 3
Input digit: 0
The 0th EJB example val is: 3
Input digit: 0
The 0th EJB example val is: 4
PKUAS2:
15:28:32[Thread-42]MigrationThread(DEBUG)get?session?done
15:28:32[Thread-42]MigrationService(DEBUG)LoadFinish()
ejbActive()
count()
count()