Core implementation of a server session
| Method from org.apache.tomcat.core.ServerSession Detail: |
void accessed() {
// set last accessed to thisAccessTime as it will be left over
// from the previous access
lastAccessed = thisAccessTime;
thisAccessTime = System.currentTimeMillis();
}
Called by context when request comes in so that accesses and
inactivities can be dealt with accordingly. |
public ApplicationSession getApplicationSession(Context context,
boolean create) {
ApplicationSession appSession =
(ApplicationSession)appSessions.get(context);
if (appSession == null && create) {
// XXX
// sync to ensure valid?
appSession = new ApplicationSession(id, this, context);
appSessions.put(context, appSession);
}
// XXX
// make sure that we haven't gone over the end of our
// inactive interval -- if so, invalidate and create
// a new appSession
return appSession;
}
|
public long getCreationTime() {
return creationTime;
}
|
public String getId() {
return id;
}
|
public long getLastAccessedTime() {
return lastAccessed;
}
|
public int getMaxInactiveInterval() {
return inactiveInterval;
}
|
public Object getValue(String name) {
if (name == null) {
String msg = sm.getString("serverSession.value.iae");
throw new IllegalArgumentException(msg);
}
return values.get(name);
}
|
public Enumeration getValueNames() {
return values.keys();
}
|
synchronized void invalidate() {
Enumeration enum = appSessions.keys();
while (enum.hasMoreElements()) {
Object key = enum.nextElement();
ApplicationSession appSession =
(ApplicationSession)appSessions.get(key);
appSession.invalidate();
}
}
|
public void putValue(String name,
Object value) {
if (name == null) {
String msg = sm.getString("serverSession.value.iae");
throw new IllegalArgumentException(msg);
}
removeValue(name); // remove any existing binding
values.put(name, value);
}
|
synchronized void reap() {
Enumeration enum = appSessions.keys();
while (enum.hasMoreElements()) {
Object key = enum.nextElement();
ApplicationSession appSession =
(ApplicationSession)appSessions.get(key);
appSession.validate();
}
}
|
void removeApplicationSession(Context context) {
appSessions.remove(context);
}
|
public void removeValue(String name) {
values.remove(name);
}
|
public void setMaxInactiveInterval(int interval) {
inactiveInterval = interval;
}
|
void validate() {
// if we have an inactive interval, check to see if
// we've exceeded it
if (inactiveInterval != -1) {
int thisInterval =
(int)(System.currentTimeMillis() - lastAccessed) / 1000;
if (thisInterval > inactiveInterval) {
invalidate();
ServerSessionManager ssm =
ServerSessionManager.getManager();
ssm.removeSession(this);
}
}
}
|