KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > catalina > cluster > session > SessionMessageImpl


1 package org.apache.catalina.cluster.session;
2
3
4 import org.apache.catalina.cluster.Member;
5 /**
6  * <p>Title: </p>
7  * <p>Description: </p>
8  * <p>Copyright: Copyright (c) 2004</p>
9  * <p>Company: </p>
10  * @author not attributable
11  * @version 1.0
12  */

13
14 public class SessionMessageImpl implements SessionMessage, java.io.Serializable JavaDoc {
15     public SessionMessageImpl() {
16     }
17     
18     
19     /*
20
21      * Private serializable variables to keep the messages state
22      */

23     private int mEvtType = -1;
24     private byte[] mSession;
25     private String JavaDoc mSessionID;
26     private Member mSrc;
27     private String JavaDoc mContextName;
28     private long serializationTimestamp;
29     private String JavaDoc uniqueId;
30
31
32     /**
33      * Creates a session message. Depending on what event type you want this
34      * message to represent, you populate the different parameters in the constructor<BR>
35      * The following rules apply dependent on what event type argument you use:<BR>
36      * <B>EVT_SESSION_CREATED</B><BR>
37      * The parameters: session, sessionID must be set.<BR>
38      * <B>EVT_SESSION_EXPIRED</B><BR>
39      * The parameters: sessionID must be set.<BR>
40      * <B>EVT_SESSION_ACCESSED</B><BR>
41      * The parameters: sessionID must be set.<BR>
42      * <B>EVT_SESSION_EXPIRED_XXXX</B><BR>
43      * The parameters: sessionID must be set.<BR>
44      * <B>EVT_ATTRIBUTE_ADDED</B><BR>
45      * The parameters: sessionID, attrName, attrValue must be set.<BR>
46      * <B>EVT_ATTRIBUTE_REMOVED</B><BR>
47      * The parameters: sessionID, attrName must be set.<BR>
48      * <B>EVT_SET_USER_PRINCIPAL</B><BR>
49      * The parameters: sessionID, principal<BR>
50      * <B>EVT_REMOVE_SESSION_NOTE</B><BR>
51      * The parameters: sessionID, attrName<
52      * <B>EVT_SET_SESSION_NOTE</B><BR>
53      * The parameters: sessionID, attrName, attrValue
54      * @param eventtype - one of the 8 event type defined in this class
55      * @param session - the serialized byte array of the session itself
56      * @param sessionID - the id that identifies this session
57      * @param attrName - the name of the attribute added/removed
58      * @param attrValue - the value of the attribute added
59
60      */

61     private SessionMessageImpl( String JavaDoc contextName,
62                            int eventtype,
63                            byte[] session,
64                            String JavaDoc sessionID)
65     {
66         mEvtType = eventtype;
67         mSession = session;
68         mSessionID = sessionID;
69         mContextName = contextName;
70         uniqueId = sessionID;
71     }
72
73     public SessionMessageImpl( String JavaDoc contextName,
74                            int eventtype,
75                            byte[] session,
76                            String JavaDoc sessionID,
77                            String JavaDoc uniqueID)
78     {
79         this(contextName,eventtype,session,sessionID);
80         uniqueId = uniqueID;
81     }
82
83     /**
84      * returns the event type
85      * @return one of the event types EVT_XXXX
86      */

87     public int getEventType() { return mEvtType; }
88     /**
89      * @return the serialized data for the session
90      */

91     public byte[] getSession() { return mSession;}
92     /**
93      * @return the session ID for the session
94      */

95     public String JavaDoc getSessionID(){ return mSessionID; }
96     /**
97      * @return the name of the attribute
98      */

99 // public String getAttributeName() { return mAttributeName; }
100
/**
101      * the value of the attribute
102      */

103 // public Object getAttributeValue() {return mAttributeValue; }
104

105 // public SerializablePrincipal getPrincipal() { return mPrincipal;}
106

107     public void setTimestamp(long time) {serializationTimestamp=time;}
108     public long getTimestamp() { return serializationTimestamp;}
109     /**
110      * @return the event type in a string representating, useful for debugging
111      */

112     public String JavaDoc getEventTypeString()
113     {
114         switch (mEvtType)
115         {
116             case EVT_SESSION_CREATED : return "SESSION-MODIFIED";
117             case EVT_SESSION_EXPIRED : return "SESSION-EXPIRED";
118             case EVT_SESSION_ACCESSED : return "SESSION-ACCESSED";
119             case EVT_GET_ALL_SESSIONS : return "SESSION-GET-ALL";
120             case EVT_SESSION_DELTA : return "SESSION-DELTA";
121             case EVT_ALL_SESSION_DATA : return "ALL-SESSION-DATA";
122             default : return "UNKNOWN-EVENT-TYPE";
123         }
124     }
125
126     /**
127      * Get the address that this message originated from. This would be set
128      * if the message was being relayed from a host other than the one
129      * that originally sent it.
130      */

131     public Member getAddress()
132     {
133         return this.mSrc;
134     }
135
136     /**
137      * Use this method to set the address that this message originated from.
138      * This can be used when re-sending the EVT_GET_ALL_SESSIONS message to
139      * another machine in the group.
140      */

141     public void setAddress(Member src)
142     {
143         this.mSrc = src;
144     }
145
146     public String JavaDoc getContextName() {
147        return mContextName;
148     }
149     public String JavaDoc getUniqueId() {
150         return uniqueId;
151     }
152     public void setUniqueId(String JavaDoc uniqueId) {
153         this.uniqueId = uniqueId;
154     }
155
156
157 }
158
Popular Tags