Top Description Fields Constructors Methods
org.eclipse.jetty.session

public abstract Class AbstractSessionDataStore

extends ContainerLifeCycle
implements SessionDataStore
Class Inheritance
All Implemented Interfaces
org.eclipse.jetty.session.SessionDataStore, org.eclipse.jetty.session.SessionDataMap, org.eclipse.jetty.util.component.LifeCycle
Known Direct Subclasses
org.eclipse.jetty.session.NullSessionDataStore, org.eclipse.jetty.session.ObjectStreamSessionDataStore
Annotations
@ManagedObject
Imports
java.io.IOException, .InputStream, .ObjectInputStream, .ObjectOutputStream, .OutputStream, java.util.HashSet, .Set, java.util.concurrent.TimeUnit, org.eclipse.jetty.util.ClassLoadingObjectInputStream, .FuturePromise, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.eclipse.jetty.util.component.ContainerLifeCycle, org.slf4j.Logger, .LoggerFactory

AbstractSessionDataStore

Field Summary

Modifier and TypeField and Description
protected SessionContext
protected int
protected long
protected long
protected int
public static final int
public static final int
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
protected void
public void
cleanOrphans(long
the time before which the sessions must have expired.
timeLimit
)

Remove all sessions for any context that expired at or before the given time.

public abstract Set<String>

Returns:

the reconciled set of session ids that have been checked in the store
doCheckExpired
(Set<String>
the ids of sessions the SessionCache thinks has expired
candidates
,
long
the time at which to check for expiry
time
)

Implemented by subclasses to resolve which sessions in this context that are being managed by this node that should be expired.

public abstract void
doCleanOrphans(long
the upper limit of the expiry time to check in msec
time
)

Implemented by subclasses to delete sessions for other contexts that expired at or before the timeLimit.

public abstract boolean

Returns:

true if the session exists in the persistent store, false otherwise
doExists
(String
the session id to check
id
)

Check if a session for the given id exists.

public abstract Set<String>

Returns:

the empty set if there are no sessions expired as at the time, or otherwise a set of session ids.
doGetExpired
(long
the upper limit of expiry times to check. Sessions expired at or before this timestamp will match.
before
)

Implemented by subclasses to find sessions for this context in the store that expired at or before the time limit and thus not being actively managed by any node.

public abstract SessionData

Returns:

the re-inflated session
doLoad
(String
the id of the session to load
id
)

Load the session from persistent store.

protected void
doStart()

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

public abstract void
doStore(String
identity of session to store
id
,
SessionData
info of the session
data
,
long
time of previous save or 0 if never saved
lastSaveTime
)

Store the session data persistently.

public boolean
exists(String
Identity of session whose existence should be checked
id
)

Implements org.eclipse.jetty.session.SessionDataStore.exists.

Test if data exists for a given session id.

public Set<String>
getExpired(Set<String>
if provided, these are keys of sessions that the SessionDataStore thinks has expired and should be verified by the SessionDataStore
candidates
)

Implements org.eclipse.jetty.session.SessionDataStore.getExpired.

Called periodically, this method should search the data store for sessions that have been expired for a 'reasonable' amount of time.

public int
public int
getSavePeriodSec()

Returns: the savePeriodSec

public void
initialize(SessionContext
context associated
context
)

Implements org.eclipse.jetty.session.SessionDataMap.initialize.

Initialize this data map for the given context.

public SessionData
load(String
identity of session to load
id
)

Implements org.eclipse.jetty.session.SessionDataMap.load.

Read in session data.

public SessionData
newSessionData(String
the id
id
,
long
the timestamp when created
created
,
long
the timestamp when accessed
accessed
,
long
the timestamp when last accessed
lastAccessed
,
long
the max inactive time in milliseconds
maxInactiveMs
)

Implements org.eclipse.jetty.session.SessionDataStore.newSessionData.

Create a new SessionData

public void
public void
setSavePeriodSec(int
the savePeriodSec to set
savePeriodSec
)

The minimum time in seconds between save operations.

