1 4 package com.tc.object.msg; 5 6 import com.tc.bytes.TCByteBuffer; 7 import com.tc.io.TCByteBufferOutput; 8 import com.tc.io.TCSerializable; 9 import com.tc.net.protocol.tcm.MessageChannel; 10 import com.tc.net.protocol.tcm.MessageMonitor; 11 import com.tc.net.protocol.tcm.TCMessageHeader; 12 import com.tc.net.protocol.tcm.TCMessageType; 13 import com.tc.object.ObjectID; 14 import com.tc.object.lockmanager.api.LockContext; 15 import com.tc.object.lockmanager.api.WaitContext; 16 import com.tc.object.session.SessionID; 17 import com.tc.object.tx.TransactionID; 18 import com.tc.util.SequenceID; 19 20 import java.io.IOException ; 21 import java.util.Collection ; 22 import java.util.HashSet ; 23 import java.util.Iterator ; 24 import java.util.Set ; 25 26 public class ClientHandshakeMessageImpl extends DSOMessageBase implements ClientHandshakeMessage { 27 28 private static final byte MANAGED_OBJECT_ID = 1; 29 private static final byte WAIT_CONTEXT = 2; 30 private static final byte LOCK_CONTEXT = 3; 31 private static final byte TRANSACTION_SEQUENCE_IDS = 4; 32 private static final byte PENDING_LOCK_CONTEXT = 5; 33 private static final byte RESENT_TRANSACTION_IDS = 6; 34 private static final byte REQUEST_OBJECT_IDS = 7; 35 36 private final Set objectIDs = new HashSet (); 37 private final Set lockContexts = new HashSet (); 38 private final Set waitContexts = new HashSet (); 39 private final Set pendingLockContexts = new HashSet (); 40 private final Set sequenceIDs = new HashSet (); 41 private final Set txnIDs = new HashSet (); 42 private boolean requestObjectIDs; 43 44 public ClientHandshakeMessageImpl(MessageMonitor monitor, TCByteBufferOutput out, MessageChannel channel, 45 TCMessageType messageType) { 46 super(monitor, out, channel, messageType); 47 } 48 49 public ClientHandshakeMessageImpl(SessionID sessionID, MessageMonitor monitor, MessageChannel channel, 50 TCMessageHeader header, TCByteBuffer[] data) { 51 super(sessionID, monitor, channel, header, data); 52 } 53 54 public void addObjectID(ObjectID objectID) { 55 synchronized (objectIDs) { 56 objectIDs.add(objectID); 57 } 58 } 59 60 public void addLockContext(LockContext ctxt) { 61 synchronized (lockContexts) { 62 lockContexts.add(ctxt); 63 } 64 } 65 66 public Collection getLockContexts() { 67 synchronized (lockContexts) { 68 return new HashSet (lockContexts); 69 } 70 } 71 72 public void addPendingLockContext(LockContext ctxt) { 73 synchronized (pendingLockContexts) { 74 pendingLockContexts.add(ctxt); 75 } 76 } 77 78 public Collection getPendingLockContexts() { 79 synchronized (pendingLockContexts) { 80 return new HashSet (pendingLockContexts); 81 } 82 } 83 84 public void addWaitContext(WaitContext ctxt) { 85 synchronized (waitContexts) { 86 waitContexts.add(ctxt); 87 } 88 } 89 90 public Collection getWaitContexts() { 91 synchronized (waitContexts) { 92 return new HashSet (waitContexts); 93 } 94 } 95 96 public Set getObjectIDs() { 97 synchronized (objectIDs) { 98 return new HashSet (objectIDs); 99 } 100 } 101 102 protected void dehydrateValues() { 103 for (Iterator i = objectIDs.iterator(); i.hasNext();) { 104 putNVPair(MANAGED_OBJECT_ID, ((ObjectID) i.next()).toLong()); 105 } 106 for (Iterator i = lockContexts.iterator(); i.hasNext();) { 107 putNVPair(LOCK_CONTEXT, (TCSerializable) i.next()); 108 } 109 for (Iterator i = waitContexts.iterator(); i.hasNext();) { 110 putNVPair(WAIT_CONTEXT, (TCSerializable) i.next()); 111 } 112 for (Iterator i = pendingLockContexts.iterator(); i.hasNext();) { 113 putNVPair(PENDING_LOCK_CONTEXT, (TCSerializable) i.next()); 114 } 115 for (Iterator i = sequenceIDs.iterator(); i.hasNext();) { 116 putNVPair(TRANSACTION_SEQUENCE_IDS, ((SequenceID) i.next()).toLong()); 117 } 118 for (Iterator i = txnIDs.iterator(); i.hasNext();) { 119 putNVPair(RESENT_TRANSACTION_IDS, ((TransactionID) i.next()).toLong()); 120 } 121 putNVPair(REQUEST_OBJECT_IDS, this.requestObjectIDs); 122 } 123 124 protected boolean hydrateValue(byte name) throws IOException { 125 switch (name) { 126 case MANAGED_OBJECT_ID: 127 objectIDs.add(new ObjectID(getLongValue())); 128 return true; 129 case LOCK_CONTEXT: 130 lockContexts.add(getObject(new LockContext())); 131 return true; 132 case WAIT_CONTEXT: 133 waitContexts.add(getObject(new WaitContext())); 134 return true; 135 case PENDING_LOCK_CONTEXT: 136 pendingLockContexts.add(getObject(new LockContext())); 137 return true; 138 case TRANSACTION_SEQUENCE_IDS: 139 sequenceIDs.add(new SequenceID(getLongValue())); 140 return true; 141 case RESENT_TRANSACTION_IDS: 142 txnIDs.add(new TransactionID(getLongValue())); 143 return true; 144 case REQUEST_OBJECT_IDS: 145 this.requestObjectIDs = getBooleanValue(); 146 return true; 147 default: 148 return false; 149 } 150 } 151 152 public Collection getTransactionSequenceIDs() { 153 return sequenceIDs; 154 } 155 156 public Collection getResentTransactionIDs() { 157 return txnIDs; 158 } 159 160 public void setTransactionSequenceIDs(Collection seqIDs) { 161 this.sequenceIDs.addAll(seqIDs); 162 } 163 164 public void setResentTransactionIDs(Collection resentTransactionIDs) { 165 this.txnIDs.addAll(resentTransactionIDs); 166 } 167 168 public void setIsObjectIDsRequested(boolean request) { 169 this.requestObjectIDs = request; 170 } 171 172 public boolean isObjectIDsRequested() { 173 return this.requestObjectIDs; 174 } 175 } 176 | Popular Tags |