com.caucho.server.session
Class SessionManager

java.lang.Object
  extended by com.caucho.server.session.SessionManager
All Implemented Interfaces:
ObjectManager, AlarmListener, java.util.EventListener

public final class SessionManager
extends java.lang.Object
implements ObjectManager, AlarmListener

Manages sessions in a web-app.


Field Summary
protected static L10N L
           
protected static java.util.logging.Logger log
           
 
Constructor Summary
SessionManager(WebApp app)
          Creates and initializes a new session manager
 
Method Summary
 void addActivationListener(HttpSessionActivationListener listener)
          Adds a new HttpSessionActivationListener.
 void addAttributeListener(HttpSessionAttributeListener listener)
          Adds a new HttpSessionAttributeListener.
 void addListener(HttpSessionListener listener)
          Adds a new HttpSessionListener.
 void close()
          Cleans up the sessions when the WebApp shuts down gracefully.
 boolean containsSession(java.lang.String id)
          Returns true if the session exists in this manager.
 StoreManager createFileStore()
          Sets the file store.
 StoreManager createJdbcStore()
          Sets the jdbc store.
 SessionImpl createSession(java.lang.String oldId, long now, HttpServletRequest request, boolean fromCookie)
          Create a new session.
 java.lang.String createSessionId(HttpServletRequest request)
          Creates a pseudo-random session id.
 java.lang.String createSessionId(HttpServletRequest request, boolean create)
          Creates a pseudo-random session id.
 java.lang.String createSessionIdImpl(HttpServletRequest request)
           
static int decode(int code)
           
 boolean enableSessionCookies()
          Returns true if sessions use the cookie header.
 boolean enableSessionUrls()
          Returns true if sessions can use the session rewriting.
 int getActiveSessionCount()
          Returns the current number of active sessions.
 SessionManagerMXBean getAdmin()
          Returns the admin.
 java.lang.String getAlternateSessionPrefix()
          Returns the alternate session prefix, before the URL for wap.