public void
store(String
identity of session to store
id
,
SessionData
info of session to store
data
)

Implements org.eclipse.jetty.session.SessionDataMap.store.

Store the session data.

public String
toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.util.component.ContainerLifeCycle:
addBeanaddBeanaddEventListeneraddManagedcontainsdestroydoStopdumpdumpdumpdumpObjectsdumpStdErrgetBeangetBeansgetBeansgetContainedBeansgetContainedBeansisAutoisManagedisUnmanagedmanageremoveBeanremoveBeansremoveEventListenersetBeansstartstopunmanageupdateBeanupdateBeanupdateBeansupdateBeans

Field Detail

_contextback to summary
protected SessionContext _context
_gracePeriodSecback to summary
protected int _gracePeriodSec
_lastExpiryCheckTimeback to summary
protected long _lastExpiryCheckTime
_lastOrphanSweepTimeback to summary
protected long _lastOrphanSweepTime
_savePeriodSecback to summary
protected int _savePeriodSec
DEFAULT_GRACE_PERIOD_SECback to summary
public static final int DEFAULT_GRACE_PERIOD_SEC
DEFAULT_SAVE_PERIOD_SECback to summary
public static final int DEFAULT_SAVE_PERIOD_SEC
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.util.component.ContainerLifeCycle.LOG.

Constructor Detail

AbstractSessionDataStoreback to summary
public AbstractSessionDataStore()

Method Detail

checkStartedback to summary
protected void checkStarted() throws IllegalStateException
cleanOrphansback to summary
public void cleanOrphans(long timeLimit)

Remove all sessions for any context that expired at or before the given time.

Parameters
timeLimit:long

the time before which the sessions must have expired.

doCheckExpiredback to summary
public abstract Set<String> doCheckExpired(Set<String> candidates, long time)

Implemented by subclasses to resolve which sessions in this context that are being managed by this node that should be expired.

Parameters
candidates:Set<String>

the ids of sessions the SessionCache thinks has expired

time:long

the time at which to check for expiry

Returns:Set<String>

the reconciled set of session ids that have been checked in the store

doCleanOrphansback to summary
public abstract void doCleanOrphans(long time)

Implemented by subclasses to delete sessions for other contexts that expired at or before the timeLimit. These are 'orphaned' sessions that are no longer being actively managed by any node. These are explicitly sessions that do NOT belong to this context (other mechanisms such as doGetExpired take care of those). As they don't belong to this context, they cannot be loaded by us. This is called only periodically to avoid placing excessive load on the store.

Parameters
time:long

the upper limit of the expiry time to check in msec

doExistsback to summary
public abstract boolean doExists(String id) throws Exception

Check if a session for the given id exists.

Parameters
id:String

the session id to check

Returns:boolean

true if the session exists in the persistent store, false otherwise

doGetExpiredback to summary
public abstract Set<String> doGetExpired(long before)

Implemented by subclasses to find sessions for this context in the store that expired at or before the time limit and thus not being actively managed by any node. This method is only called periodically (the period is configurable) to avoid putting too much load on the store.

Parameters
before:long

the upper limit of expiry times to check. Sessions expired at or before this timestamp will match.

Returns:Set<String>

the empty set if there are no sessions expired as at the time, or otherwise a set of session ids.

doLoadback to summary
public abstract SessionData doLoad(String id) throws Exception

Load the session from persistent store.

Parameters
id:String

the id of the session to load

Returns:SessionData

the re-inflated session

Exceptions
Exception:
if unable to load the session
doStartback to summary
protected void doStart() throws Exception

Overrides org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Doc from org.eclipse.jetty.util.component.ContainerLifeCycle.doStart.

Starts the managed lifecycle beans in the order they were added.

Annotations
@Override
Exceptions
Exception:

Doc from org.eclipse.jetty.util.component.AbstractLifeCycle.doStart.

If there was a problem starting. Will cause a transition to FAILED state

doStoreback to summary
public abstract void doStore(String id, SessionData data, long lastSaveTime) throws Exception

