package org.jboss.web.tomcat.tc5.session;
import org.jboss.metadata.WebMetaData;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.security.Principal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
class SessionBasedClusteredSession
extends ClusteredSession implements Serializable
{
static final long serialVersionUID = 3200976125245487256L;
protected static final String info = "SessionBasedClusteredSession/1.0";
private transient boolean isSessionModifiedSinceLastSave;
private transient JBossCacheService proxy_;
public SessionBasedClusteredSession(AbstractJBossManager manager)
{
super(manager);
initAfterLoad(manager);
}
public void initAfterLoad(AbstractJBossManager manager)
{
if (this.proxy_ == null)
{
if (log.isDebugEnabled())
{
log.debug("initAfterLoad(): initialize the transient variables ...");
}
setManager(manager);
listeners = new ArrayList();
notes = new HashMap();
support = new PropertyChangeSupport(this);
expiring = false;
isSessionModifiedSinceLastSave = false;
isOutdated = false;
proxy_ = ((JBossCacheManager) manager).getCacheService();
if (proxy_ == null)
{
throw new RuntimeException("SessionBasedClusteredSession: Cache service is null.");
}
this.activate();
}
}
public void setCreationTime(long time)
{
super.setCreationTime(time);
sessionIsDirty();
}
public void setPrincipal(Principal principal)
{
Principal oldPrincipal = this.principal;
this.principal = principal;
support.firePropertyChange("principal", oldPrincipal, this.principal);
if ((oldPrincipal != null && !oldPrincipal.equals(principal)) ||
(oldPrincipal == null && principal != null))
sessionIsDirty();
}
public String toString()
{
StringBuffer sb = new StringBuffer();
sb.append("SessionBasedClusteredSession[");
sb.append(id);
sb.append("]");
return (sb.toString());
}
public synchronized void processSessionRepl()
{
if (!isSessionDirty())
{
if (log.isDebugEnabled())
{
log.debug("processSessionRepl(): session is not dirty. No need to replicate.");
}
return;
}
if (log.isDebugEnabled())
{
log.debug("processSessionRepl(): session is dirty. Will increment version from: " +
getVersion() + " and replicate.");
}
this.incrementVersion(); proxy_.putSession(id, this);
isSessionModifiedSinceLastSave = false;
}
public void removeMyself()
{
proxy_.removeSession(id);
}
public void removeMyselfLocal()
{
proxy_.removeSessionLocal(id);
}
public void access()
{
super.access();
if (invalidationPolicy == WebMetaData.SESSION_INVALIDATE_ACCESS)
{
this.sessionIsDirty();
}
}
protected Object getJBossInternalAttribute(String name)
{
Object result = attributes.get(name);
if (result != null)
{
if (invalidationPolicy == WebMetaData.SESSION_INVALIDATE_SET_AND_GET)
{
sessionIsDirty();
}
else if (invalidationPolicy == WebMetaData.SESSION_INVALIDATE_SET_AND_NON_PRIMITIVE_GET)
{
if (!(result instanceof String ||
result instanceof Integer ||
result instanceof Long ||
result instanceof Byte ||
result instanceof Short ||
result instanceof Float ||
result instanceof Double ||
result instanceof Character ||
result instanceof Boolean)
)
{
sessionIsDirty();
}
}
}
return result;
}
protected Object removeJBossInternalAttribute(String name)
{
sessionIsDirty();
return attributes.remove(name);
}
protected Map getJBossInternalAttributes()
{
sessionIsDirty();
return attributes;
}
protected Object setJBossInternalAttribute(String name, Object value)
{
sessionIsDirty();
return attributes.put(name, value);
}
protected void sessionIsDirty()
{
isSessionModifiedSinceLastSave = true;
}
public boolean isSessionDirty()
{
return isSessionModifiedSinceLastSave;
}
}