01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.l2.msg;
06:
07: import com.tc.async.api.EventContext;
08: import com.tc.net.groups.AbstractGroupMessage;
09: import com.tc.net.groups.MessageID;
10: import com.tc.net.groups.NodeID;
11: import com.tc.net.groups.NodeIDSerializer;
12: import com.tc.object.tx.ServerTransactionID;
13: import com.tc.object.tx.TransactionID;
14: import com.tc.util.Assert;
15:
16: import java.io.IOException;
17: import java.io.ObjectInput;
18: import java.io.ObjectOutput;
19: import java.util.HashSet;
20: import java.util.Iterator;
21: import java.util.Set;
22:
23: public class ServerTxnAckMessage extends AbstractGroupMessage implements
24: EventContext {
25:
26: public static final int SERVER_TXN_ACK_MSG_TYPE = 0;
27:
28: private Set serverTxnIDs;
29:
30: private transient NodeID nodeID;
31:
32: // To make serialization happy
33: public ServerTxnAckMessage() {
34: super (-1);
35: }
36:
37: public ServerTxnAckMessage(NodeID nodeID, MessageID messageID,
38: Set serverTxnIDs) {
39: super (SERVER_TXN_ACK_MSG_TYPE, messageID);
40: this .nodeID = nodeID;
41: this .serverTxnIDs = serverTxnIDs;
42: }
43:
44: public Set getAckedServerTxnIDs() {
45: return serverTxnIDs;
46: }
47:
48: public NodeID getDestinationID() {
49: Assert.assertNotNull(nodeID);
50: return nodeID;
51: }
52:
53: protected void basicReadExternal(int msgType, ObjectInput in)
54: throws IOException, ClassNotFoundException {
55: Assert.assertEquals(SERVER_TXN_ACK_MSG_TYPE, msgType);
56: int size = in.readInt();
57: serverTxnIDs = new HashSet(size);
58: for (int i = 0; i < size; i++) {
59: NodeID cid = NodeIDSerializer.readNodeID(in);
60: long clientTxID = in.readLong();
61: serverTxnIDs.add(new ServerTransactionID(cid,
62: new TransactionID(clientTxID)));
63: }
64: }
65:
66: protected void basicWriteExternal(int msgType, ObjectOutput out)
67: throws IOException {
68: Assert.assertEquals(SERVER_TXN_ACK_MSG_TYPE, msgType);
69: out.writeInt(serverTxnIDs.size());
70: for (Iterator i = serverTxnIDs.iterator(); i.hasNext();) {
71: ServerTransactionID sTxID = (ServerTransactionID) i.next();
72: NodeIDSerializer.writeNodeID(sTxID.getSourceID(), out);
73: out.writeLong(sTxID.getClientTransactionID().toLong());
74: }
75: }
76:
77: }
|