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

public Class FileSessionDataStore

extends ObjectStreamSessionDataStore
Class Inheritance
Annotations
@ManagedObject
Imports
java.io.DataInputStream, .DataOutputStream, .File, .FileInputStream, .FileOutputStream, .IOException, .InputStream, .ObjectInputStream, .ObjectOutputStream, .OutputStream, java.nio.file.FileVisitOption, .Files, .Path, java.util.HashSet, .Map, .Set, java.util.concurrent.ConcurrentHashMap, .TimeUnit, java.util.stream.Stream, org.eclipse.jetty.util.ExceptionUtil, .StringUtil, org.eclipse.jetty.util.annotation.ManagedAttribute, .ManagedObject, org.slf4j.Logger, .LoggerFactory

FileSessionDataStore A file-based store of session data.

Field Summary

Modifier and TypeField and Description
protected String
protected boolean
protected long
protected Map<String, String>
protected File
private static final Logger

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public boolean
delete(String
session id
id
)

Implements org.eclipse.jetty.session.SessionDataMap.delete.

Delete a session

public boolean

Returns:

true if file was deleted, false otherwise
deleteFile
(String
name of the file containing the session's information
filename
)

Delete the file associated with a session

public Set<String>

Returns:

the complete set of sessions that have expired, including those that are not currently loaded into the SessionCache
doCheckExpired
(final Set<String>
the set of session ids that the SessionCache believes have expired
candidates
,
long
the time at which to check for expiry
time
)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doCheckExpired.

Check to see which sessions have expired.

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

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doCleanOrphans.

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

public boolean
doExists(String
the session id to check
id
)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doExists.

Check if a session for the given id exists.

public Set<String>
doGetExpired(long
the upper limit of expiry times to check. Sessions expired at or before this timestamp will match.
timeLimit
)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doGetExpired.

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 SessionData
doLoad(String
the id of the session to load
id
)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doLoad.

Load the session from persistent store.

protected void
doStart()

Overrides org.eclipse.jetty.session.AbstractSessionDataStore.doStart.

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

protected void
doStop()

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

Stops the managed lifecycle beans in the reverse order they were added.

public 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
)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doStore.

Store the session data persistently.

protected String
protected long
protected String
protected String

Returns:

the session id plus context
getIdWithContext
(String
identity of session
id
)

Get the session id with its context.

protected String

Returns:

the session id plus context and expiry
getIdWithContextAndExpiry
(SessionData
the session data
data
)

Get the session id with its context and its expiry time

protected String

Returns:

the session id plus context
getIdWithContextFromFilename
(String
the name of the file to use
filename
)

Extract the session id and context from the filename

public File
public void
initialize(SessionContext
context associated
context
)

Overrides org.eclipse.jetty.session.AbstractSessionDataStore.initialize.

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

Initialize this data map for the given context.

public void
initializeStore()

Read the names of the existing session files and build a map of fully qualified session ids (ie with context) to filename.

public boolean
protected boolean

Returns:

true if the filename has the correct filename format and is for this context
isOurContextSessionFilename
(String
the filename to check
filename
)

Check if the filename matches our session pattern and is a session for our context.

public boolean
isPassivating()

Implements org.eclipse.jetty.session.SessionDataStore.isPassivating.

True if this type of datastore will passivate session objects

protected boolean

Returns:

true if the filename has the correct filename format
isSessionFilename
(String
the filename to check
filename
)

Check if the filename is a session filename.

protected SessionData

Returns:

the session data
load
(InputStream
file input stream containing session data
is
,
String
the id we've been told to load
expectedId
)

Load the session data from a file.

protected void
save(OutputStream
the output stream to save to
os
,
String
identity of the session
id
,
SessionData
the info of the session
data
)

Save the session data.

public void
setDeleteUnrestorableFiles(boolean deleteUnrestorableFiles)

public void
setStoreDir(File storeDir)

protected void
sweepDisk(long time)

Check all session files for any context and remove any that expired at or before the time limit.

protected void
sweepFile(long
the time in msec
time
,
Path
the file to check
p
)

Delete file (from any context) that expired at or before the given time

public String
toString()

Overrides org.eclipse.jetty.session.AbstractSessionDataStore.toString.

Returns a string representation of the object.

Inherited from org.eclipse.jetty.session.ObjectStreamSessionDataStore:
deserializeAttributesnewObjectInputStreamnewObjectOutputStreamserializeAttributes

Field Detail

_contextStringback to summary
protected String _contextString
_deleteUnrestorableFilesback to summary
protected boolean _deleteUnrestorableFiles
_lastSweepTimeback to summary
protected long _lastSweepTime
_sessionFileMapback to summary
protected Map<String, String> _sessionFileMap
_storeDirback to summary
protected File _storeDir
LOGback to summary
private static final Logger LOG

Hides org.eclipse.jetty.session.AbstractSessionDataStore.LOG.

Constructor Detail

FileSessionDataStoreback to summary
public FileSessionDataStore()

Method Detail

deleteback to summary
public boolean delete(String id) throws Exception

Implements org.eclipse.jetty.session.SessionDataMap.delete.

Delete a session

Parameters
id:String

session id

Returns:boolean

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

true if the session was deleted

Annotations
@Override
Exceptions
Exception:

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

if unable to delete session data

deleteFileback to summary
public boolean deleteFile(String filename) throws Exception

Delete the file associated with a session

Parameters
filename:String

name of the file containing the session's information

Returns:boolean

true if file was deleted, false otherwise

