1 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 ; 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 EventContext { 24 25 public static final int SERVER_TXN_ACK_MSG_TYPE = 0; 26 27 private Set serverTxnIDs; 28 29 private transient NodeID nodeID; 30 31 public ServerTxnAckMessage() { 33 super(-1); 34 } 35 36 public ServerTxnAckMessage(NodeID nodeID, MessageID messageID, Set serverTxnIDs) { 37 super(SERVER_TXN_ACK_MSG_TYPE, messageID); 38 this.nodeID = nodeID; 39 this.serverTxnIDs = serverTxnIDs; 40 } 41 42 public Set 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 in) throws IOException { 52 Assert.assertEquals(SERVER_TXN_ACK_MSG_TYPE, msgType); 53 int size = in.readInt(); 54 serverTxnIDs = new HashSet (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 out) throws IOException { 63 Assert.assertEquals(SERVER_TXN_ACK_MSG_TYPE, msgType); 64 out.writeInt(serverTxnIDs.size()); 65 for (Iterator 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 |