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.l2.msg;
06:
07: import com.tc.async.api.EventContext;
08: import com.tc.l2.state.Enrollment;
09: import com.tc.net.groups.AbstractGroupMessage;
10: import com.tc.net.groups.MessageID;
11:
12: import java.io.IOException;
13: import java.io.ObjectInput;
14: import java.io.ObjectOutput;
15:
16: public class L2StateMessage extends AbstractGroupMessage implements
17: EventContext {
18:
19: public static final int START_ELECTION = 0; // Sent during the start of an election by the initiator
20: public static final int ELECTION_RESULT = 1; // Sen at the end of an election by the initiator
21: public static final int RESULT_AGREED = 2; // Sent in response to ELECTION_WON if no conflict
22: public static final int RESULT_CONFLICT = 3; // Sent in response to ELECTION_WON on conflict
23: public static final int ABORT_ELECTION = 4; // Sent in response to START_ELECTION by already elected ACTIVE
24: public static final int ELECTION_WON = 5; // Sent by the node that wins an election
25: public static final int MOVE_TO_PASSIVE_STANDBY = 6; // Sent by active to notify passive can become PASSIVE_STANDBY
26:
27: private Enrollment enrollment;
28:
29: // To make serialization happy
30: public L2StateMessage() {
31: super (-1);
32: }
33:
34: public L2StateMessage(int type, Enrollment e) {
35: super (type);
36: this .enrollment = e;
37: }
38:
39: public L2StateMessage(MessageID requestID, int type, Enrollment e) {
40: super (type, requestID);
41: this .enrollment = e;
42: }
43:
44: protected void basicReadExternal(int type, ObjectInput in)
45: throws IOException, ClassNotFoundException {
46: this .enrollment = (Enrollment) in.readObject();
47: }
48:
49: protected void basicWriteExternal(int type, ObjectOutput out)
50: throws IOException {
51: out.writeObject(enrollment);
52: }
53:
54: public Enrollment getEnrollment() {
55: return enrollment;
56: }
57:
58: public String toString() {
59: return "L2StateMessage [ " + messageFrom() + ", type = "
60: + getTypeString() + ", " + enrollment + "]";
61: }
62:
63: private String getTypeString() {
64: switch (getType()) {
65: case START_ELECTION:
66: return "START_ELECTION";
67: case ELECTION_RESULT:
68: return "ELECTION_RESULT";
69: case RESULT_AGREED:
70: return "RESULT_AGREED";
71: case RESULT_CONFLICT:
72: return "RESULT_CONFLICT";
73: case ABORT_ELECTION:
74: return "ABORT_ELECTION";
75: case ELECTION_WON:
76: return "ELECTION_WON";
77: case MOVE_TO_PASSIVE_STANDBY:
78: return "MOVE_TO_PASSIVE_STANDBY";
79: default:
80: throw new AssertionError("Unknow Type ! : " + getType());
81: }
82: }
83:
84: }
|