01: /*
02: * All content copyright (c) 2003-2007 Terracotta, Inc., except as may otherwise be noted in a separate copyright
03: * notice. All rights reserved.
04: */
05: package com.tc.net.groups;
06:
07: import com.tc.io.TCByteBufferInput;
08: import com.tc.io.TCByteBufferOutput;
09: import com.tc.net.protocol.tcm.ChannelID;
10:
11: import java.io.IOException;
12: import java.io.ObjectInput;
13: import java.io.ObjectOutput;
14:
15: public class ClientID implements NodeID {
16:
17: public static final ClientID NULL_ID = new ClientID(
18: ChannelID.NULL_ID);
19:
20: private ChannelID channelID;
21:
22: public ClientID() {
23: // To make serialization happy
24: }
25:
26: // satisfy serialization
27: public ClientID(ChannelID channelID) {
28: this .channelID = channelID;
29: }
30:
31: public boolean isNull() {
32: return channelID.isNull();
33: }
34:
35: public boolean equals(Object obj) {
36: if (obj instanceof ClientID) {
37: ClientID other = (ClientID) obj;
38: return this .channelID.equals(other.channelID);
39: }
40: return false;
41: }
42:
43: public int hashCode() {
44: return channelID.hashCode();
45: }
46:
47: public String toString() {
48: return "ClientID[" + channelID.toLong() + "]";
49: }
50:
51: public ChannelID getChannelID() {
52: return channelID;
53: }
54:
55: /**
56: * FIXME::Two difference serialization mechanisms are implemented since these classes are used with two different
57: * implementation of comms stack.
58: */
59:
60: public void readExternal(ObjectInput in) throws IOException {
61: this .channelID = new ChannelID(in.readLong());
62: }
63:
64: public void writeExternal(ObjectOutput out) throws IOException {
65: out.writeLong(this .channelID.toLong());
66: }
67:
68: /**
69: * FIXME::Two difference serialization mechanisms are implemented since these classes are used with two different
70: * implementation of comms stack.
71: */
72: public Object deserializeFrom(TCByteBufferInput serialInput)
73: throws IOException {
74: this .channelID = new ChannelID(serialInput.readLong());
75: return this ;
76: }
77:
78: public void serializeTo(TCByteBufferOutput serialOutput) {
79: serialOutput.writeLong(this.channelID.toLong());
80: }
81:
82: }
|