Store the session data persistently.

Parameters
id:String

identity of session to store

data:SessionData

info of the session

lastSaveTime:long

time of previous save or 0 if never saved

Exceptions
Exception:
if unable to store data
existsback to summary
public boolean exists(String id) throws Exception

Implements org.eclipse.jetty.session.SessionDataStore.exists.

Doc from org.eclipse.jetty.session.SessionDataStore.exists.

Test if data exists for a given session id.

Parameters
id:String

Identity of session whose existence should be checked

Returns:boolean

true if valid, non-expired session exists

Annotations
@Override
Exceptions
Exception:
if problem checking existence with persistence layer
getExpiredback to summary
public Set<String> getExpired(Set<String> candidates)

Implements org.eclipse.jetty.session.SessionDataStore.getExpired.

Doc from org.eclipse.jetty.session.SessionDataStore.getExpired.

Called periodically, this method should search the data store for sessions that have been expired for a 'reasonable' amount of time.

Parameters
candidates:Set<String>

if provided, these are keys of sessions that the SessionDataStore thinks has expired and should be verified by the SessionDataStore

Returns:Set<String>

set of session ids

Annotations
@Override
getGracePeriodSecback to summary
public int getGracePeriodSec()
Annotations
@ManagedAttribute:interval in secs to prevent too eager session scavenging
readonly:true
getSavePeriodSecback to summary
public int getSavePeriodSec()
Returns:int

the savePeriodSec

Annotations
@ManagedAttribute:min secs between saves
readonly:true
initializeback to summary
public void initialize(SessionContext context) throws Exception

Implements org.eclipse.jetty.session.SessionDataMap.initialize.

Doc from org.eclipse.jetty.session.SessionDataMap.initialize.

Initialize this data map for the given context. A SessionDataMap can only be used by one context(/session manager).

Parameters
context:SessionContext

context associated

Annotations
@Override
Exceptions
Exception:
if unable to initialize the
loadback to summary
public SessionData load(String id) throws Exception

Implements org.eclipse.jetty.session.SessionDataMap.load.

Doc from org.eclipse.jetty.session.SessionDataMap.load.

Read in session data.

Parameters
id:String

identity of session to load

Returns:SessionData

the SessionData matching the id

Annotations
@Override
Exceptions
Exception:
if unable to load session data
newSessionDataback to summary
public SessionData newSessionData(String id, long created, long accessed, long lastAccessed, long maxInactiveMs)

Implements org.eclipse.jetty.session.SessionDataStore.newSessionData.

Doc from org.eclipse.jetty.session.SessionDataStore.newSessionData.

Create a new SessionData

Parameters
id:String

the id

created:long

the timestamp when created

accessed:long

the timestamp when accessed

lastAccessed:long

the timestamp when last accessed

maxInactiveMs:long

the max inactive time in milliseconds

Returns:SessionData

a new SessionData object

Annotations
@Override
setGracePeriodSecback to summary
public void setGracePeriodSec(int sec)
setSavePeriodSecback to summary
public void setSavePeriodSec(int savePeriodSec)

The minimum time in seconds between save operations. Saves normally occur every time the last request exits as session. If nothing changes on the session except for the access time and the persistence technology is slow, this can cause delays.

By default the value is 0, which means we save after the last request exists. A non zero value means that we will skip doing the save if the session isn't dirty if the elapsed time since the session was last saved does not exceed this value.

Parameters
savePeriodSec:int

the savePeriodSec to set

storeback to summary
public void store(String id, SessionData data) throws Exception

Implements org.eclipse.jetty.session.SessionDataMap.store.

Doc from org.eclipse.jetty.session.SessionDataMap.store.

Store the session data.

Parameters
id:String

identity of session to store

data:SessionData

info of session to store

Annotations
@Override
Exceptions
Exception:
if unable to write session data
toStringback to summary
public String toString()

Overrides org.eclipse.jetty.util.component.AbstractLifeCycle.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Returns:String

a string representation of the object

Annotations
@Override