KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tc > l2 > msg > L2StateMessage


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

5 package com.tc.l2.msg;
6
7 import com.tc.l2.state.Enrollment;
8 import com.tc.net.groups.AbstractGroupMessage;
9 import com.tc.net.groups.MessageID;
10
11 import java.io.IOException JavaDoc;
12 import java.io.ObjectInput JavaDoc;
13 import java.io.ObjectOutput JavaDoc;
14
15 public class L2StateMessage extends AbstractGroupMessage {
16
17   public static final int START_ELECTION = 0; // Sent during the start of an election by the initiator
18
public static final int ELECTION_RESULT = 1; // Sen at the end of an election by the initiator
19
public static final int RESULT_AGREED = 2; // Sent in response to ELECTION_WON if no conflict
20
public static final int RESULT_CONFLICT = 3; // Sent in response to ELECTION_WON on conflict
21
public static final int ABORT_ELECTION = 4; // Sent in response to START_ELECTION by already elected ACTIVE
22
public static final int ELECTION_WON = 5; // Sent by the node that wins an election
23
public static final int MOVE_TO_PASSIVE_STANDBY = 6; // Sent by active to notify passive can become PASSIVE_STANDBY
24

25   private Enrollment enrollment;
26
27   // To make serialization happy
28
public L2StateMessage() {
29     super(-1);
30   }
31
32   public L2StateMessage(int type, Enrollment e) {
33     super(type);
34     this.enrollment = e;
35   }
36
37   public L2StateMessage(MessageID requestID, int type, Enrollment e) {
38     super(type, requestID);
39     this.enrollment = e;
40   }
41
42   protected void basicReadExternal(int type, ObjectInput JavaDoc in) throws IOException JavaDoc, ClassNotFoundException JavaDoc {
43     this.enrollment = (Enrollment) in.readObject();
44   }
45
46   protected void basicWriteExternal(int type, ObjectOutput JavaDoc out) throws IOException JavaDoc {
47     out.writeObject(enrollment);
48   }
49
50   public Enrollment getEnrollment() {
51     return enrollment;
52   }
53
54   public String JavaDoc toString() {
55     return "ClusterStateMessage [ " + messageFrom() + ", type = " + getTypeString() + ", " + enrollment + "]";
56   }
57
58   private String JavaDoc getTypeString() {
59     switch (getType()) {
60       case START_ELECTION:
61         return "START_ELECTION";
62       case ELECTION_RESULT:
63         return "ELECTION_RESULT";
64       case RESULT_AGREED:
65         return "RESULT_AGREED";
66       case RESULT_CONFLICT:
67         return "RESULT_CONFLICT";
68       case ABORT_ELECTION:
69         return "ABORT_ELECTION";
70       case ELECTION_WON:
71         return "ELECTION_WON";
72       case MOVE_TO_PASSIVE_STANDBY:
73         return "MOVE_TO_PASSIVE_STANDBY";
74       default:
75         throw new AssertionError JavaDoc("Unknow Type ! : " + getType());
76     }
77   }
78
79 }
80
Popular Tags