jrun.servlet.session
Class SessionService

jrunx.kernel.ServiceAdapter
  |
  +--jrunx.kernel.ServicePartition
        |
        +--jrunx.kernel.ConfigurableServicePartition
              |
              +--jrun.servlet.session.SessionService
All Implemented Interfaces:
ConfigurableServicePartitionMBean, javax.naming.Referenceable, java.lang.Runnable, java.io.Serializable, Service, ServiceMBean, ServicePartitionMBean, Session, SessionServiceMBean

public class SessionService
extends ConfigurableServicePartition
implements Session, java.lang.Runnable

The JRun session service.

Author:
Karl Moss
See Also:
Serialized Form

Field Summary
static java.lang.String FILE_PERSISTENCE
           
protected  java.util.Hashtable holders
           
static java.lang.String JDBC_PERSISTENCE
           
static java.lang.String JSESSIONID
           
protected  LRUTable lruTable
           
protected  Metrics metrics
           
protected  int metricsSessionIMIndex
           
protected  int metricsSessionIndex
           
static java.lang.String SESSION_COUNT
          The metrics key for the number of sessions
static java.lang.String SESSION_IM_COUNT
          The metrics key for the number of sessions in memory
static java.lang.String SESSION_PERSIST_LIST_ID
           
protected  SessionIdGenerator sessionIdGenerator
           
protected  java.lang.String sessionPathMatch
           
protected  WebApplication webapp
           
protected  java.lang.String webappContext
           
 
Fields inherited from class jrunx.kernel.ServicePartition
sortedServices
 
Fields inherited from class jrunx.kernel.ServiceAdapter
DEFAULT_DEACTIVATED, DEFAULT_DOMAIN, DOMAIN_NAME_SEPARATOR, DOMAIN_NAME_SUFFIX, domainName, jndiBindable, LOGGER_CACHE_TIME, SCHEDULER_SERVICE, SECURITY_MANAGER, server, status, TRANSACTION_MANAGER
 
Fields inherited from interface jrunx.kernel.Service
INITIALIZED, STARTED, STARTING, STOPPED, STOPPING, UNINITIALIZED
 
Constructor Summary
SessionService()
           
 
Method Summary
 void addSession(JRunSession session)
           
protected  void clearSessionMetrics()
           
 javax.servlet.http.HttpSession createSession(java.lang.String id)
          Create and register a new session
 void destroy()
          Every service is eventually destroyed.
 java.lang.String encodeURL(java.lang.String url, java.lang.String id)
           
 javax.servlet.http.HttpSession findSession(java.lang.String sessionId)
          Returns the Session bound to the specified session id, or null if the specified session id does not refer to a valid Session.
 void fireSessionCreatedEvent(javax.servlet.http.HttpSession session)
          Fire a sessionCreated event to all of the HttpSessionListener instances
 void fireSessionDestroyedEvent(javax.servlet.http.HttpSession session)
          Fire a sessionDestroyed event to all of the HttpSessionListener instances
 javax.servlet.http.Cookie getCookie(java.lang.String id)
          Return a cookie for tracking this session id
 boolean getCookieActive()
          Determines whether user sessions should be tracked using cookies.
 java.lang.String getCookieSessionID(javax.servlet.http.HttpServletRequest request)
          Attempt to get the session ID from a cookie
 int getMaxInactiveInterval()
          Gets the default time, in seconds, between client requests before the servlet container will invalidate a session.
 java.util.ArrayList getSessions()
           
 Session getSessionService()
          Returns a direct reference to the session service
 java.lang.String getUrlSessionID(javax.servlet.http.HttpServletRequest request)
          Attempt to get the session ID from the URL
 WebApplication getWebApplication()
          Returns the owning WebApplication
 void invalidateSession(java.lang.String id)
          Invalidates the given session ID
 boolean isReplicationServicePresent()
          Determine if a replication service is present.
protected  void notifyDidActivate(javax.servlet.http.HttpSession session)
          Notify any HttpSessionActivationListener objects bound to the given session that they did activate
protected  void notifyWillPassivate(javax.servlet.http.HttpSession session)
          Notify any HttpSessionActivationListener objects bound to the given session that they are about to be passivated
protected  void remove(java.lang.String id)
          Remove the given id from session storage
