nl.justobjects.pushlet.core
Class SessionManager

java.lang.Object
  extended by nl.justobjects.pushlet.core.SessionManager
All Implemented Interfaces:
ConfigDefs

public class SessionManager
extends java.lang.Object
implements ConfigDefs

Manages lifecycle of Sessions.

Version:
$Id: SessionManager.java,v 1.12 2007/12/04 13:55:53 justb Exp $
Author:
Just van den Broecke - Just Objects ©

Nested Class Summary
private  class SessionManager.AgingTimerTask
          Manages Session timeouts.
 
Field Summary
private static SessionManager instance
          Singleton pattern: single instance.
private  java.lang.Object mutex
          Lock for any operation on Sessions (Session Map and/or -cache).
private  Session[] sessionCache
          Cache of Sessions for iteration and to allow concurrent modification.
private  boolean sessionCacheDirty
          State of SessionCache, becomes true whenever sessionCache out of sync with sessions Map.
private  java.util.Map sessions
          Map of active sessions, keyed by their id, all access is through mutex.
private  java.util.Timer timer
          Timer to schedule session leasing TimerTasks.
private  long TIMER_INTERVAL_MILLIS
           
 
Fields inherited from interface nl.justobjects.pushlet.core.ConfigDefs
CONTROLLER_CLASS, DISPATCHER_CLASS, LISTEN_FORCE_PULL_AGENTS, LISTEN_FORCE_PULL_ALL, LOG_LEVEL, LOG_LEVEL_DEBUG, LOG_LEVEL_ERROR, LOG_LEVEL_FATAL, LOG_LEVEL_INFO, LOG_LEVEL_TRACE, LOG_LEVEL_WARN, LOGGER_CLASS, POLL_REFRESH_TIMEOUT_MILLIS, POLL_REFRESH_WAIT_MAX_MILLIS, POLL_REFRESH_WAIT_MIN_MILLIS, PULL_REFRESH_TIMEOUT_MILLIS, PULL_REFRESH_WAIT_MAX_MILLIS, PULL_REFRESH_WAIT_MIN_MILLIS, QUEUE_READ_TIMEOUT_MILLIS, QUEUE_SIZE, QUEUE_WRITE_TIMEOUT_MILLIS, SESSION_CLASS, SESSION_ID_GENERATION, SESSION_ID_GENERATION_RANDOMSTRING, SESSION_ID_GENERATION_UUID, SESSION_ID_SIZE, SESSION_MANAGER_CLASS, SESSION_TIMEOUT_MINS, SOURCES_ACTIVATE, SUBSCRIBER_CLASS, SUBSCRIPTION_CLASS
 
Constructor Summary
protected SessionManager()
          Singleton pattern: protected constructor needed for derived classes.
 
Method Summary
 void addSession(Session session)
          Add session.
 void apply(java.lang.Object visitor, java.lang.reflect.Method method, java.lang.Object[] args)
          Visitor pattern implementation for Session iteration.
 Session createSession(Event anEvent)
          Create new Session (but add later).
protected  java.lang.String createSessionId()
          Create unique Session id.
protected  void debug(java.lang.String s)
          Util: stdout printing.
static SessionManager getInstance()
          Singleton pattern: get single instance.
 Session getSession(java.lang.String anId)
          Get Session by session id.
 int getSessionCount()
          Get number of listening Sessions.
 Session[] getSessions()
          Get copy of listening Sessions.
 java.lang.String getStatus()
          Get status info.
 boolean hasSession(java.lang.String anId)
          Is Session present?.
protected  void info(java.lang.String s)
          Util: stdout printing.
 Session removeSession(Session aSession)
          Register session for removal.
 void start()
          Starts us.
 void stop()
          Stopis us.
protected  void warn(java.lang.String s)
          Util: stdout printing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

instance

private static SessionManager instance
Singleton pattern: single instance.


timer

private java.util.Timer timer
Timer to schedule session leasing TimerTasks.


TIMER_INTERVAL_MILLIS

private final long TIMER_INTERVAL_MILLIS
See Also:
Constant Field Values

sessions

private java.util.Map sessions
Map of active sessions, keyed by their id, all access is through mutex.


sessionCache

private Session[] sessionCache
Cache of Sessions for iteration and to allow concurrent modification.


sessionCacheDirty

private boolean sessionCacheDirty
State of SessionCache, becomes true whenever sessionCache out of sync with sessions Map.


mutex

private final java.lang.Object mutex
Lock for any operation on Sessions (Session Map and/or -cache).

Constructor Detail

SessionManager

protected SessionManager()
Singleton pattern: protected constructor needed for derived classes.

Method Detail

apply

public void apply(java.lang.Object visitor,
                  java.lang.reflect.Method method,
                  java.lang.Object[] args)
Visitor pattern implementation for Session iteration.

This method can be used to iterate over all Sessions in a threadsafe way. See Dispatcher.multicast and broadcast methods for examples.

Parameters:
visitor - the object that should implement method parm
method - the method to be called from visitor
args - arguments to be passed in visit method, args[0] will always be Session object

createSession

public Session createSession(Event anEvent)
                      throws PushletException
Create new Session (but add later).

Throws:
PushletException

getInstance

public static SessionManager getInstance()
Singleton pattern: get single instance.


getSession

public Session getSession(java.lang.String anId)
Get Session by session id.


getSessions

public Session[] getSessions()
Get copy of listening Sessions.


getSessionCount

public int getSessionCount()
Get number of listening Sessions.


getStatus

public java.lang.String getStatus()
Get status info.


hasSession

public boolean hasSession(java.lang.String anId)
Is Session present?.


addSession

public void addSession(Session session)
Add session.


removeSession

public Session removeSession(Session aSession)
Register session for removal.


start

public void start()
           throws PushletException
Starts us.

Throws:
PushletException

stop

public void stop()
Stopis us.


createSessionId

protected java.lang.String createSessionId()
Create unique Session id.


info

protected void info(java.lang.String s)
Util: stdout printing.


warn

protected void warn(java.lang.String s)
Util: stdout printing.


debug

protected void debug(java.lang.String s)
Util: stdout printing.



Copyright 2000-2003 - Just Objects B.V.