protected  Cluster getCluster()
          Gets the cluster.
 java.lang.String getCookieDomain()
          Returns the default session cookie domain.
 long getCookieLength()
          Returns the cookie length.
 long getCookieMaxAge()
          Returns the max-age of the session cookie.
 java.lang.String getCookieName()
          Returns the default cookie name.
 java.lang.String getCookiePort()
          Gets the cookie ports.
 boolean getCookieSecure()
          Returns the secure of the session cookie.
 int getCookieVersion()
          Returns the cookie version.
 java.util.logging.Logger getDebug()
          Returns the debug log
 java.lang.String getDistributionId()
           
 long getMaxIdleTime()
          Returns the idle time.
 int getReuseSessionId()
          True if the server should reuse the current session id if the session doesn't exist.
 java.lang.String getSaveMode()
          Returns the string value of the save-mode.
 SessionImpl getSession(java.lang.String key, long now, boolean create, boolean fromCookie)
          Returns a session from the session store, returning null if there's no cached session.
 int getSessionActiveCount()
          Returns the active sessions.
 long getSessionCreateCount()
          Returns the created sessions.
 long getSessionInvalidateCount()
          Returns the invalidate sessions.
 int getSessionMax()
          Returns the maximum number of sessions.
 java.lang.String getSessionPrefix()
          Returns the session prefix, ie..
 Store getSessionStore()
          Returns the session store.
 long getSessionTimeout()
          Returns the default session timeout in milliseconds.
 long getSessionTimeoutCount()
          Returns the timeout sessions.
 int getSrunIndex()
          Returns the index of this JVM in the ring.
 int getSrunLength()
          Returns the number of sruns in the cluster
 java.lang.String getSSLCookieName()
          Returns the SSL cookie name.
 void handleAlarm(Alarm alarm)
          Timeout for reaping old sessions
 void init()
           
 void invalidateSession(SessionImpl session)
          Invalidates a session from the cache.
 boolean isClosed()
          Returns true if the sessions are closed.
 boolean isCookieAppendServerIndex()
          Sets module session id generation.
 boolean isCookieHttpOnly()
          Returns the http-only of the session cookie.
 boolean isEmpty(java.lang.Object obj)
          Checks if the session is empty.
 boolean isHessianSerialization()
          Returns true for Hessian serialization.
 boolean isInSessionGroup(java.lang.String id)
           
 boolean isInvalidateAfterListener()
          True if the session should be invalidated after the listener.
 boolean isSaveAfterRequest()
          True if sessions should be saved after the request.
 boolean isSaveBeforeFlush()
          True if sessions should be saved before each flush.
 boolean isSaveBeforeHeaders()
          True if sessions should be saved before the HTTP headers.
 boolean isSaveOnlyOnShutdown()
          True if sessions should only be saved on shutdown.
 boolean isSaveOnShutdown()
          True if sessions should be saved on shutdown.
 void load(java.io.InputStream is, java.lang.Object obj)
          Loads the session.
 void notifyRemove(java.lang.String id)
          Notification from the cluster.
 void notifyUpdate(java.lang.String id)
          Notification from the cluster.
 void removeSession(SessionImpl session)
          Removes a session from the cache.
 boolean reuseSessionId(boolean fromCookie)
          True if the server should reuse the current session id if the session doesn't exist.
 void setAlwaysLoadSession(boolean load)
          True if sessions should always be loadd.
 void setAlwaysSaveSession(boolean save)
          True if sessions should always be saved.
 void setClusterStore(boolean isEnable)
          Sets the cluster store.
 void setCookieAppendServerIndex(boolean isAppend)
          Sets module session id generation.
 void setCookieDomain(java.lang.String domain)
          Sets the default session cookie domain.
 void setCookieHttpOnly(boolean httpOnly)
          Sets the http-only of the session cookie.
 void setCookieLength(int cookieLength)
          Sets the cookie length
 void setCookieMaxAge(Period maxAge)
          Sets the max-age of the session cookie.
 void setCookieModuloCluster(boolean isModulo)
          Sets module session id generation.
 void setCookiePort(java.lang.String port)
          Sets the cookie ports.
 void setCookieSecure(boolean secure)
          Sets the secure of the session cookie.
 void setCookieVersion(int cookieVersion)
          Sets the cookie version.
 void setDistributionId(java.lang.String distributionId)
           
 void setEnableCookies(boolean enableCookies)
          Returns true if sessions use the cookie header.
 void setEnableUrlRewriting(boolean enableUrls)
          Returns true if sessions can use the session rewriting.
 void setIgnoreSerializationErrors(boolean ignore)
          True if serialization errors should just fail silently.
 void setInvalidateAfterListener(boolean inv)
          True if the session should be invalidated after the listener.
 void setPersistentPath(Path path)
          Returns the session factory.
 void setPersistentStore(JndiBuilder store)
          Sets the persistent store.
 void setReuseSessionId(java.lang.String reuse)
          True if the server should reuse the current session id if the session doesn't exist.
 void setSaveMode(java.lang.String mode)
          Sets the save-mode: before-flush, before-headers, after-request, on-shutdown
 void setSaveOnlyOnShutdown(boolean save)
          True if sessions should only be saved on shutdown.
 void setSaveOnShutdown(boolean save)
          True if sessions should only be saved on shutdown.
 void setSerializationType(java.lang.String type)
          Sets the serialization type.
 void setSessionMax(int max)
          Returns the maximum number of sessions.
 void setSessionTimeout(long timeout)
          Set the default session timeout in minutes
 void setTcpStore(boolean isEnable)
          Sets the tcp store.
 void setUsePersistentStore(boolean enable)
          Sets the cluster store.
 void start()
           
 void store(java.io.OutputStream os, java.lang.Object obj)
          Saves the session.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

L

protected static final L10N L

log

protected static final java.util.logging.Logger log
Constructor Detail

SessionManager

public SessionManager(WebApp app)
               throws java.lang.Exception
Creates and initializes a new session manager

Parameters:
app - the web-app webApp
registry - the web-app configuration node
Throws:
java.lang.Exception
Method Detail

getAdmin

public SessionManagerMXBean getAdmin()
Returns the admin.


getCluster

protected Cluster getCluster()
Gets the cluster.


getSessionPrefix

public java.lang.String getSessionPrefix()
Returns the session prefix, ie.. ";jsessionid=".


getAlternateSessionPrefix

public java.lang.String getAlternateSessionPrefix()
Returns the alternate session prefix, before the URL for wap.


getCookieVersion

public int getCookieVersion()
Returns the cookie version.


setCookieVersion

public void setCookieVersion(int cookieVersion)
Sets the cookie version.


setCookiePort

public void setCookiePort(java.lang.String port)
Sets the cookie ports.


getCookiePort

public java.lang.String getCookiePort()
Gets the cookie ports.


getDebug

public java.util.logging.Logger getDebug()
Returns the debug log


setPersistentStore

public void setPersistentStore(JndiBuilder store)
                        throws javax.naming.NamingException,
                               ConfigException
Sets the persistent store.

Throws:
javax.naming.NamingException
ConfigException

setAlwaysLoadSession

public void setAlwaysLoadSession(boolean load)
True if sessions should always be loadd.


setAlwaysSaveSession

public void setAlwaysSaveSession(boolean save)
True if sessions should always be saved.


isSaveOnShutdown

