001: package org.apache.catalina.cluster.session;
002:
003: import org.apache.catalina.cluster.SessionMessage;
004: import org.apache.catalina.cluster.Member;
005:
006: /**
007: * <p>Title: </p>
008: * <p>Description: </p>
009: * <p>Copyright: Copyright (c) 2004</p>
010: * <p>Company: </p>
011: * @author not attributable
012: * @version 1.0
013: */
014:
015: public class SessionMessageImpl implements SessionMessage,
016: java.io.Serializable {
017: public SessionMessageImpl() {
018: }
019:
020: /*
021:
022: * Private serializable variables to keep the messages state
023: */
024: private int mEvtType = -1;
025: private byte[] mSession;
026: private String mSessionID;
027: private Member mSrc;
028: private String mContextName;
029: private long serializationTimestamp;
030: private String uniqueId;
031:
032: /**
033: * Creates a session message. Depending on what event type you want this
034: * message to represent, you populate the different parameters in the constructor<BR>
035: * The following rules apply dependent on what event type argument you use:<BR>
036: * <B>EVT_SESSION_CREATED</B><BR>
037: * The parameters: session, sessionID must be set.<BR>
038: * <B>EVT_SESSION_EXPIRED</B><BR>
039: * The parameters: sessionID must be set.<BR>
040: * <B>EVT_SESSION_ACCESSED</B><BR>
041: * The parameters: sessionID must be set.<BR>
042: * <B>EVT_SESSION_EXPIRED_XXXX</B><BR>
043: * The parameters: sessionID must be set.<BR>
044: * <B>EVT_ATTRIBUTE_ADDED</B><BR>
045: * The parameters: sessionID, attrName, attrValue must be set.<BR>
046: * <B>EVT_ATTRIBUTE_REMOVED</B><BR>
047: * The parameters: sessionID, attrName must be set.<BR>
048: * <B>EVT_SET_USER_PRINCIPAL</B><BR>
049: * The parameters: sessionID, principal<BR>
050: * <B>EVT_REMOVE_SESSION_NOTE</B><BR>
051: * The parameters: sessionID, attrName<
052: * <B>EVT_SET_SESSION_NOTE</B><BR>
053: * The parameters: sessionID, attrName, attrValue
054: * @param eventtype - one of the 8 event type defined in this class
055: * @param session - the serialized byte array of the session itself
056: * @param sessionID - the id that identifies this session
057: * @param attrName - the name of the attribute added/removed
058: * @param attrValue - the value of the attribute added
059:
060: */
061: private SessionMessageImpl(String contextName, int eventtype,
062: byte[] session, String sessionID) {
063: mEvtType = eventtype;
064: mSession = session;
065: mSessionID = sessionID;
066: mContextName = contextName;
067: uniqueId = sessionID;
068: }
069:
070: public SessionMessageImpl(String contextName, int eventtype,
071: byte[] session, String sessionID, String uniqueID) {
072: this (contextName, eventtype, session, sessionID);
073: uniqueId = uniqueID;
074: }
075:
076: /**
077: * returns the event type
078: * @return one of the event types EVT_XXXX
079: */
080: public int getEventType() {
081: return mEvtType;
082: }
083:
084: /**
085: * @return the serialized data for the session
086: */
087: public byte[] getSession() {
088: return mSession;
089: }
090:
091: /**
092: * @return the session ID for the session
093: */
094: public String getSessionID() {
095: return mSessionID;
096: }
097:
098: /**
099: * @return the name of the attribute
100: */
101: // public String getAttributeName() { return mAttributeName; }
102: /**
103: * the value of the attribute
104: */
105: // public Object getAttributeValue() {return mAttributeValue; }
106: // public SerializablePrincipal getPrincipal() { return mPrincipal;}
107: public void setTimestamp(long time) {
108: serializationTimestamp = time;
109: }
110:
111: public long getTimestamp() {
112: return serializationTimestamp;
113: }
114:
115: /**
116: * @return the event type in a string representating, useful for debugging
117: */
118: public String getEventTypeString() {
119: switch (mEvtType) {
120: case EVT_SESSION_CREATED:
121: return "SESSION-MODIFIED";
122: case EVT_SESSION_EXPIRED:
123: return "SESSION-EXPIRED";
124: case EVT_SESSION_ACCESSED:
125: return "SESSION-ACCESSED";
126: case EVT_GET_ALL_SESSIONS:
127: return "SESSION-GET-ALL";
128: case EVT_SESSION_DELTA:
129: return "SESSION-DELTA";
130: case EVT_ALL_SESSION_DATA:
131: return "ALL-SESSION-DATA";
132: default:
133: return "UNKNOWN-EVENT-TYPE";
134: }
135: }
136:
137: /**
138: * Get the address that this message originated from. This would be set
139: * if the message was being relayed from a host other than the one
140: * that originally sent it.
141: */
142: public Member getAddress() {
143: return this .mSrc;
144: }
145:
146: /**
147: * Use this method to set the address that this message originated from.
148: * This can be used when re-sending the EVT_GET_ALL_SESSIONS message to
149: * another machine in the group.
150: */
151: public void setAddress(Member src) {
152: this .mSrc = src;
153: }
154:
155: public String getContextName() {
156: return mContextName;
157: }
158:
159: public String getUniqueId() {
160: return uniqueId;
161: }
162:
163: public void setUniqueId(String uniqueId) {
164: this.uniqueId = uniqueId;
165: }
166:
167: }
|