org.marketcetera.util.ws.stateful
Class SessionManager<T>

java.lang.Object
  extended by org.marketcetera.util.ws.stateful.SessionManager<T>

public class SessionManager<T>
extends Object

A session manager. It maps session IDs (SessionId) to session holders (SessionHolder), and (optionally) automatically expires sessions (map entries) which remain unused for a time interval that exceeds the session lifespan. This expiration is performed at regular intervals by a reaper thread, initiated during construction as part of the caller's thread group; the interval between scans is normally 5% of the session lifespan.

Since:
1.0.0
Version:
$Id: SessionManager.java 16154 2012-07-14 16:34:05Z colin $
Author:
tlerios@marketcetera.com

Field Summary
static long INFINITE_SESSION_LIFESPAN
          A sentinel value for an infinite session lifespan (non-expiring sessions).
static long MAX_SCAN_INTERVAL
          The maximum sleep interval between reaper scans, in ms.
 
Constructor Summary
SessionManager()
          Creates a new session manager whose sessions never expire.
SessionManager(long sessionLife)
          Creates a new session manager whose sessions have the given lifespan, in ms.
SessionManager(SessionFactory<T> sessionFactory)
          Creates a new session manager whose sessions are created by the given factory, and which never expire.
SessionManager(SessionFactory<T> sessionFactory, long sessionLife)
          Creates a new session manager whose sessions are created by the given factory, and which have the given lifespan, in ms.
 
Method Summary
 SessionHolder<T> get(SessionId id)
          Returns the holder that the receiver associates with the given session ID.
 long getLifespan()
          Returns the lifespan of the sessions managed by the receiver.
 NodeId getServerId()
          Returns the receiver's server ID.
 SessionFactory<T> getSessionFactory()
          Returns the receiver's session factory.
 void put(SessionId id, SessionHolder<T> holder)
          Adds the given holder, associated with the given session ID, to the receiver.
 void remove(SessionId id)
          Removes the holder that the receiver associates with the given session ID.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAX_SCAN_INTERVAL

public static final long MAX_SCAN_INTERVAL
The maximum sleep interval between reaper scans, in ms.

See Also:
Constant Field Values

INFINITE_SESSION_LIFESPAN

public static final long INFINITE_SESSION_LIFESPAN
A sentinel value for an infinite session lifespan (non-expiring sessions).

See Also:
Constant Field Values
Constructor Detail

SessionManager

public SessionManager(SessionFactory<T> sessionFactory,
                      long sessionLife)
Creates a new session manager whose sessions are created by the given factory, and which have the given lifespan, in ms.

Parameters:
sessionFactory - The session factory. It may be null.
sessionLife - The lifespan. Use INFINITE_SESSION_LIFESPAN for an infinite lifespan.

SessionManager

public SessionManager(long sessionLife)
Creates a new session manager whose sessions have the given lifespan, in ms.

Parameters:
sessionLife - The lifespan. Use INFINITE_SESSION_LIFESPAN for an infinite lifespan.

SessionManager

public SessionManager(SessionFactory<T> sessionFactory)
Creates a new session manager whose sessions are created by the given factory, and which never expire.

Parameters:
sessionFactory - The session factory. It may be null.

SessionManager

public SessionManager()
Creates a new session manager whose sessions never expire.

Method Detail

getServerId

public NodeId getServerId()
Returns the receiver's server ID.

Returns:
The server ID, which may be null.

getSessionFactory

public SessionFactory<T> getSessionFactory()
Returns the receiver's session factory.

Returns:
The factory. It may be null.

getLifespan

public long getLifespan()
Returns the lifespan of the sessions managed by the receiver.

Returns:
The lifespan, in ms.

put

public void put(SessionId id,
                SessionHolder<T> holder)
Adds the given holder, associated with the given session ID, to the receiver. This addition counts as an access that renews the session's expiration counter.

Parameters:
id - The session ID.
holder - The holder.

get

public SessionHolder<T> get(SessionId id)
Returns the holder that the receiver associates with the given session ID. This access renews the session's expiration counter.

Parameters:
id - The session ID.
Returns:
The holder. It is null if there is no holder for the given ID.

remove

public void remove(SessionId id)
Removes the holder that the receiver associates with the given session ID. This method is a no-op if no such association exists.

Parameters:
id - The session ID.


Copyright © 2012. All Rights Reserved.