public class SessionManager<T> extends java.lang.Object implements SessionProvider<T>
SessionManager
object is used to create sessions
that are active for a given time period. Each session is referenced
using a unique key, and only one session exists per key at a time.
Once a session has been created it remains active for a fixed time
period, this time period is renewed each time that session is open.
When the session manager is no longer required it can be closed. Closing the session manager will cancel and destroy all active sessions, and release all resources occupied by the provider such as threads and memory. Typically it is advisable to close a manager when it is not longer required by the application.
Constructor and Description |
---|
SessionManager()
Constructor for the
SessionManager object. |
SessionManager(long duration,
java.util.concurrent.TimeUnit unit)
Constructor for the
SessionManager object. |
SessionManager(Observer<T> observer)
Constructor for the
SessionManager object. |
SessionManager(Observer<T> observer,
long duration,
java.util.concurrent.TimeUnit unit)
Constructor for the
SessionManager object. |
Modifier and Type | Method and Description |
---|---|
void |
close()
This
close method is used to close the manager and
release all resources associated with it. |
Session |
open(T key)
This
open method is used to either open an existing
session or create a new session if one does not exist. |
Session |
open(T key,
boolean create)
This
open method is used to either open an existing
session or create a new session if requested. |
public SessionManager()
SessionManager
object. This is
used to create a session manager than can manage sessions. This
sets the default renewal duration of the sessions created to
twenty minutes. If the session is not used within this duration
then it is destroyed and its state is lost.public SessionManager(Observer<T> observer)
SessionManager
object. This is
used to create a session manager than can manage sessions. This
sets the default renewal duration of the sessions created to
twenty minutes. If the session is not used within this duration
then it is destroyed and its state is lost.observer
- this is used to observe the session managerpublic SessionManager(long duration, java.util.concurrent.TimeUnit unit)
SessionManager
object. This is
used to create a session manager than can manage sessions. This
takes a duration which specifies the default lifetime of a
session, also when a session is opened for a second time this
represents the renewal duration for that instance.duration
- this is the default renewal duration to useunit
- this is the time unit for the specified durationpublic SessionManager(Observer<T> observer, long duration, java.util.concurrent.TimeUnit unit)
SessionManager
object. This is
used to create a session manager than can manage sessions. This
takes a duration which specifies the default lifetime of a
session, also when a session is opened for a second time this
represents the renewal duration for that instance.observer
- this is used to observe the session managerduration
- this is the default renewal duration to useunit
- this is the time unit for the specified durationpublic Session open(T key) throws LeaseException
open
method is used to either open an existing
session or create a new session if one does not exist. This is
always guaranteed to open a session. Upon each open for a given
sesion that sessions expiry is renewed for a fixed period of
time, typically this is several minutes long.open
in interface SessionProvider<T>
key
- the unique key identifying the session instanceLeaseException
- if the keyed session can not be retrievedpublic Session open(T key, boolean create) throws LeaseException
open
method is used to either open an existing
session or create a new session if requested. This is used to
optionally create a new session if one does not already exist.
This is used in situations where a session might not be required
but the existence of one may be queried. Once created a session
is active for a fixed time period.open
in interface SessionProvider<T>
key
- the unique key identifying the session instanceLeaseException
- if the keyed session can not be retrievedpublic void close() throws LeaseException
close
method is used to close the manager and
release all resources associated with it. This includes canceling
all active sessions and emptying the contents of those sessions.
All threads and other such resources are released by this method.close
in interface SessionProvider<T>
LeaseException
- if the session provider can not be shutdown