KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > objectserver > handler > CommitTransactionChangeHandler


1 /*
2  * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
3  * notice. All rights reserved.
4  */

5 package com.tc.objectserver.handler;
6
7 import com.tc.async.api.AbstractEventHandler;
8 import com.tc.async.api.ConfigurationContext;
9 import com.tc.async.api.EventContext;
10 import com.tc.objectserver.context.CommitTransactionContext;
11 import com.tc.objectserver.core.api.ServerConfigurationContext;
12 import com.tc.objectserver.gtx.ServerGlobalTransactionManager;
13 import com.tc.objectserver.persistence.api.PersistenceTransaction;
14 import com.tc.objectserver.persistence.api.PersistenceTransactionProvider;
15 import com.tc.objectserver.tx.ServerTransactionManager;
16 import com.tc.objectserver.tx.TransactionalObjectManager;
17
18 import java.util.Collection JavaDoc;
19
20 public class CommitTransactionChangeHandler extends AbstractEventHandler {
21
22   private ServerTransactionManager transactionManager;
23   private final ServerGlobalTransactionManager gtxm;
24   private final PersistenceTransactionProvider ptxp;
25   private TransactionalObjectManager txnObjectManager;
26
27   public CommitTransactionChangeHandler(ServerGlobalTransactionManager gtxm, PersistenceTransactionProvider ptxp) {
28     this.gtxm = gtxm;
29     this.ptxp = ptxp;
30   }
31
32   public void handleEvent(EventContext context) {
33     CommitTransactionContext ctc = (CommitTransactionContext) context;
34     txnObjectManager.commitTransactionsComplete(ctc);
35     if (ctc.isInitialized()) {
36       Collection JavaDoc appliedTxns = ctc.getAppliedServerTransactionIDs();
37       PersistenceTransaction ptx = ptxp.newTransaction();
38       transactionManager.release(ptx, ctc.getObjects(), ctc.getNewRoots());
39       gtxm.commitAll(ptx, appliedTxns);
40       gtxm.completeTransactions(ptx, ctc.getCompletedTransactionIDs());
41       ptx.commit();
42       transactionManager.committed(appliedTxns);
43     }
44   }
45
46   public void initialize(ConfigurationContext context) {
47     super.initialize(context);
48     ServerConfigurationContext scc = (ServerConfigurationContext) context;
49     this.transactionManager = scc.getTransactionManager();
50     this.txnObjectManager = scc.getTransactionalObjectManager();
51   }
52
53 }
54
Popular Tags