1 5 package com.tc.object.msg; 6 7 import com.tc.bytes.TCByteBuffer; 8 import com.tc.io.TCByteBufferOutput; 9 import com.tc.net.protocol.tcm.ChannelID; 10 import com.tc.net.protocol.tcm.MessageChannel; 11 import com.tc.net.protocol.tcm.MessageMonitor; 12 import com.tc.net.protocol.tcm.TCMessageHeader; 13 import com.tc.net.protocol.tcm.TCMessageType; 14 import com.tc.object.session.SessionID; 15 16 import java.io.IOException ; 17 import java.util.HashSet ; 18 import java.util.Iterator ; 19 import java.util.Set ; 20 21 public class ClientHandshakeAckMessageImpl extends DSOMessageBase implements ClientHandshakeAckMessage { 22 23 private static final byte OBJECT_ID_START_SEQUENCE = 1; 24 private static final byte OBJECT_ID_END_SEQUENCE = 2; 25 private static final byte PERSISTENT_SERVER = 3; 26 private static final byte ALL_NODES = 4; 27 private static final byte THIS_NODE_ID = 5; 28 29 private final Set allNodes = new HashSet (); 30 private long oidStart; 31 private long oidEnd; 32 private boolean persistentServer; 33 private String thisNodeId; 34 35 public ClientHandshakeAckMessageImpl(MessageMonitor monitor, TCByteBufferOutput out, MessageChannel channel, 36 TCMessageType type) { 37 super(monitor, out, channel, type); 38 } 39 40 public ClientHandshakeAckMessageImpl(SessionID sessionID, MessageMonitor monitor, MessageChannel channel, 41 TCMessageHeader header, TCByteBuffer[] data) { 42 super(sessionID, monitor, channel, header, data); 43 } 44 45 protected void dehydrateValues() { 46 putNVPair(OBJECT_ID_START_SEQUENCE, oidStart); 47 putNVPair(OBJECT_ID_END_SEQUENCE, oidEnd); 48 putNVPair(PERSISTENT_SERVER, persistentServer); 49 50 for (Iterator i = allNodes.iterator(); i.hasNext();) { 51 putNVPair(ALL_NODES, (String ) i.next()); 52 } 53 54 putNVPair(THIS_NODE_ID, thisNodeId); 55 } 56 57 protected boolean hydrateValue(byte name) throws IOException { 58 switch (name) { 59 case OBJECT_ID_START_SEQUENCE: 60 oidStart = getLongValue(); 61 return true; 62 case OBJECT_ID_END_SEQUENCE: 63 oidEnd = getLongValue(); 64 return true; 65 case PERSISTENT_SERVER: 66 persistentServer = getBooleanValue(); 67 return true; 68 case ALL_NODES: 69 allNodes.add(getStringValue()); 70 return true; 71 case THIS_NODE_ID: 72 thisNodeId = getStringValue(); 73 return true; 74 default: 75 return false; 76 } 77 } 78 79 public void initialize(long start, long end, boolean persistent, MessageChannel[] channels) { 80 this.oidStart = start; 81 this.oidEnd = end; 82 this.persistentServer = persistent; 83 84 for (int i = 0; i < channels.length; i++) { 85 allNodes.add(toString(channels[i].getChannelID())); 86 } 87 88 this.thisNodeId = toString(getChannelID()); 89 } 90 91 public long getObjectIDSequenceStart() { 92 return oidStart; 93 } 94 95 public long getObjectIDSequenceEnd() { 96 return oidEnd; 97 } 98 99 public boolean getPersistentServer() { 100 return persistentServer; 101 } 102 103 public String [] getAllNodes() { 104 return (String []) allNodes.toArray(new String [] {}); 105 } 106 107 public String getThisNodeId() { 108 return thisNodeId; 109 } 110 111 private static String toString(ChannelID cid) { 112 return String.valueOf(cid.toLong()); 113 } 114 115 } 116 | Popular Tags |