001: /*
002: * All content copyright (c) 2003-2006 Terracotta, Inc., except as may otherwise be noted in a separate copyright
003: * notice. All rights reserved.
004: */
005: package com.tc.object.msg;
006:
007: import com.tc.bytes.TCByteBuffer;
008: import com.tc.io.TCByteBufferOutput;
009: import com.tc.net.protocol.tcm.MessageChannel;
010: import com.tc.net.protocol.tcm.MessageMonitor;
011: import com.tc.net.protocol.tcm.TCMessageHeader;
012: import com.tc.net.protocol.tcm.TCMessageType;
013: import com.tc.object.session.SessionID;
014:
015: import java.io.IOException;
016: import java.util.HashSet;
017: import java.util.Iterator;
018: import java.util.Set;
019:
020: public class ClientHandshakeAckMessageImpl extends DSOMessageBase
021: implements ClientHandshakeAckMessage {
022:
023: private static final byte OBJECT_ID_START_SEQUENCE = 1;
024: private static final byte OBJECT_ID_END_SEQUENCE = 2;
025: private static final byte PERSISTENT_SERVER = 3;
026: private static final byte ALL_NODES = 4;
027: private static final byte THIS_NODE_ID = 5;
028: private static final byte SERVER_VERSION = 6;
029:
030: private final Set allNodes = new HashSet();
031: private long oidStart;
032: private long oidEnd;
033: private boolean persistentServer;
034: private String this NodeId;
035: private String serverVersion;
036:
037: public ClientHandshakeAckMessageImpl(SessionID sessionID,
038: MessageMonitor monitor, TCByteBufferOutput out,
039: MessageChannel channel, TCMessageType type) {
040: super (sessionID, monitor, out, channel, type);
041: }
042:
043: public ClientHandshakeAckMessageImpl(SessionID sessionID,
044: MessageMonitor monitor, MessageChannel channel,
045: TCMessageHeader header, TCByteBuffer[] data) {
046: super (sessionID, monitor, channel, header, data);
047: }
048:
049: protected void dehydrateValues() {
050: putNVPair(OBJECT_ID_START_SEQUENCE, oidStart);
051: putNVPair(OBJECT_ID_END_SEQUENCE, oidEnd);
052: putNVPair(PERSISTENT_SERVER, persistentServer);
053:
054: for (Iterator i = allNodes.iterator(); i.hasNext();) {
055: putNVPair(ALL_NODES, (String) i.next());
056: }
057:
058: putNVPair(THIS_NODE_ID, this NodeId);
059: putNVPair(SERVER_VERSION, serverVersion);
060: }
061:
062: protected boolean hydrateValue(byte name) throws IOException {
063: switch (name) {
064: case OBJECT_ID_START_SEQUENCE:
065: oidStart = getLongValue();
066: return true;
067: case OBJECT_ID_END_SEQUENCE:
068: oidEnd = getLongValue();
069: return true;
070: case PERSISTENT_SERVER:
071: persistentServer = getBooleanValue();
072: return true;
073: case ALL_NODES:
074: allNodes.add(getStringValue());
075: return true;
076: case THIS_NODE_ID:
077: this NodeId = getStringValue();
078: return true;
079: case SERVER_VERSION:
080: serverVersion = getStringValue();
081: return true;
082: default:
083: return false;
084: }
085: }
086:
087: public void initialize(long start, long end, boolean persistent,
088: Set allNodeIDs, String this NodeID, String sv) {
089: this .oidStart = start;
090: this .oidEnd = end;
091: this .persistentServer = persistent;
092: this .allNodes.addAll(allNodeIDs);
093:
094: this .this NodeId = this NodeID;
095: this .serverVersion = sv;
096: }
097:
098: public long getObjectIDSequenceStart() {
099: return oidStart;
100: }
101:
102: public long getObjectIDSequenceEnd() {
103: return oidEnd;
104: }
105:
106: public boolean getPersistentServer() {
107: return persistentServer;
108: }
109:
110: public String[] getAllNodes() {
111: return (String[]) allNodes.toArray(new String[] {});
112: }
113:
114: public String getThisNodeId() {
115: return this NodeId;
116: }
117:
118: public String getServerVersion() {
119: return serverVersion;
120: }
121: }
|