1 5 package com.tc.l2.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.exception.ImplementMe; 11 import com.tc.l2.context.IncomingTransactionContext; 12 import com.tc.l2.msg.RelayedCommitTransactionMessage; 13 import com.tc.l2.msg.RelayedCommitTransactionMessageFactory; 14 import com.tc.l2.objectserver.L2ObjectState; 15 import com.tc.l2.objectserver.L2ObjectStateManager; 16 import com.tc.logging.TCLogger; 17 import com.tc.logging.TCLogging; 18 import com.tc.net.groups.GroupException; 19 import com.tc.net.groups.GroupManager; 20 import com.tc.net.groups.NodeID; 21 import com.tc.net.protocol.tcm.ChannelID; 22 import com.tc.object.tx.ServerTransactionID; 23 import com.tc.objectserver.core.api.ServerConfigurationContext; 24 import com.tc.objectserver.tx.ServerTransactionManager; 25 26 import java.util.Iterator ; 27 import java.util.List ; 28 29 public class TransactionRelayHandler extends AbstractEventHandler { 30 private static final TCLogger logger = TCLogging.getLogger(TransactionRelayHandler.class); 31 32 33 private final L2ObjectStateManager l2ObjectStateMgr; 34 private GroupManager groupManager; 35 36 37 private ServerTransactionManager transactionManager; 38 39 public TransactionRelayHandler(L2ObjectStateManager objectStateManager) { 40 this.l2ObjectStateMgr = objectStateManager; 41 } 42 43 public void handleEvent(EventContext context) { 44 IncomingTransactionContext ict = (IncomingTransactionContext) context; 45 List states = l2ObjectStateMgr.getL2ObjectStates(); 46 for (Iterator i = states.iterator(); i.hasNext();) { 47 L2ObjectState state = (L2ObjectState) i.next(); 48 NodeID nodeID = state.getNodeID(); 49 if (state.isInSync()) { 50 sendCommitTransactionMessage(nodeID, ict); 52 } else { 53 System.err.println("WARNING :: Unimplemented yet - " + state ); 55 throw new ImplementMe(); 56 } 57 } 58 transactionManager.transactionsRelayed(ict.getChannelID(), ict.getServerTransactionIDs()); 59 } 60 61 private void sendCommitTransactionMessage(NodeID nodeID, IncomingTransactionContext ict) { 62 addWaitForNotification(nodeID, ict); 63 RelayedCommitTransactionMessage msg = RelayedCommitTransactionMessageFactory 64 .createRelayedCommitTransactionMessage(ict.getCommitTransactionMessage()); 65 try { 66 this.groupManager.sendTo(nodeID, msg); 67 } catch (GroupException e) { 68 logger.error("Removing " + nodeID + " from group because of Exception :", e); 69 groupManager.zapNode(nodeID); 70 } 71 } 72 73 private void addWaitForNotification(NodeID nodeID, IncomingTransactionContext ict) { 74 ChannelID waitee = nodeID.toChannelID(); 75 for (Iterator i = ict.getServerTransactionIDs().iterator(); i.hasNext();) { 77 ServerTransactionID stxnID = (ServerTransactionID) i.next(); 78 transactionManager.addWaitingForAcknowledgement(ict.getChannelID(), stxnID.getClientTransactionID(), waitee); 79 } 80 } 81 82 public void initialize(ConfigurationContext context) { 83 super.initialize(context); 84 ServerConfigurationContext oscc = (ServerConfigurationContext) context; 85 this.groupManager = oscc.getL2Coordinator().getGroupManager(); 86 this.transactionManager = oscc.getTransactionManager(); 87 } 88 } 89 | Popular Tags |