public boolean isSaveOnShutdown()
True if sessions should be saved on shutdown.


isSaveOnlyOnShutdown

public boolean isSaveOnlyOnShutdown()
True if sessions should only be saved on shutdown.


isSaveBeforeHeaders

public boolean isSaveBeforeHeaders()
True if sessions should be saved before the HTTP headers.


isSaveBeforeFlush

public boolean isSaveBeforeFlush()
True if sessions should be saved before each flush.


isSaveAfterRequest

public boolean isSaveAfterRequest()
True if sessions should be saved after the request.


setSaveMode

public void setSaveMode(java.lang.String mode)
                 throws ConfigException
Sets the save-mode: before-flush, before-headers, after-request, on-shutdown

Throws:
ConfigException

getSaveMode

public java.lang.String getSaveMode()
Returns the string value of the save-mode.


setSaveOnlyOnShutdown

public void setSaveOnlyOnShutdown(boolean save)
True if sessions should only be saved on shutdown.


setSaveOnShutdown

public void setSaveOnShutdown(boolean save)
True if sessions should only be saved on shutdown.


setSerializationType

public void setSerializationType(java.lang.String type)
Sets the serialization type.


isHessianSerialization

public boolean isHessianSerialization()
Returns true for Hessian serialization.


setInvalidateAfterListener

public void setInvalidateAfterListener(boolean inv)
True if the session should be invalidated after the listener.


isInvalidateAfterListener

public boolean isInvalidateAfterListener()
True if the session should be invalidated after the listener.


getActiveSessionCount

public int getActiveSessionCount()
Returns the current number of active sessions.


getSessionActiveCount

public int getSessionActiveCount()
Returns the active sessions.


getSessionCreateCount

public long getSessionCreateCount()
Returns the created sessions.


getSessionTimeoutCount

public long getSessionTimeoutCount()
Returns the timeout sessions.


getSessionInvalidateCount

public long getSessionInvalidateCount()
Returns the invalidate sessions.


addListener

public void addListener(HttpSessionListener listener)
Adds a new HttpSessionListener.


addActivationListener

public void addActivationListener(HttpSessionActivationListener listener)
Adds a new HttpSessionActivationListener.


addAttributeListener

public void addAttributeListener(HttpSessionAttributeListener listener)
Adds a new HttpSessionAttributeListener.


setIgnoreSerializationErrors

public void setIgnoreSerializationErrors(boolean ignore)
True if serialization errors should just fail silently.


getReuseSessionId

public int getReuseSessionId()
True if the server should reuse the current session id if the session doesn't exist.


reuseSessionId

public boolean reuseSessionId(boolean fromCookie)
True if the server should reuse the current session id if the session doesn't exist.


setReuseSessionId

public void setReuseSessionId(java.lang.String reuse)
                       throws ConfigException
True if the server should reuse the current session id if the session doesn't exist.

Throws:
ConfigException

getSrunIndex

public int getSrunIndex()
Returns the index of this JVM in the ring.


getSrunLength

public int getSrunLength()
Returns the number of sruns in the cluster


isClosed

public boolean isClosed()
Returns true if the sessions are closed.


createFileStore

public StoreManager createFileStore()
                             throws ConfigException
Sets the file store.

Throws:
ConfigException

createJdbcStore

public StoreManager createJdbcStore()
                             throws ConfigException
Sets the jdbc store.

Throws:
ConfigException

setTcpStore

public void setTcpStore(boolean isEnable)
                 throws java.lang.Exception
Sets the tcp store.

Throws:
java.lang.Exception

setClusterStore

public void setClusterStore(boolean isEnable)
                     throws java.lang.Exception
Sets the cluster store.

Throws:
java.lang.Exception

setUsePersistentStore

public void setUsePersistentStore(boolean enable)
                           throws java.lang.Exception
Sets the cluster store.

Throws:
java.lang.Exception

setPersistentPath

public void setPersistentPath(Path path)
Returns the session factory.


getDistributionId

public java.lang.String getDistributionId()

setDistributionId

public void setDistributionId(java.lang.String distributionId)

getSessionTimeout

public long getSessionTimeout()
Returns the default session timeout in milliseconds.


setSessionTimeout

public void setSessionTimeout(long timeout)
Set the default session timeout in minutes


getMaxIdleTime

public long getMaxIdleTime()
Returns the idle time.

Specified by:
getMaxIdleTime in interface ObjectManager

getSessionMax

public int getSessionMax()
Returns the maximum number of sessions.


setSessionMax

public void setSessionMax(int max)
Returns the maximum number of sessions.


enableSessionCookies

public boolean enableSessionCookies()
Returns true if sessions use the cookie header.


setEnableCookies