protected  void remove(java.lang.String id, boolean quiet)
          Remove the given id from session storage
 void replicate(javax.servlet.http.HttpSession session)
          If possible, replicates the session to all replication buddies.
protected  JRunSession restoreSession(java.lang.String id)
           
 void restoreSessionState()
          Attempt to restore the session state from an external source.
 JRunSession retrieve(SessionHolder h)
          Retrieve a session from persistent storage
protected  JRunSession retrieve(SessionHolder h, java.lang.String id)
          Retrieve the session from storage
protected  JRunSession retrieve(SessionHolder h, java.lang.String id, boolean quiet)
          Retrieve the session from storage
 void run()
          Called by the Scheduler to process session swapping
 void saveSessionState()
          Save the current session state externally
 void scheduleRunnable(java.lang.Runnable runnable, long msFromNow)
          Schedule a runnable to execute using the standard SchedulerService
 void setClassLoader(java.lang.ClassLoader loader)
          Tells the session persistence mechanism that a new classloader is being used
 void setMaxInactiveInterval(int seconds)
          Sets the default time, in seconds, between client requests before the servlet container will invalidate a session.
 void setMostRecentlyUsed(int id)
          Marks the given session ID as most recently used
 void start()
          Every service other than mere data collections should start
 void stop()
          Every service other than mere data collections should stop
protected  boolean store(SessionHolder holder, boolean keep)
          Stores the session with the storage provider
protected  boolean store(java.lang.String id, java.lang.Object obj, boolean keep)
           
protected  void unbindAll()
          Unbind all session objects
protected  void unbindAndRemove()
           
 void unscheduleRunnable(java.lang.Runnable runnable)
          Unschedule a runnable to execute using the standard SchedulerService
 void updateInMemoryCount(int n)
          Updates the in memory count metric
 
Methods inherited from class jrunx.kernel.ConfigurableServicePartition
destroyServices, init, initServices, loadAndInit, loadChildren, setChildElements, startServices, stopServices
 
Methods inherited from class jrunx.kernel.ServicePartition
addService, addService, getServices, invokeChain, iterator, removeService, removeService
 
Methods inherited from class jrunx.kernel.ServiceAdapter
bind, findObjectInstance, findObjectInstance, findObjectInstance, getBindToJNDI, getDeactivated, getDomainName, getDomainSearchPath, getJRunService, getLogger, getName, getParentService, getReference, getResourceManager, getServerName, getServerProperties, getStatus, invokeMethod, isInPartition, isPartition, lookup, postDeregister, postRegister, preDeregister, preRegister, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, toString, unbind, updateStatus
 
Methods inherited from interface jrunx.kernel.ConfigurableServicePartitionMBean
setChildElements
 
Methods inherited from interface jrunx.kernel.ServicePartitionMBean
addService, addService, iterator, removeService, removeService
 
Methods inherited from interface jrunx.kernel.ServiceMBean
bind, getBindToJNDI, getDeactivated, getDomainName, getJRunService, getLogger, getName, getParentService, getServerName, requestServer, setBindToJNDI, setDeactivated, setDomainName, setName, setParentService, unbind
 
Methods inherited from interface jrunx.kernel.Service
getStatus, init, updateStatus
 

Field Detail

SESSION_COUNT

public static final java.lang.String SESSION_COUNT
The metrics key for the number of sessions

SESSION_IM_COUNT

public static final java.lang.String SESSION_IM_COUNT
The metrics key for the number of sessions in memory

JSESSIONID

public static final java.lang.String JSESSIONID

webapp

protected WebApplication webapp

webappContext

protected java.lang.String webappContext

sessionIdGenerator

protected SessionIdGenerator sessionIdGenerator

metrics

protected Metrics metrics

metricsSessionIndex

protected int metricsSessionIndex

metricsSessionIMIndex

protected int metricsSessionIMIndex

holders

protected java.util.Hashtable holders

lruTable

protected LRUTable lruTable

sessionPathMatch

protected java.lang.String sessionPathMatch

SESSION_PERSIST_LIST_ID

public static final java.lang.String SESSION_PERSIST_LIST_ID

FILE_PERSISTENCE

public static final java.lang.String FILE_PERSISTENCE

JDBC_PERSISTENCE

public static final java.lang.String JDBC_PERSISTENCE
Constructor Detail

