01: /*
02: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.objectserver.l1.impl;
06:
07: import com.tc.logging.TCLogger;
08: import com.tc.logging.TCLogging;
09: import com.tc.net.groups.NodeID;
10: import com.tc.net.protocol.tcm.MessageChannel;
11: import com.tc.net.protocol.tcm.TCMessageType;
12: import com.tc.object.msg.AcknowledgeTransactionMessage;
13: import com.tc.object.msg.BatchTransactionAcknowledgeMessage;
14: import com.tc.object.net.DSOChannelManager;
15: import com.tc.object.net.NoSuchChannelException;
16: import com.tc.object.tx.ServerTransactionID;
17: import com.tc.object.tx.TxnBatchID;
18: import com.tc.objectserver.tx.NoSuchBatchException;
19: import com.tc.objectserver.tx.TransactionBatchManager;
20:
21: /**
22: * @author steve
23: */
24: public class TransactionAcknowledgeActionImpl implements
25: TransactionAcknowledgeAction {
26: private final DSOChannelManager channelManager;
27: private final TCLogger logger = TCLogging
28: .getLogger(TransactionAcknowledgeActionImpl.class);
29: private final TransactionBatchManager transactionBatchManager;
30:
31: public TransactionAcknowledgeActionImpl(
32: DSOChannelManager channelManager,
33: TransactionBatchManager transactionBatchManager) {
34: this .channelManager = channelManager;
35: this .transactionBatchManager = transactionBatchManager;
36: }
37:
38: public void acknowledgeTransaction(ServerTransactionID stxID) {
39: try {
40: NodeID nodeID = stxID.getSourceID();
41: MessageChannel channel = channelManager
42: .getActiveChannel(nodeID);
43:
44: // send ack
45: AcknowledgeTransactionMessage m = (AcknowledgeTransactionMessage) channel
46: .createMessage(TCMessageType.ACKNOWLEDGE_TRANSACTION_MESSAGE);
47: m.initialize(stxID.getSourceID(), stxID
48: .getClientTransactionID());
49: m.send();
50:
51: // send batch ack if necessary
52: try {
53: if (transactionBatchManager.batchComponentComplete(
54: nodeID, stxID.getClientTransactionID())) {
55: BatchTransactionAcknowledgeMessage msg = channelManager
56: .newBatchTransactionAcknowledgeMessage(nodeID);
57: // We always send null batch ID since its never used - clean up
58: msg.initialize(TxnBatchID.NULL_BATCH_ID);
59: msg.send();
60: }
61: } catch (NoSuchBatchException e) {
62: throw new AssertionError(e);
63: }
64:
65: } catch (NoSuchChannelException e) {
66: logger
67: .info("An attempt was made to send a commit ack but the client seems to have gone away:"
68: + stxID);
69: return;
70: }
71: }
72: }
|