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.util.Assert;
08:
09: import java.io.IOException;
10: import java.io.ObjectInput;
11: import java.io.ObjectOutput;
12:
13: public class GroupZapNodeMessage extends AbstractGroupMessage {
14:
15: public static final int ZAP_NODE_REQUEST = 0;
16:
17: private int zapNodeType;
18: private String reason;
19: private long[] weights;
20:
21: // To make serialization happy
22: public GroupZapNodeMessage() {
23: super (-1);
24: }
25:
26: public GroupZapNodeMessage(int type, int zapNodeType,
27: String reason, long[] weights) {
28: super (type);
29: this .reason = reason;
30: this .zapNodeType = zapNodeType;
31: this .weights = weights;
32: }
33:
34: protected void basicReadExternal(int msgType, ObjectInput in)
35: throws IOException {
36: Assert.assertEquals(ZAP_NODE_REQUEST, msgType);
37: zapNodeType = in.readInt();
38: reason = in.readUTF();
39: weights = new long[in.readInt()];
40: for (int i = 0; i < weights.length; i++) {
41: weights[i] = in.readLong();
42: }
43: }
44:
45: protected void basicWriteExternal(int msgType, ObjectOutput out)
46: throws IOException {
47: Assert.assertEquals(ZAP_NODE_REQUEST, msgType);
48: out.writeInt(zapNodeType);
49: out.writeUTF(reason);
50: out.writeInt(weights.length);
51: for (int i = 0; i < weights.length; i++) {
52: out.writeLong(weights[i]);
53: }
54: }
55:
56: public String toString() {
57: return "GroupZapNodeMessage [ " + zapNodeType + " , " + reason
58: + " , weights = " + toString(weights) + " ]";
59: }
60:
61: private String toString(long[] l) {
62: if (l == null)
63: return "null";
64: if (l.length == 0)
65: return "empty";
66: StringBuffer sb = new StringBuffer();
67: for (int i = 0; i < l.length; i++) {
68: sb.append(String.valueOf(l[i])).append(",");
69: }
70: sb.setLength(sb.length() - 1);
71: return sb.toString();
72: }
73:
74: public String getReason() {
75: return reason;
76: }
77:
78: public int getZapNodeType() {
79: return zapNodeType;
80: }
81:
82: public long[] getWeights() {
83: return weights;
84: }
85: }
|