1 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 ; 12 import java.io.ObjectInput ; 13 import java.io.ObjectOutput ; 14 15 public class L2StateMessage extends AbstractGroupMessage { 16 17 public static final int START_ELECTION = 0; public static final int ELECTION_RESULT = 1; public static final int RESULT_AGREED = 2; public static final int RESULT_CONFLICT = 3; public static final int ABORT_ELECTION = 4; public static final int ELECTION_WON = 5; public static final int MOVE_TO_PASSIVE_STANDBY = 6; 25 private Enrollment enrollment; 26 27 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 in) throws IOException , ClassNotFoundException { 43 this.enrollment = (Enrollment) in.readObject(); 44 } 45 46 protected void basicWriteExternal(int type, ObjectOutput out) throws IOException { 47 out.writeObject(enrollment); 48 } 49 50 public Enrollment getEnrollment() { 51 return enrollment; 52 } 53 54 public String toString() { 55 return "ClusterStateMessage [ " + messageFrom() + ", type = " + getTypeString() + ", " + enrollment + "]"; 56 } 57 58 private String 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 ("Unknow Type ! : " + getType()); 76 } 77 } 78 79 } 80 | Popular Tags |