Methods Summary |
---|
public void | applyDiff(byte[] diff, int offset, int length)Applies a diff to an existing object.
ReplicationStream stream = ((ClusterManager)getManager()).getReplicationStream(diff,offset,length);
getDeltaRequest().readExternal(stream);
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
try {
ClassLoader[] loaders = getClassLoaders();
if ( loaders != null && loaders.length >0 ) Thread.currentThread().setContextClassLoader(loaders[0]);
getDeltaRequest().execute(this);
}finally {
Thread.currentThread().setContextClassLoader(contextLoader);
}
|
public void | expire(boolean notify)Perform the internal processing required to invalidate this session,
without triggering an exception if the session has already expired.
expire(notify, true);
|
public void | expire(boolean notify, boolean notifyCluster)
String expiredId = getIdInternal();
super.expire(notify);
if (notifyCluster) {
if (log.isDebugEnabled())
log.debug(sm.getString("deltaSession.notifying",
((ClusterManager)manager).getName(),
new Boolean(isPrimarySession()),
expiredId));
if ( manager instanceof DeltaManager ) {
( (DeltaManager) manager).sessionExpired(expiredId);
}
}
|
protected java.lang.Object | getAttributeInternal(java.lang.String name)Return the value of an attribute without a check for validity.
return (attributes.get(name));
|
public java.lang.ClassLoader[] | getClassLoaders()
if ( manager instanceof BackupManager ) return ((BackupManager)manager).getClassLoaders();
else if ( manager instanceof ClusterManagerBase ) return ((ClusterManagerBase)manager).getClassLoaders();
else if ( manager instanceof StandardManager ) {
StandardManager sm = (StandardManager)manager;
return ClusterManagerBase.getClassLoaders(sm.getContainer());
} else if ( manager instanceof ManagerBase ) {
ManagerBase mb = (ManagerBase)manager;
return ClusterManagerBase.getClassLoaders(mb.getContainer());
}//end if
return null;
|
public DeltaRequest | getDeltaRequest()
if (deltaRequest == null) resetDeltaRequest();
return deltaRequest;
|
public byte[] | getDiff()Returns a diff and sets the dirty map to false
return getDeltaRequest().serialize();
|
public long | getLastAccessedTimeInternal()Return the last client access time without invalidation check
return (this.lastAccessedTime);
|
protected long | getLastTimeReplicated()
return lastTimeReplicated;
|
public long | getVersion()
return version;
|
public boolean | isDiffable()If this returns true, the map will extract the diff using getDiff()
Otherwise it will serialize the entire object.
return true;
|
public boolean | isDirty()Has the object changed since last replication
and is not in a locked state
return getDeltaRequest().getSize()>0;
|
public boolean | isPrimarySession()returns true if this session is the primary session, if that is the case,
the manager can expire it upon timeout.
return isPrimarySession;
|
public boolean | isValid()Return the isValid flag for this session.
if (this.expiring) {
return true;
}
if (!this.isValid) {
return false;
}
if (ACTIVITY_CHECK && accessCount.get() > 0) {
return true;
}
if (maxInactiveInterval >= 0) {
long timeNow = System.currentTimeMillis();
int timeIdle = (int) ( (timeNow - thisAccessedTime) / 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);
|
public void | lock()Lock during serialization
diffLock.lock();
|
public synchronized void | readExternal(java.io.ObjectInput in)
readObjectData(in);
|
private void | readObject(java.io.ObjectInput stream)Read a serialized version of this session object from the specified
object input stream.
IMPLEMENTATION NOTE : The reference to the owning Manager is not
restored by this method, and must be set explicitly.
// Deserialize the scalar instance variables (except Manager)
authType = null; // Transient only
creationTime = ( (Long) stream.readObject()).longValue();
lastAccessedTime = ( (Long) stream.readObject()).longValue();
maxInactiveInterval = ( (Integer) stream.readObject()).intValue();
isNew = ( (Boolean) stream.readObject()).booleanValue();
isValid = ( (Boolean) stream.readObject()).booleanValue();
thisAccessedTime = ( (Long) stream.readObject()).longValue();
version = ( (Long) stream.readObject()).longValue();
boolean hasPrincipal = stream.readBoolean();
principal = null;
if (hasPrincipal) {
principal = SerializablePrincipal.readPrincipal(stream,getManager().getContainer().getRealm());
}
// setId((String) stream.readObject());
id = (String) stream.readObject();
if (log.isDebugEnabled()) log.debug(sm.getString("deltaSession.readSession", id));
// Deserialize the attribute count and attribute values
if (attributes == null) attributes = new Hashtable();
int n = ( (Integer) stream.readObject()).intValue();
boolean isValidSave = isValid;
isValid = true;
for (int i = 0; i < n; i++) {
String name = (String) stream.readObject();
Object value = (Object) stream.readObject();
if ( (value instanceof String) && (value.equals(NOT_SERIALIZED)))
continue;
attributes.put(name, value);
}
isValid = isValidSave;
if (listeners == null) {
listeners = new ArrayList();
}
if (notes == null) {
notes = new Hashtable();
}
activate();
|
public void | readObjectData(java.io.ObjectInput 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.
readObject(stream);
|
public void | recycle()Release all object references, and initialize instance variables, in
preparation for reuse of this object.
super.recycle();
deltaRequest.clear();
|
public void | removeAttribute(java.lang.String name, boolean notify)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.
removeAttribute(name, notify, true);
|
public void | removeAttribute(java.lang.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(java.lang.String name, boolean notify, boolean addDeltaRequest)
try {
lock();
// Remove this attribute from our collection
Object value = attributes.get(name);
if (value == null) return;
super.removeAttributeInternal(name,notify);
if (addDeltaRequest && (deltaRequest != null)) deltaRequest.removeAttribute(name);
}finally {
unlock();
}
|
public void | resetDeltaRequest()
if (deltaRequest == null) {
deltaRequest = new DeltaRequest(getIdInternal(), false);
} else {
deltaRequest.reset();
deltaRequest.setSessionId(getIdInternal());
}
|
public void | resetDiff()Resets the current diff state and resets the dirty flag
resetDeltaRequest();
|
protected void | setAccessCount(int count)
if ( accessCount == null && ACTIVITY_CHECK ) accessCount = new AtomicInteger();
if ( accessCount != null ) super.accessCount.set(count);
|
public void | setAttribute(java.lang.String name, java.lang.Object value)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.
setAttribute(name, value, true, true);
|
public void | setAttribute(java.lang.String name, java.lang.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;
}
try {
lock();
super.setAttribute(name,value, notify);
if (addDeltaRequest && (deltaRequest != null)) deltaRequest.setAttribute(name, value);
} finally {
unlock();
}
|
public void | setId(java.lang.String id)Set the session identifier for this session.
super.setId(id);
resetDeltaRequest();
|
public void | setIdInternal(java.lang.String id)Set the session identifier for this session without notify listeners.
this.id = id;
resetDeltaRequest();
|
protected void | setLastTimeReplicated(long lastTimeReplicated)
this.lastTimeReplicated = lastTimeReplicated;
|
public void | setMaxInactiveInterval(int interval, boolean addDeltaRequest)
super.maxInactiveInterval = interval;
if (isValid && interval == 0) {
expire();
} else {
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setMaxInactiveInterval(interval);
}
|
public void | setNew(boolean isNew)Set the isNew flag for this session.
setNew(isNew, true);
|
public void | setNew(boolean isNew, boolean addDeltaRequest)
super.setNew(isNew);
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setNew(isNew);
|
public void | setOwner(java.lang.Object owner)
if ( owner instanceof ClusterManager && getManager()==null) {
ClusterManager cm = (ClusterManager)owner;
this.setManager(cm);
this.setValid(true);
this.setPrimarySession(false);
this.access();
this.resetDeltaRequest();
this.endAccess();
}
|
public void | setPrimarySession(boolean primarySession)Sets whether this is the primary session or not.
this.isPrimarySession = primarySession;
|
public void | setPrincipal(java.security.Principal principal)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.
setPrincipal(principal, true);
|
public void | setPrincipal(java.security.Principal principal, boolean addDeltaRequest)
try {
lock();
super.setPrincipal(principal);
if (addDeltaRequest && (deltaRequest != null))
deltaRequest.setPrincipal(principal);
} finally {
unlock();
}
|
public void | setVersion(long version)
this.version = version;
|
public java.lang.String | toString()Return a string representation of this object.
StringBuffer sb = new StringBuffer();
sb.append("DeltaSession[");
sb.append(id);
sb.append("]");
return (sb.toString());
|
public void | unlock()Unlock after serialization
diffLock.unlock();
|
public synchronized void | writeExternal(java.io.ObjectOutput out)
writeObject(out);
|
private void | writeObject(java.io.ObjectOutput stream)Write a serialized version of this session object to the specified object
output stream.
IMPLEMENTATION NOTE : The owning Manager will not be stored in the
serialized representation of this Session. After calling
readObject() , you must set the associated Manager
explicitly.
IMPLEMENTATION NOTE : Any attribute that is not Serializable will
be unbound from the session, with appropriate actions if it implements
HttpSessionBindingListener. If you do not want any such attributes, be
sure the distributable property of the associated Manager
is set to true .
// Write the scalar instance variables (except Manager)
stream.writeObject(new Long(creationTime));
stream.writeObject(new Long(lastAccessedTime));
stream.writeObject(new Integer(maxInactiveInterval));
stream.writeObject(new Boolean(isNew));
stream.writeObject(new Boolean(isValid));
stream.writeObject(new Long(thisAccessedTime));
stream.writeObject(new Long(version));
stream.writeBoolean(getPrincipal() != null);
if (getPrincipal() != null) {
SerializablePrincipal.writePrincipal((GenericPrincipal) principal,stream);
}
stream.writeObject(id);
if (log.isDebugEnabled()) log.debug(sm.getString("deltaSession.writeSession", id));
// Accumulate the names of serializable and non-serializable attributes
String keys[] = keys();
ArrayList saveNames = new ArrayList();
ArrayList saveValues = new ArrayList();
for (int i = 0; i < keys.length; i++) {
Object value = null;
value = attributes.get(keys[i]);
if (value == null)
continue;
else if (value instanceof Serializable) {
saveNames.add(keys[i]);
saveValues.add(value);
}
}
// Serialize the attribute count and the Serializable attributes
int n = saveNames.size();
stream.writeObject(new Integer(n));
for (int i = 0; i < n; i++) {
stream.writeObject( (String) saveNames.get(i));
try {
stream.writeObject(saveValues.get(i));
} catch (NotSerializableException e) {
log.error(sm.getString("standardSession.notSerializable",saveNames.get(i), id), e);
stream.writeObject(NOT_SERIALIZED);
log.error(" storing attribute '" + saveNames.get(i)+ "' with value NOT_SERIALIZED");
}
}
|
public void | writeObjectData(java.io.ObjectOutput 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.
writeObject(stream);
|