Exceptions
Exception:
indicating delete failure
doCheckExpiredback to summary
public Set<String> doCheckExpired(final Set<String> candidates, long time)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doCheckExpired.

Check to see which sessions have expired.

Parameters
candidates:Set<String>

the set of session ids that the SessionCache believes have expired

time:long

Doc from org.eclipse.jetty.session.AbstractSessionDataStore.doCheckExpired.

the time at which to check for expiry

Returns:Set<String>

the complete set of sessions that have expired, including those that are not currently loaded into the SessionCache

Annotations
@Override
doCleanOrphansback to summary
public void doCleanOrphans(long time)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doCleanOrphans.

Doc from org.eclipse.jetty.session.AbstractSessionDataStore.doCleanOrphans.

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

Annotations
@Override
doExistsback to summary
public boolean doExists(String id) throws Exception

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doExists.

Doc from org.eclipse.jetty.session.AbstractSessionDataStore.doExists.

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

Annotations
@Override
doGetExpiredback to summary
public Set<String> doGetExpired(long timeLimit)

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doGetExpired.

Doc from org.eclipse.jetty.session.AbstractSessionDataStore.doGetExpired.

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
timeLimit: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.

Annotations
@Override
doLoadback to summary
public SessionData doLoad(String id) throws Exception

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doLoad.

Doc from org.eclipse.jetty.session.AbstractSessionDataStore.doLoad.

Load the session from persistent store.

Parameters
id:String

the id of the session to load

Returns:SessionData

the re-inflated session

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

Overrides org.eclipse.jetty.session.AbstractSessionDataStore.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

doStopback to summary
protected void doStop() throws Exception

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

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

Stops the managed lifecycle beans in the reverse order they were added.

Annotations
@Override
Exceptions
Exception:

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

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

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

Implements abstract org.eclipse.jetty.session.AbstractSessionDataStore.doStore.

Doc from org.eclipse.jetty.session.AbstractSessionDataStore.doStore.

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

Annotations
@Override
Exceptions
Exception:
if unable to store data
getContextFromFilenameback to summary
protected String getContextFromFilename(String filename)
getExpiryFromFilenameback to summary
protected long getExpiryFromFilename(String filename)
getIdFromFilenameback to summary
protected String getIdFromFilename(String filename)
getIdWithContextback to summary
protected String getIdWithContext(String id)

Get the session id with its context.

Parameters
id:String

identity of session

Returns:String

the session id plus context

getIdWithContextAndExpiryback to summary
protected String getIdWithContextAndExpiry(SessionData data)

Get the session id with its context and its expiry time

Parameters
data:SessionData

the session data

Returns:String

the session id plus context and expiry

getIdWithContextFromFilenameback to summary
protected String getIdWithContextFromFilename(String filename)

Extract the session id and context from the filename

Parameters
filename:String

the name of the file to use

Returns:String

the session id plus context

getStoreDirback to summary
public File getStoreDir()
Annotations
@ManagedAttribute:dir where sessions are stored
readonly:true
initializeback to summary
public void initialize(SessionContext context) throws Exception

Overrides org.eclipse.jetty.session.AbstractSessionDataStore.initialize.

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
initializeStoreback to summary
public void initializeStore() throws Exception

Read the names of the existing session files and build a map of fully qualified session ids (ie with context) to filename. If there is more than one file for the same session, only the most recently modified will be kept and the rest deleted. At the same time, any files - for any context - that expired a long time ago will be cleaned up.

Exceptions
Exception:
if storeDir doesn't exist, isn't readable/writeable or contains 2 files with the same lastmodify time for the same session. Throws IOException if the lastmodifytimes can't be read.
isDeleteUnrestorableFilesback to summary
public boolean isDeleteUnrestorableFiles()
isOurContextSessionFilenameback to summary
protected boolean isOurContextSessionFilename(String filename)

Check if the filename matches our session pattern and is a session for our context.

Parameters
filename:String

the filename to check

Returns:boolean

true if the filename has the correct filename format and is for this context

isPassivatingback to summary
public boolean isPassivating()

Implements org.eclipse.jetty.session.SessionDataStore.isPassivating.

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

True if this type of datastore will passivate session objects

Returns:boolean

true if this store can passivate sessions, false otherwise

Annotations
@Override
@ManagedAttribute:are sessions serialized by this store
readonly:true
isSessionFilenameback to summary
protected boolean isSessionFilename(String filename)

Check if the filename is a session filename.

Parameters
filename:String

the filename to check

Returns:boolean

true if the filename has the correct filename format

loadback to summary
protected SessionData load(InputStream is, String expectedId) throws Exception

Load the session data from a file.

Parameters
is:InputStream

file input stream containing session data

expectedId:String

the id we've been told to load

Returns:SessionData

the session data

saveback to summary
protected void save(OutputStream os, String id, SessionData data) throws Exception

Save the session data.

Parameters
os:OutputStream

the output stream to save to

id:String

identity of the session

data:SessionData

the info of the session

setDeleteUnrestorableFilesback to summary
public void setDeleteUnrestorableFiles(boolean deleteUnrestorableFiles)
setStoreDirback to summary
public void setStoreDir(File storeDir)
sweepDiskback to summary
protected void sweepDisk(long time)

Check all session files for any context and remove any that expired at or before the time limit.

sweepFileback to summary
protected void sweepFile(long time, Path p)

Delete file (from any context) that expired at or before the given time

Parameters
time:long

the time in msec

p:Path

the file to check

toStringback to summary
public String toString()

Overrides org.eclipse.jetty.session.AbstractSessionDataStore.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