SessionService

public SessionService()
Method Detail

start

public void start()
           throws java.lang.Exception
Description copied from class: ServiceAdapter
Every service other than mere data collections should start
Specified by:
start in interface Service
Overrides:
start in class ConfigurableServicePartition

run

public void run()
Called by the Scheduler to process session swapping
Specified by:
run in interface java.lang.Runnable

destroy

public void destroy()
             throws java.lang.Exception
Description copied from class: ServiceAdapter
Every service is eventually destroyed. Convenience implementation.
Specified by:
destroy in interface Service
Overrides:
destroy in class ConfigurableServicePartition

unbindAll

protected void unbindAll()
Unbind all session objects

setClassLoader

public void setClassLoader(java.lang.ClassLoader loader)
Description copied from interface: Session
Tells the session persistence mechanism that a new classloader is being used
Specified by:
setClassLoader in interface Session

saveSessionState

public void saveSessionState()
Save the current session state externally

getSessions

public java.util.ArrayList getSessions()
Specified by:
getSessions in interface Session

store

protected boolean store(SessionHolder holder,
                        boolean keep)
Stores the session with the storage provider

isReplicationServicePresent

public boolean isReplicationServicePresent()
Description copied from interface: Session
Determine if a replication service is present.
Specified by:
isReplicationServicePresent in interface Session
Following copied from interface: jrun.servlet.session.Session
Returns:
true if a replication service is present

replicate

public void replicate(javax.servlet.http.HttpSession session)
If possible, replicates the session to all replication buddies.
Specified by:
replicate in interface Session

store

protected boolean store(java.lang.String id,
                        java.lang.Object obj,
                        boolean keep)

notifyWillPassivate

protected void notifyWillPassivate(javax.servlet.http.HttpSession session)
Notify any HttpSessionActivationListener objects bound to the given session that they are about to be passivated

notifyDidActivate

protected void notifyDidActivate(javax.servlet.http.HttpSession session)
Notify any HttpSessionActivationListener objects bound to the given session that they did activate

clearSessionMetrics

protected void clearSessionMetrics()

restoreSessionState

public void restoreSessionState()
Attempt to restore the session state from an external source. This first loads sessions stored through session persistence and then loads sessions that may have been borrowed in session replication

stop

public void stop()
          throws java.lang.Exception
Description copied from class: ServiceAdapter
Every service other than mere data collections should stop
Specified by:
stop in interface Service
Overrides:
stop in class ConfigurableServicePartition

unbindAndRemove

protected void unbindAndRemove()

scheduleRunnable

public void scheduleRunnable(java.lang.Runnable runnable,
                             long msFromNow)
Description copied from interface: Session
Schedule a runnable to execute using the standard SchedulerService
Specified by:
scheduleRunnable in interface Session
Overrides:
scheduleRunnable in class ServiceAdapter
Following copied from interface: jrun.servlet.session.Session
Parameters:
runnable - The runnable
msFromNow - The number of ms from now to run, or 0 for immediate

unscheduleRunnable

public void unscheduleRunnable(java.lang.Runnable runnable)
Description copied from interface: Session
Unschedule a runnable to execute using the standard SchedulerService
Specified by:
unscheduleRunnable in interface Session
Overrides:
unscheduleRunnable in class ServiceAdapter
Following copied from interface: jrun.servlet.session.Session
Parameters:
runnable - The runnable

invalidateSession

public void invalidateSession(java.lang.String id)
Description copied from interface: Session
Invalidates the given session ID
Specified by:
invalidateSession in interface Session
Following copied from interface: jrun.servlet.session.Session
Parameters:
sessionID - The session ID

updateInMemoryCount

public void updateInMemoryCount(int n)
Description copied from interface: Session
Updates the in memory count metric
Specified by:
updateInMemoryCount in interface Session
Following copied from interface: jrun.servlet.session.Session
Parameters:
n - The number to increment/decrement

setMostRecentlyUsed

public void setMostRecentlyUsed(int id)
Description copied from interface: Session
Marks the given session ID as most recently used
Specified by:
setMostRecentlyUsed in interface Session
Following copied from interface: jrun.servlet.session.Session
Parameters:
id - The session ID

getSessionService

