KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > l2 > msg > ServerTxnAckMessage


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

5 package com.tc.l2.msg;
6
7 import com.tc.async.api.EventContext;
8 import com.tc.net.groups.AbstractGroupMessage;
9 import com.tc.net.groups.MessageID;
10 import com.tc.net.groups.NodeID;
11 import com.tc.net.protocol.tcm.ChannelID;
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 JavaDoc;
17 import java.io.ObjectInput JavaDoc;
18 import java.io.ObjectOutput JavaDoc;
19 import java.util.HashSet JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.Set JavaDoc;
22
23 public class ServerTxnAckMessage extends AbstractGroupMessage implements EventContext {
24
25   public static final int SERVER_TXN_ACK_MSG_TYPE = 0;
26
27   private Set JavaDoc serverTxnIDs;
28
29   private transient NodeID nodeID;
30
31   // To make serialization happy
32
public ServerTxnAckMessage() {
33     super(-1);
34   }
35
36   public ServerTxnAckMessage(NodeID nodeID, MessageID messageID, Set JavaDoc serverTxnIDs) {
37     super(SERVER_TXN_ACK_MSG_TYPE, messageID);
38     this.nodeID = nodeID;
39     this.serverTxnIDs = serverTxnIDs;
40   }
41
42   public Set JavaDoc getAckedServerTxnIDs() {
43     return serverTxnIDs;
44   }
45   
46   public NodeID getDestinationID() {
47     Assert.assertNotNull(nodeID);
48     return nodeID;
49   }
50   
51   protected void basicReadExternal(int msgType, ObjectInput JavaDoc in) throws IOException JavaDoc {
52     Assert.assertEquals(SERVER_TXN_ACK_MSG_TYPE, msgType);
53     int size = in.readInt();
54     serverTxnIDs = new HashSet JavaDoc(size);
55     for (int i = 0; i < size; i++) {
56       long cid = in.readLong();
57       long clientTxID = in.readLong();
58       serverTxnIDs.add(new ServerTransactionID(new ChannelID(cid), new TransactionID(clientTxID)));
59     }
60   }
61
62   protected void basicWriteExternal(int msgType, ObjectOutput JavaDoc out) throws IOException JavaDoc {
63     Assert.assertEquals(SERVER_TXN_ACK_MSG_TYPE, msgType);
64     out.writeInt(serverTxnIDs.size());
65     for (Iterator JavaDoc i = serverTxnIDs.iterator(); i.hasNext();) {
66       ServerTransactionID sTxID = (ServerTransactionID) i.next();
67       out.writeLong(sTxID.getChannelID().toLong());
68       out.writeLong(sTxID.getClientTransactionID().toLong());
69     }
70   }
71
72 }
73
Popular Tags