com.sdm.quasar.client.core.application
Class AbstractSessionManager

java.lang.Object
  extended bycom.sdm.quasar.client.core.application.AbstractSessionManager
All Implemented Interfaces:
Disposable, SessionManager
Direct Known Subclasses:
DefaultJSFSessionManager, DefaultSessionManager

public abstract class AbstractSessionManager
extends java.lang.Object
implements SessionManager, Disposable

Basic implementation of SessionManager.

Derived classes must implement SessionManager.createSession() and SessionManager.disposeSession(com.sdm.quasar.client.core.application.SessionId) in a threadsafe manner that allows for maximum parallelization.

Derived classes can access the registered sessions by using registerSession(com.sdm.quasar.client.core.application.Session), unregisterSession(com.sdm.quasar.client.core.application.SessionId), hasRegisteredSession(com.sdm.quasar.client.core.application.SessionId), and getRegisteredSession(com.sdm.quasar.client.core.application.SessionId).

The implementation of SessionManager.createSession() should determine the session instance and use createSessionInstance(com.sdm.quasar.client.core.application.SessionId) to create a new session or return an existing (if applicable). The new session should be added to the manager using registerSession(com.sdm.quasar.client.core.application.Session). If a new session is created, it should notify the SessionListeners using fireSessionCreated(com.sdm.quasar.client.core.application.Session).

The implementation of SessionManager.disposeSession(com.sdm.quasar.client.core.application.SessionId) should notify the SessionListeners using fireSessionWillBeDisposed(com.sdm.quasar.client.core.application.Session), then dispose the session using Session.dispose() and finally unregister it using unregisterSession(com.sdm.quasar.client.core.application.SessionId).

Version:
1.0
Author:
Carsten Lucke, sd&m AG, Bernd Olleck, sd&m AG

Field Summary
protected  java.util.List listeners
          Keeps the list of registered SessionListener objects.
 
Constructor Summary
AbstractSessionManager(Application application, SessionCreator sessionCreator)
          Constructor.
 
Method Summary
 void addSessionListener(SessionListener listener)
          Registers an observer that is notified when sessions are created and disposed.
abstract  Session createSession()
          Creates and initializes a session object.
protected  Session createSessionInstance(SessionId sessionId)
          Creates the session using a SessionCreator.
 void dispose()
          This implementation disposes all sessions.
abstract  void disposeSession(SessionId sessionId)
          Disposes a session.
protected  void fireSessionCreated(Session session)
          Notifies all registered SessionListeners that a new session has been created.
protected  void fireSessionWillBeDisposed(Session session)
          Notifies all registered SessionListeners that a session will be disposed.
protected  Application getApplication()
           
protected  Session getRegisteredSession(SessionId sessionId)
          Returns the session with the given id.
protected  int getRegisteredSessionCount()
          Returns the number of sessions that are currently registered
protected  boolean hasRegisteredSession(SessionId sessionId)
          Tests if a session with a given id has been registered.
protected  void registerSession(Session session)
          Registers a session.
 void removeSessionListener(SessionListener listener)
          Unregisters an observer.
protected  void unregisterSession(SessionId sessionId)
          Unregisteres a session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

listeners

protected final java.util.List listeners
Keeps the list of registered SessionListener objects.

Constructor Detail

AbstractSessionManager

public AbstractSessionManager(Application application,
                              SessionCreator sessionCreator)
Constructor.

Parameters:
application - the Application this session manager forks for.
sessionCreator - the SessionCreator that is used for creating a Session.
Method Detail

addSessionListener

public void addSessionListener(SessionListener listener)
Description copied from interface: SessionManager
Registers an observer that is notified when sessions are created and disposed.

Specified by:
addSessionListener in interface SessionManager
Parameters:
listener - the listener to be added

removeSessionListener

public void removeSessionListener(SessionListener listener)
Description copied from interface: SessionManager
Unregisters an observer.

Specified by:
removeSessionListener in interface SessionManager
Parameters:
listener - the listener to be removed

getApplication

protected Application getApplication()
Returns:
the Application this SessionManager works for.

registerSession

protected void registerSession(Session session)
Registers a session.

Parameters:
session - the new session

hasRegisteredSession

protected boolean hasRegisteredSession(SessionId sessionId)
Tests if a session with a given id has been registered.

Parameters:
sessionId - the session id
Returns:
true iff the session has been registered

unregisterSession

protected void unregisterSession(SessionId sessionId)
Unregisteres a session.

Parameters:
sessionId - the session id of the session that should be unregistered

getRegisteredSession

protected Session getRegisteredSession(SessionId sessionId)
Returns the session with the given id. If the id is unknown, null will be returned.

Parameters:
sessionId - the session id
Returns:
the session object, may be null

getRegisteredSessionCount

protected int getRegisteredSessionCount()
Returns the number of sessions that are currently registered

Returns:
the number of sessions

createSessionInstance

protected Session createSessionInstance(SessionId sessionId)
Creates the session using a SessionCreator.

Parameters:
sessionId - the session id of the new session
Returns:
the session instance

dispose

public void dispose()
             throws DisposeException
This implementation disposes all sessions.

For more information see Disposable.dispose().

Specified by:
dispose in interface Disposable
Throws:
DisposeException - if there was one or more errors while disposing the component.

fireSessionCreated

protected void fireSessionCreated(Session session)
Notifies all registered SessionListeners that a new session has been created.

Parameters:
session - the new session

fireSessionWillBeDisposed

protected void fireSessionWillBeDisposed(Session session)
Notifies all registered SessionListeners that a session will be disposed.

Parameters:
session - the new session

createSession

public abstract Session createSession()
Description copied from interface: SessionManager
Creates and initializes a session object. If the session identity depends on other circumstances (e.g. a web-based session), the session manager may return an existing session object.

Specified by:
createSession in interface SessionManager
Returns:
the session object.
See Also:
SessionManager.createSession()

disposeSession

public abstract void disposeSession(SessionId sessionId)
                             throws DisposeException
Description copied from interface: SessionManager
Disposes a session.

The implementation should call Session.dispose().

The call to this method is irrevokable. If you want to allow for user interaction or server calls before the session or its dialogs are disposed, you should do so before calling.

Note: The implementation must not return before the session is disposed. Any threads or asynchronous calls started must be completed before this method returns.

Specified by:
disposeSession in interface SessionManager
Parameters:
sessionId - the id of the session to be disposed
Throws:
DisposeException - if there is an error while disposing the session
See Also:
SessionManager.disposeSession(com.sdm.quasar.client.core.application.SessionId)