001: /*
002: * Copyright 2005 jWic group (http://www.jwic.de)
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: *
016: * de.jwic.base.SessionStore
017: * Created on 08.11.2005
018: * $Id: SessionContainer.java,v 1.2 2006/03/06 16:40:10 lordsam Exp $
019: */
020: package de.jwic.base;
021:
022: /**
023: * Contains the SessionContext assigned to a specified session. It manages the
024: * state of the application.
025: *
026: * @author Florian Lippisch
027: * @version $Revision: 1.2 $
028: */
029: public class SessionContainer {
030:
031: public final static int STATE_NORMAL = 0;
032: public final static int STATE_DESTROYED = 1;
033: public final static int STATE_STORED = 2;
034:
035: private String clientId = null;
036: private String id = null;
037: private String applicationId = null;
038: private SessionContext sessionContext = null;
039: private int state = STATE_NORMAL;
040: private long lastAccess = 0;
041:
042: /**
043: * Constructs a new SessionStore with the given ID.
044: * @param id
045: */
046: public SessionContainer(String id, String clientId) {
047: this .id = id;
048: this .clientId = clientId;
049: lastAccess = System.currentTimeMillis();
050: }
051:
052: /**
053: * Update the access timestamp.
054: */
055: public void access() {
056: lastAccess = System.currentTimeMillis();
057: }
058:
059: /**
060: * @return Returns the id.
061: */
062: public String getId() {
063: return id;
064: }
065:
066: /**
067: * @param id The id to set.
068: */
069: public void setId(String id) {
070: this .id = id;
071: }
072:
073: /**
074: * @return Returns the sessionContext.
075: */
076: public SessionContext getSessionContext() {
077: return sessionContext;
078: }
079:
080: /**
081: * @param sessionContext The sessionContext to set.
082: */
083: public void setSessionContext(SessionContext sessionContext) {
084: this .sessionContext = sessionContext;
085: }
086:
087: /**
088: * @return Returns the state.
089: */
090: public int getState() {
091: return state;
092: }
093:
094: /**
095: * @param state The state to set.
096: */
097: public void setState(int state) {
098: this .state = state;
099: }
100:
101: /**
102: * @return Returns the lastAccess.
103: */
104: public long getLastAccess() {
105: return lastAccess;
106: }
107:
108: /**
109: * @return Returns the applicationId.
110: */
111: public String getApplicationId() {
112: return applicationId;
113: }
114:
115: /**
116: * @param applicationId The applicationId to set.
117: */
118: public void setApplicationId(String applicationId) {
119: this .applicationId = applicationId;
120: }
121:
122: /**
123: * @return Returns the clientId.
124: */
125: public String getClientId() {
126: return clientId;
127: }
128:
129: /**
130: * @param clientId The clientId to set.
131: */
132: public void setClientId(String clientId) {
133: this .clientId = clientId;
134: }
135:
136: /* (non-Javadoc)
137: * @see java.lang.Object#toString()
138: */
139: public String toString() {
140: return "SessionContainer ID '" + id + "', AppID: '"
141: + applicationId + "', Client: " + clientId;
142: }
143:
144: /**
145: * Returns the age in minutes and seconds.
146: * @param container
147: */
148: public String getAge() {
149:
150: long age = System.currentTimeMillis() - getLastAccess();
151:
152: long seconds = (age / 1000) % 60;
153: long minutes = (age / 1000 / 60);
154:
155: return minutes + "m " + seconds + "s";
156: }
157:
158: }
|