| Method from org.apache.catalina.cluster.session.DeltaSession Detail: |
public void access() {
this.lastAccessedTime = this.thisAccessedTime;
this.thisAccessedTime = System.currentTimeMillis();
evaluateIfValid();
accessCount++;
}
Update the accessed time information for this session. This method should
be called by the context when a request comes in for a particular
session, even if the application does not reference it. |
public void addSessionListener(SessionListener listener) {
synchronized (listeners) {
listeners.add(listener);
}
}
Add a session event listener to this component. |
public void endAccess() {
isNew = false;
accessCount--;
}
|
public void expire() {
expire(true);
}
Perform the internal processing required to invalidate this session,
without triggering an exception if the session has already expired. |
public void expire(boolean notify) {
expire(notify, true);
}
Perform the internal processing required to invalidate this session,
without triggering an exception if the session has already expired. |
public void expire(boolean notify,
boolean notifyCluster) {
// Mark this session as "being expired" if needed
if (expiring)
return;
String expiredId = getIdInternal();
synchronized (this) {
if (manager == null)
return;
expiring = true;
// Notify interested application event listeners
// FIXME - Assumes we call listeners in reverse order
Context context = (Context) manager.getContainer();
//fix for standalone manager without container
if (context != null) {
Object listeners[] = context.getApplicationLifecycleListeners();
if (notify && (listeners != null)) {
HttpSessionEvent event = new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
int j = (listeners.length - 1) - i;
if (!(listeners[j] instanceof HttpSessionListener))
continue;
HttpSessionListener listener = (HttpSessionListener) listeners[j];
try {
fireContainerEvent(context,
"beforeSessionDestroyed", listener);
listener.sessionDestroyed(event);
fireContainerEvent(context,
"afterSessionDestroyed", listener);
} catch (Throwable t) {
try {
fireContainerEvent(context,
"afterSessionDestroyed", listener);
} catch (Exception e) {
;
}
// FIXME - should we do anything besides log these?
log.error(sm
.getString("standardSession.sessionEvent"),
t);
}
}
}
}//end if
//end fix
accessCount = 0;
setValid(false);
// Remove this session from our manager's active sessions
if (manager != null)
manager.remove(this);
// Notify interested session event listeners
if (notify) {
fireSessionEvent(Session.SESSION_DESTROYED_EVENT, null);
}
// We have completed expire of this session
expiring = false;
// Unbind any objects associated with this session
String keys[] = keys();
for (int i = 0; i < keys.length; i++)
removeAttributeInternal(keys[i], notify, false);
if (notifyCluster) {
if (log.isDebugEnabled())
log.debug(smp.getString("deltaSession.notifying",
((DeltaManager) manager).getName(), new Boolean(
isPrimarySession()), expiredId));
((DeltaManager) manager).sessionExpired(expiredId);
}
}
}
|
public void fireSessionEvent(String type,
Object data) {
if (listeners.size() < 1)
return;
SessionEvent event = new SessionEvent(this, type, data);
SessionListener list[] = new SessionListener[0];
synchronized (listeners) {
list = (SessionListener[]) listeners.toArray(list);
}
for (int i = 0; i < list.length; i++) {
((SessionListener) list[i]).sessionEvent(event);
}
}
Notify all session event listeners that a particular event has occurred
for this Session. The default implementation performs this notification
synchronously using the calling thread. |
protected int getAccessCount() {
return accessCount;
}
|
public Object getAttribute(String name) {
if (!isValid())
throw new IllegalStateException(sm
.getString("standardSession.getAttribute.ise"));
return (attributes.get(name));
}
Return the object bound with the specified name in this session, or
null if no object is bound with that name. |
protected Object getAttributeInternal(String name) {
return (attributes.get(name));
}
Return the value of an attribute without a check for validity. |
public Enumeration getAttributeNames() {
if (!isValid())
throw new IllegalStateException(sm
.getString("standardSession.getAttributeNames.ise"));
return (new Enumerator(attributes.keySet(), true));
}
Return an Enumeration of String objects
containing the names of the objects bound to this session. |
public String getAuthType() {
return (this.authType);
}
Return the authentication type used to authenticate our cached Principal,
if any. |
public long getCreationTime() {
if (!expiring && !isValid)
throw new IllegalStateException(sm
.getString("standardSession.getCreationTime.ise"));
return (this.creationTime);
}
Return the time when this session was created, in milliseconds since
midnight, January 1, 1970 GMT. |
public DeltaRequest getDeltaRequest() {
if (deltaRequest == null)
resetDeltaRequest();
return deltaRequest;
}
|
public String getId() {
if ( !isValid() ) {
throw new IllegalStateException
(sm.getString("standardSession.getId.ise"));
}
return (this.id);
}
Return the session identifier for this session. |
public String getIdInternal() {
return (this.id);
}
Return the session identifier for this session. |
public String getInfo() {
return (info);
}
Return descriptive information about this Session implementation and the
corresponding version number, in the format
<description>/<version>. |
public long getLastAccessedTime() {
if (!isValid) {
throw new IllegalStateException(sm
.getString("standardSession.getLastAccessedTime"));
}
return (this.lastAccessedTime);
}
Return the last time the client sent a request associated with this
session, as the number of milliseconds since midnight, January 1, 1970
GMT. Actions that your application takes, such as getting or setting a
value associated with the session, do not affect the access time. |
protected long getLastTimeReplicated() {
return lastTimeReplicated;
}
|
public Manager getManager() {
return (this.manager);
}
Return the Manager within which this Session is valid. |
public int getMaxInactiveInterval() {
return (this.maxInactiveInterval);
}
Return the maximum time interval, in seconds, between client requests
before the servlet container will invalidate the session. A negative time
indicates that the session should never time out. |
public Object getNote(String name) {
return (notes.get(name));
}
Return the object bound with the specified name to the internal notes for
this session, or null if no such binding exists. |
public Iterator getNoteNames() {
return (notes.keySet().iterator());
}
Return an Iterator containing the String names of all notes bindings that
exist for this session. |
public Principal getPrincipal() {
return (this.principal);
}
Return the authenticated Principal that is associated with this Session.
This provides an Authenticator with a means to cache a
previously authenticated Principal, and avoid potentially expensive
Realm.authenticate() calls on every request. If there is
no current associated Principal, return null. |
public ServletContext getServletContext() {
if (manager == null)
return (null);
Context context = (Context) manager.getContainer();
if (context == null)
return (null);
else
return (context.getServletContext());
}
Return the ServletContext to which this session belongs. |
public HttpSession getSession() {
if (facade == null) {
if (System.getSecurityManager() != null) {
final DeltaSession fsession = this;
facade = (DeltaSessionFacade) AccessController
.doPrivileged(new PrivilegedAction() {
public Object run() {
return new DeltaSessionFacade(fsession);
}
});
} else {
facade = new DeltaSessionFacade(this);
}
}
return (facade);
}
Return the HttpSession for which this object is the
facade. |
public HttpSessionContext getSessionContext() {
if (sessionContext == null)
sessionContext = new StandardSessionContext();
return (sessionContext);
} Deprecated! As - of Version 2.1, this method is deprecated and has no
replacement. It will be removed in a future version of the
Java Servlet API.
Return the session context with which this session is associated. |
public Object getValue(String name) {
return (getAttribute(name));
} Deprecated! As - of Version 2.2, this method is replaced by
getAttribute()
Return the object bound with the specified name in this session, or
null if no object is bound with that name. |
public String[] getValueNames() {
if (!isValid())
throw new IllegalStateException(sm
.getString("standardSession.getValueNames.ise"));
return (keys());
} Deprecated! As - of Version 2.2, this method is replaced by
getAttributeNames()
Return the set of names of objects bound to this session. If there are no
such objects, a zero-length array is returned. |
public void invalidate() {
if (!isValid())
throw new IllegalStateException(sm
.getString("standardSession.invalidate.ise"));
// Cause this session to expire
expire();
}
Invalidates this session and unbinds any objects bound to it. |
public boolean isNew() {
if (!isValid())
throw new IllegalStateException(sm
.getString("standardSession.isNew.ise"));
return (this.isNew);
}
Return true if the client does not yet know about the
session, or if the client chooses not to join the session. For example,
if the server used only cookie-based sessions, and the client has
disabled the use of cookies, then a session would be new on each request. |
public boolean isPrimarySession() {
return isPrimarySession;
}
returns true if this session is the primary session, if that is the case,
the manager can expire it upon timeout. |
public boolean isValid() {
if (this.expiring) {
return true;
}
if (!this.isValid) {
return false;
}
if (accessCount > 0) {
return true;
}
if (maxInactiveInterval >= 0) {
long timeNow = System.currentTimeMillis();
int timeIdle = (int) ((timeNow - lastAccessedTime) / 1000L);
if (isPrimarySession()) {
if(timeIdle >= maxInactiveInterval) {
expire(true);
}
} else {
if (timeIdle >= (2 * maxInactiveInterval)) {
//if the session has been idle twice as long as allowed,
//the primary session has probably crashed, and no other
//requests are coming in. that is why we do this. otherwise
//we would have a memory leak
expire(true, false);
}
}
}
return (this.isValid);
}
Return the isValid flag for this session. |
protected String[] keys() {
return ((String[]) attributes.keySet().toArray(EMPTY_ARRAY));
}
Return the names of all currently defined session attributes as an array
of Strings. If there are no defined attributes, a zero-length array is
returned. |
public void putValue(String name,
Object value) {
setAttribute(name, value);
} Deprecated! As - of Version 2.2, this method is replaced by
setAttribute()
Bind an object to this session, using the specified name. If an object of
the same name is already bound to this session, the object is replaced.
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueBound() on the object. |
public void readObjectData(ObjectInputStream stream) throws IOException, ClassNotFoundException {
readObject(stream);
}
Read a serialized version of the contents of this session object from the
specified object input stream, without requiring that the StandardSession
itself have been serialized. |
public void recycle() {
// Reset the instance variables associated with this Session
attributes.clear();
setAuthType(null);
creationTime = 0L;
expiring = false;
id = null;
lastAccessedTime = 0L;
maxInactiveInterval = -1;
accessCount = 0;
notes.clear();
setPrincipal(null);
isNew = false;
isValid = false;
manager = null;
deltaRequest.clear();
}
Release all object references, and initialize instance variables, in
preparation for reuse of this object. |
public void removeAttribute(String name) {
removeAttribute(name, true);
}
Remove the object bound with the specified name from this session. If the
session does not have an object bound with this name, this method does
nothing.
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueUnbound() on the object. |
public void removeAttribute(String name,
boolean notify) {
removeAttribute(name, notify, true);
}
Remove the object bound with the specified name from this session. If the
session does not have an object bound with this name, this method does
nothing.
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueUnbound() on the object. |
public void removeAttribute(String name,
boolean notify,
boolean addDeltaRequest) {
// Validate our current state
if (!isValid())
throw new IllegalStateException(sm
.getString("standardSession.removeAttribute.ise"));
removeAttributeInternal(name, notify, addDeltaRequest);
}
|
protected void removeAttributeInternal(String name,
boolean notify,
boolean addDeltaRequest) {
// Remove this attribute from our collection
Object value = attributes.remove(name);
if (value == null)
return;
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.removeAttribute(name);
// Do we need to do valueUnbound() and attributeRemoved() notification?
if (!notify) {
return;
}
// Call the valueUnbound() method if necessary
HttpSessionBindingEvent event = null;
if (value instanceof HttpSessionBindingListener) {
event = new HttpSessionBindingEvent(
(HttpSession) getSession(), name, value);
try {
((HttpSessionBindingListener) value).valueUnbound(event);
} catch (Exception x) {
log.error(smp.getString("deltaSession.valueUnbound.ex"), x);
}
}
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
//fix for standalone manager without container
if (context != null) {
Object listeners[] = context.getApplicationEventListeners();
if (listeners == null)
return;
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionAttributeListener))
continue;
HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners[i];
try {
fireContainerEvent(context,
"beforeSessionAttributeRemoved", listener);
if (event == null) {
event = new HttpSessionBindingEvent
(getSession(), name, value);
}
listener.attributeRemoved(event);
fireContainerEvent(context, "afterSessionAttributeRemoved",
listener);
} catch (Throwable t) {
try {
fireContainerEvent(context,
"afterSessionAttributeRemoved", listener);
} catch (Exception e) {
;
}
// FIXME - should we do anything besides log these?
log
.error(
sm
.getString("standardSession.attributeEvent"),
t);
}
} //for
}//end if
//end fix
}
|
public void removeNote(String name) {
notes.remove(name);
}
Remove any object bound to the specified name in the internal notes for
this session. |
public void removeSessionListener(SessionListener listener) {
synchronized (listeners) {
listeners.remove(listener);
}
}
Remove a session event listener from this component. |
public void removeValue(String name) {
removeAttribute(name);
} Deprecated! As - of Version 2.2, this method is replaced by
removeAttribute()
Remove the object bound with the specified name from this session. If the
session does not have an object bound with this name, this method does
nothing.
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueUnbound() on the object. |
public void resetDeltaRequest() {
if (deltaRequest == null) {
deltaRequest = new DeltaRequest(getIdInternal(), false);
} else {
deltaRequest.reset();
deltaRequest.setSessionId(getIdInternal());
}
}
|
protected void setAccessCount(int accessCount) {
this.accessCount = accessCount;
}
|
public void setAttribute(String name,
Object value) {
setAttribute(name, value, true, true);
}
Bind an object to this session, using the specified name. If an object of
the same name is already bound to this session, the object is replaced.
After this method executes, and if the object implements
HttpSessionBindingListener, the container calls
valueBound() on the object. |
public void setAttribute(String name,
Object value,
boolean notify,
boolean addDeltaRequest) {
// Name cannot be null
if (name == null)
throw new IllegalArgumentException(sm
.getString("standardSession.setAttribute.namenull"));
// Null value is the same as removeAttribute()
if (value == null) {
removeAttribute(name);
return;
}
// Validate our current state
if (!isValid())
throw new IllegalStateException(sm
.getString("standardSession.setAttribute.ise"));
if (!(value instanceof java.io.Serializable)) {
throw new IllegalArgumentException("Attribute [" + name
+ "] is not serializable");
}
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setAttribute(name, value);
// Construct an event with the new value
HttpSessionBindingEvent event = null;
// Call the valueBound() method if necessary
if (value instanceof HttpSessionBindingListener && notify) {
// Don't call any notification if replacing with the same value
Object oldValue = attributes.get(name);
if (value != oldValue) {
event = new HttpSessionBindingEvent(getSession(), name, value);
try {
((HttpSessionBindingListener) value).valueBound(event);
} catch (Exception x) {
log.error(smp.getString("deltaSession.valueBound.ex"), x);
}
}
}
// Replace or add this attribute
Object unbound = attributes.put(name, value);
// Call the valueUnbound() method if necessary
if ((unbound != null) && (unbound != value) && notify
&& (unbound instanceof HttpSessionBindingListener)) {
try {
((HttpSessionBindingListener) unbound)
.valueUnbound(new HttpSessionBindingEvent(
(HttpSession) getSession(), name));
} catch (Exception x) {
log.error(smp.getString("deltaSession.valueBinding.ex"), x);
}
}
//dont notify any listeners
if (!notify)
return;
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
//fix for standalone manager without container
if (context != null) {
Object listeners[] = context.getApplicationEventListeners();
if (listeners == null)
return;
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionAttributeListener))
continue;
HttpSessionAttributeListener listener = (HttpSessionAttributeListener) listeners[i];
try {
if (unbound != null) {
fireContainerEvent(context,
"beforeSessionAttributeReplaced", listener);
if (event == null) {
event = new HttpSessionBindingEvent(getSession(),
name, unbound);
}
listener.attributeReplaced(event);
fireContainerEvent(context,
"afterSessionAttributeReplaced", listener);
} else {
fireContainerEvent(context,
"beforeSessionAttributeAdded", listener);
if (event == null) {
event = new HttpSessionBindingEvent(getSession(),
name, value);
}
listener.attributeAdded(event);
fireContainerEvent(context,
"afterSessionAttributeAdded", listener);
}
} catch (Throwable t) {
try {
if (unbound != null) {
fireContainerEvent(context,
"afterSessionAttributeReplaced", listener);
} else {
fireContainerEvent(context,
"afterSessionAttributeAdded", listener);
}
} catch (Exception e) {
;
}
// FIXME - should we do anything besides log these?
log
.error(
sm
.getString("standardSession.attributeEvent"),
t);
}
} //for
}//end if
//end fix
}
|
public void setAuthType(String authType) {
String oldAuthType = this.authType;
this.authType = authType;
support.firePropertyChange("authType", oldAuthType, this.authType);
}
Set the authentication type used to authenticate our cached Principal, if
any. |
public void setCreationTime(long time) {
this.creationTime = time;
this.lastAccessedTime = time;
this.thisAccessedTime = time;
}
Set the creation time for this session. This method is called by the
Manager when an existing Session instance is reused. |
public void setId(String id) {
setIdInternal(id);
tellNew();
}
Set the session identifier for this session. |
public void setIdInternal(String id) {
if ((this.id != null) && (manager != null))
manager.remove(this);
this.id = id;
if (manager != null)
manager.add(this);
if ( deltaRequest == null ) resetDeltaRequest();
else deltaRequest.setSessionId(id);
}
Set the session identifier for this session without notify listeners. |
protected void setLastTimeReplicated(long lastTimeReplicated) {
this.lastTimeReplicated = lastTimeReplicated;
}
|
public void setManager(Manager manager) {
this.manager = manager;
}
Set the Manager within which this Session is valid. |
public void setMaxInactiveInterval(int interval) {
setMaxInactiveInterval(interval, true);
}
Set the maximum time interval, in seconds, between client requests before
the servlet container will invalidate the session. A negative time
indicates that the session should never time out. |
public void setMaxInactiveInterval(int interval,
boolean addDeltaRequest) {
this.maxInactiveInterval = interval;
if (isValid && interval == 0) {
expire();
} else {
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setMaxInactiveInterval(interval);
}
}
|
public void setNew(boolean isNew) {
setNew(isNew, true);
}
Set the isNew flag for this session. |
public void setNew(boolean isNew,
boolean addDeltaRequest) {
this.isNew = isNew;
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setNew(isNew);
}
|
public void setNote(String name,
Object value) {
notes.put(name, value);
}
Bind an object to a specified name in the internal notes associated with
this session, replacing any existing binding for this name. |
public void setPrimarySession(boolean primarySession) {
this.isPrimarySession = primarySession;
}
Sets whether this is the primary session or not. |
public void setPrincipal(Principal principal) {
setPrincipal(principal, true);
}
Set the authenticated Principal that is associated with this Session.
This provides an Authenticator with a means to cache a
previously authenticated Principal, and avoid potentially expensive
Realm.authenticate() calls on every request. |
public void setPrincipal(Principal principal,
boolean addDeltaRequest) {
Principal oldPrincipal = this.principal;
this.principal = principal;
support.firePropertyChange("principal", oldPrincipal, this.principal);
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setPrincipal(principal);
}
|
public void setValid(boolean isValid) {
this.isValid = isValid;
}
Set the isValid flag for this session. |
public void tellNew() {
// Notify interested session event listeners
fireSessionEvent(Session.SESSION_CREATED_EVENT, null);
// Notify interested application event listeners
Context context = (Context) manager.getContainer();
//fix for standalone manager without container
if (context != null) {
Object listeners[] = context.getApplicationLifecycleListeners();
if (listeners != null) {
HttpSessionEvent event = new HttpSessionEvent(getSession());
for (int i = 0; i < listeners.length; i++) {
if (!(listeners[i] instanceof HttpSessionListener))
continue;
HttpSessionListener listener = (HttpSessionListener) listeners[i];
try {
fireContainerEvent(context, "beforeSessionCreated",
listener);
listener.sessionCreated(event);
fireContainerEvent(context, "afterSessionCreated",
listener);
} catch (Throwable t) {
try {
fireContainerEvent(context, "afterSessionCreated",
listener);
} catch (Exception e) {
;
}
// FIXME - should we do anything besides log these?
log.error(sm.getString("standardSession.sessionEvent"),
t);
}
}
}
}//end if
//end fix
}
Inform the listeners about the new session. |
public String toString() {
StringBuffer sb = new StringBuffer();
sb.append("DeltaSession[");
sb.append(id);
sb.append("]");
return (sb.toString());
}
Return a string representation of this object. |
public void writeObjectData(ObjectOutputStream stream) throws IOException {
writeObject(stream);
}
Write a serialized version of the contents of this session object to the
specified object output stream, without requiring that the
StandardSession itself have been serialized. |