KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > object > msg > ClientHandshakeAckMessageImpl


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

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 JavaDoc;
17 import java.util.HashSet JavaDoc;
18 import java.util.Iterator JavaDoc;
19 import java.util.Set JavaDoc;
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 JavaDoc allNodes = new HashSet JavaDoc();
30   private long oidStart;
31   private long oidEnd;
32   private boolean persistentServer;
33   private String JavaDoc 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 JavaDoc i = allNodes.iterator(); i.hasNext();) {
51       putNVPair(ALL_NODES, (String JavaDoc) i.next());
52     }
53
54     putNVPair(THIS_NODE_ID, thisNodeId);
55   }
56
57   protected boolean hydrateValue(byte name) throws IOException JavaDoc {
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 JavaDoc[] getAllNodes() {
104     return (String JavaDoc[]) allNodes.toArray(new String JavaDoc[] {});
105   }
106
107   public String JavaDoc getThisNodeId() {
108     return thisNodeId;
109   }
110
111   private static String JavaDoc toString(ChannelID cid) {
112     return String.valueOf(cid.toLong());
113   }
114
115 }
116
Popular Tags