001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.catalina.ha.session;
018:
019: import org.apache.catalina.ha.ClusterMessageBase;
020:
021: /**
022: * Session cluster message
023: *
024: * @author Filip Hanik
025: * @author Peter Rossbach
026: *
027: * @version $Revision: 531471 $ $Date: 2007-04-23 16:11:44 +0200 (lun., 23 avr. 2007) $
028: */
029: public class SessionMessageImpl extends ClusterMessageBase implements
030: SessionMessage, java.io.Serializable {
031:
032: public SessionMessageImpl() {
033: }
034:
035: /*
036:
037: * Private serializable variables to keep the messages state
038: */
039: private int mEvtType = -1;
040: private byte[] mSession;
041: private String mSessionID;
042:
043: private String mContextName;
044: private long serializationTimestamp;
045: private boolean timestampSet = false;
046: private String uniqueId;
047:
048: private SessionMessageImpl(String contextName, int eventtype,
049: byte[] session, String sessionID) {
050: mEvtType = eventtype;
051: mSession = session;
052: mSessionID = sessionID;
053: mContextName = contextName;
054: uniqueId = sessionID;
055: }
056:
057: /**
058: * Creates a session message. Depending on what event type you want this
059: * message to represent, you populate the different parameters in the constructor<BR>
060: * The following rules apply dependent on what event type argument you use:<BR>
061: * <B>EVT_SESSION_CREATED</B><BR>
062: * The parameters: session, sessionID must be set.<BR>
063: * <B>EVT_SESSION_EXPIRED</B><BR>
064: * The parameters: sessionID must be set.<BR>
065: * <B>EVT_SESSION_ACCESSED</B><BR>
066: * The parameters: sessionID must be set.<BR>
067: * <B>EVT_SESSION_EXPIRED_XXXX</B><BR>
068: * The parameters: sessionID must be set.<BR>
069: * <B>EVT_SESSION_DELTA</B><BR>
070: * Send attribute delta (add,update,remove attribute or principal, ...).<BR>
071: * <B>EVT_ALL_SESSION_DATA</B><BR>
072: * Send complete serializes session list<BR>
073: * <B>EVT_ALL_SESSION_TRANSFERCOMPLETE</B><BR>
074: * send that all session state information are transfered
075: * after GET_ALL_SESSION received from this sender.<BR>
076: * @param contextName - the name of the context (application
077: * @param eventtype - one of the 8 event type defined in this class
078: * @param session - the serialized byte array of the session itself
079: * @param sessionID - the id that identifies this session
080: * @param uniqueID - the id that identifies this message
081: */
082: public SessionMessageImpl(String contextName, int eventtype,
083: byte[] session, String sessionID, String uniqueID) {
084: this (contextName, eventtype, session, sessionID);
085: uniqueId = uniqueID;
086: }
087:
088: /**
089: * returns the event type
090: * @return one of the event types EVT_XXXX
091: */
092: public int getEventType() {
093: return mEvtType;
094: }
095:
096: /**
097: * @return the serialized data for the session
098: */
099: public byte[] getSession() {
100: return mSession;
101: }
102:
103: /**
104: * @return the session ID for the session
105: */
106: public String getSessionID() {
107: return mSessionID;
108: }
109:
110: /**
111: * set message send time but only the first setting works (one shot)
112: */
113: public void setTimestamp(long time) {
114: synchronized (this ) {
115: if (!timestampSet) {
116: serializationTimestamp = time;
117: timestampSet = true;
118: }
119: }
120: }
121:
122: public long getTimestamp() {
123: return serializationTimestamp;
124: }
125:
126: /**
127: * clear text event type name (for logging purpose only)
128: * @return the event type in a string representating, useful for debugging
129: */
130: public String getEventTypeString() {
131: switch (mEvtType) {
132: case EVT_SESSION_CREATED:
133: return "SESSION-MODIFIED";
134: case EVT_SESSION_EXPIRED:
135: return "SESSION-EXPIRED";
136: case EVT_SESSION_ACCESSED:
137: return "SESSION-ACCESSED";
138: case EVT_GET_ALL_SESSIONS:
139: return "SESSION-GET-ALL";
140: case EVT_SESSION_DELTA:
141: return "SESSION-DELTA";
142: case EVT_ALL_SESSION_DATA:
143: return "ALL-SESSION-DATA";
144: case EVT_ALL_SESSION_TRANSFERCOMPLETE:
145: return "SESSION-STATE-TRANSFERED";
146: default:
147: return "UNKNOWN-EVENT-TYPE";
148: }
149: }
150:
151: public String getContextName() {
152: return mContextName;
153: }
154:
155: public String getUniqueId() {
156: return uniqueId;
157: }
158:
159: public void setUniqueId(String uniqueId) {
160: this .uniqueId = uniqueId;
161: }
162:
163: public String toString() {
164: return getEventTypeString() + "#" + getContextName() + "#"
165: + getSessionID();
166: }
167: }
|