public Session getSessionService()
Description copied from interface: SessionServiceMBean
Returns a direct reference to the session service
Specified by:
getSessionService in interface SessionServiceMBean
Following copied from interface: jrun.servlet.session.SessionServiceMBean
Returns:
The session service

getMaxInactiveInterval

public int getMaxInactiveInterval()
Description copied from interface: SessionServiceMBean
Gets the default time, in seconds, between client requests before the servlet container will invalidate a session.
Specified by:
getMaxInactiveInterval in interface SessionServiceMBean
Following copied from interface: jrun.servlet.session.SessionServiceMBean
Returns:
The timeout in seconds. A negative value indicates the session should never timeout.

setMaxInactiveInterval

public void setMaxInactiveInterval(int seconds)
Description copied from interface: SessionServiceMBean
Sets the default time, in seconds, between client requests before the servlet container will invalidate a session. A negative time indicates the session should never timeout. The session-timeout attribute in web.xml will override this value. The default is 1800 (30 minutes).
Specified by:
setMaxInactiveInterval in interface SessionServiceMBean
Following copied from interface: jrun.servlet.session.SessionServiceMBean
Parameters:
seconds - The timeout in seconds

getCookieActive

public boolean getCookieActive()
Description copied from interface: SessionServiceMBean
Determines whether user sessions should be tracked using cookies.
Specified by:
getCookieActive in interface SessionServiceMBean
Following copied from interface: jrun.servlet.session.SessionServiceMBean
Returns:
true if user sessions should be tracked using cookies

getUrlSessionID

public java.lang.String getUrlSessionID(javax.servlet.http.HttpServletRequest request)
Description copied from interface: Session
Attempt to get the session ID from the URL
Specified by:
getUrlSessionID in interface Session

getCookieSessionID

public java.lang.String getCookieSessionID(javax.servlet.http.HttpServletRequest request)
Description copied from interface: Session
Attempt to get the session ID from a cookie
Specified by:
getCookieSessionID in interface Session

findSession

public javax.servlet.http.HttpSession findSession(java.lang.String sessionId)
Description copied from interface: Session
Returns the Session bound to the specified session id, or null if the specified session id does not refer to a valid Session.
Specified by:
findSession in interface Session

createSession

public javax.servlet.http.HttpSession createSession(java.lang.String id)
Description copied from interface: Session
Create and register a new session
Specified by:
createSession in interface Session

restoreSession

protected JRunSession restoreSession(java.lang.String id)

addSession

public void addSession(JRunSession session)
Specified by:
addSession in interface Session

remove

protected void remove(java.lang.String id)
Remove the given id from session storage

remove

protected void remove(java.lang.String id,
                      boolean quiet)
Remove the given id from session storage

retrieve

public JRunSession retrieve(SessionHolder h)
Description copied from interface: Session
Retrieve a session from persistent storage
Specified by:
retrieve in interface Session
Following copied from interface: jrun.servlet.session.Session
Parameters:
holder - The SessionHolder
Returns:
The session object or null if not found

retrieve

protected JRunSession retrieve(SessionHolder h,
                               java.lang.String id)
Retrieve the session from storage

retrieve

protected JRunSession retrieve(SessionHolder h,
                               java.lang.String id,
                               boolean quiet)
Retrieve the session from storage

getCookie

public javax.servlet.http.Cookie getCookie(java.lang.String id)
Description copied from interface: Session
Return a cookie for tracking this session id
Specified by:
getCookie in interface Session

getWebApplication

public WebApplication getWebApplication()
Description copied from interface: Session
Returns the owning WebApplication
Specified by:
getWebApplication in interface Session

fireSessionCreatedEvent

public void fireSessionCreatedEvent(javax.servlet.http.HttpSession session)
Fire a sessionCreated event to all of the HttpSessionListener instances
Specified by:
fireSessionCreatedEvent in interface Session

fireSessionDestroyedEvent

public void fireSessionDestroyedEvent(javax.servlet.http.HttpSession session)
Fire a sessionDestroyed event to all of the HttpSessionListener instances
Specified by:
fireSessionDestroyedEvent in interface Session

encodeURL

public java.lang.String encodeURL(java.lang.String url,
                                  java.lang.String id)
Specified by:
encodeURL in interface Session


Copyright � 2002 Macromedia Corporation. All Rights Reserved.