public void setEnableCookies(boolean enableCookies)
Returns true if sessions use the cookie header.


enableSessionUrls

public boolean enableSessionUrls()
Returns true if sessions can use the session rewriting.


setEnableUrlRewriting

public void setEnableUrlRewriting(boolean enableUrls)
Returns true if sessions can use the session rewriting.


getCookieName

public java.lang.String getCookieName()
Returns the default cookie name.


getSSLCookieName

public java.lang.String getSSLCookieName()
Returns the SSL cookie name.


getCookieDomain

public java.lang.String getCookieDomain()
Returns the default session cookie domain.


setCookieDomain

public void setCookieDomain(java.lang.String domain)
Sets the default session cookie domain.


getCookieMaxAge

public long getCookieMaxAge()
Returns the max-age of the session cookie.


setCookieMaxAge

public void setCookieMaxAge(Period maxAge)
Sets the max-age of the session cookie.


getCookieSecure

public boolean getCookieSecure()
Returns the secure of the session cookie.


setCookieSecure

public void setCookieSecure(boolean secure)
Sets the secure of the session cookie.


isCookieHttpOnly

public boolean isCookieHttpOnly()
Returns the http-only of the session cookie.


setCookieHttpOnly

public void setCookieHttpOnly(boolean httpOnly)
Sets the http-only of the session cookie.


setCookieLength

public void setCookieLength(int cookieLength)
Sets the cookie length


getCookieLength

public long getCookieLength()
Returns the cookie length.


setCookieModuloCluster

public void setCookieModuloCluster(boolean isModulo)
Sets module session id generation.


setCookieAppendServerIndex

public void setCookieAppendServerIndex(boolean isAppend)
Sets module session id generation.


isCookieAppendServerIndex

public boolean isCookieAppendServerIndex()
Sets module session id generation.


init

public void init()

start

public void start()
           throws java.lang.Exception
Throws:
java.lang.Exception

getSessionStore

public Store getSessionStore()
Returns the session store.


containsSession

public boolean containsSession(java.lang.String id)
Returns true if the session exists in this manager.


createSession

public SessionImpl createSession(java.lang.String oldId,
                                 long now,
                                 HttpServletRequest request,
                                 boolean fromCookie)
Create a new session.

Parameters:
oldId - the id passed to the request. Reuse if possible.
now - the current date
sessionGroup - the srun index for this machine

createSessionId

public java.lang.String createSessionId(HttpServletRequest request)
Creates a pseudo-random session id. If there's an old id and the group matches, then use it because different webApps on the same matchine should use the same cookie.

Parameters:
sessionGroup - possibly assigned by the web server

createSessionId

public java.lang.String createSessionId(HttpServletRequest request,
                                        boolean create)
Creates a pseudo-random session id. If there's an old id and the group matches, then use it because different webApps on the same machine should use the same cookie.

Parameters:
sessionGroup - possibly assigned by the web server

createSessionIdImpl

public java.lang.String createSessionIdImpl(HttpServletRequest request)

getSession

public SessionImpl getSession(java.lang.String key,
                              long now,
                              boolean create,
                              boolean fromCookie)
Returns a session from the session store, returning null if there's no cached session.

Parameters:
key - the session id
now - the time in milliseconds
Returns:
the cached session.

isInSessionGroup

public boolean isInSessionGroup(java.lang.String id)

notifyRemove

public void notifyRemove(java.lang.String id)
Notification from the cluster.

Specified by:
notifyRemove in interface ObjectManager

notifyUpdate

public void notifyUpdate(java.lang.String id)
Notification from the cluster.

Specified by:
notifyUpdate in interface ObjectManager

decode

public static int decode(int code)

invalidateSession

public void invalidateSession(SessionImpl session)
Invalidates a session from the cache.


removeSession

public void removeSession(SessionImpl session)
Removes a session from the cache.


load

public void load(java.io.InputStream is,
                 java.lang.Object obj)
          throws java.io.IOException
Loads the session.

Specified by:
load in interface ObjectManager
Parameters:
in - the input stream containing the serialized session
obj - the session object to be deserialized
Throws:
java.io.IOException

isEmpty

public boolean isEmpty(java.lang.Object obj)
Checks if the session is empty.

Specified by:
isEmpty in interface ObjectManager

store

public void store(java.io.OutputStream os,
                  java.lang.Object obj)
           throws java.io.IOException
Saves the session.

Specified by:
store in interface ObjectManager
Throws:
java.io.IOException

handleAlarm

public void handleAlarm(Alarm alarm)
Timeout for reaping old sessions

Specified by:
handleAlarm in interface AlarmListener

close

public void close()
Cleans up the sessions when the WebApp shuts down gracefully.


toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object