com.caucho.server.session
Class SessionManager

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

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

Manages sessions in a web-webApp.


Field Summary
protected static L10N L
           
protected static java.util.logging.Logger log
           
 
Constructor Summary
SessionManager(WebApp webApp)
          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.
 java.lang.String createCookieValue()
           
protected  java.lang.String createCookieValue(java.lang.Object owner)
           
 SessionImpl createSession(boolean isCreate, HttpServletRequest request, java.lang.String sessionId, long now, boolean fromCookie)
          Finds a session in the session store, creating one if 'create' is true
 SessionImpl createSession(java.lang.String oldId, long now, HttpServletRequest request, boolean fromCookie)
          Create a new session.
 SessionDeserializer createSessionDeserializer(java.io.InputStream is)
           
 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)
           
 SessionSerializer createSessionSerializer(java.io.OutputStream os)
           
 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.
 java.lang.String getComment()
           
 java.lang.String getCookieDomain()
          Returns the default session cookie domain.
 java.lang.String getCookieDomainRegexp()
           
 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.
 int getCookieVersion()
          Returns the cookie version.
 java.util.logging.Logger getDebug()
          Returns the debug log
 java.lang.String getDistributionId()
           
 java.lang.String getDomain()
           
 int getMaxAge()
           
 long getMaxIdleTime()
          Returns the idle time.
 java.lang.String getName()
           
 java.lang.String getPath()
           
 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)
           
 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..
 java.lang.String getSessionSerializationDebug(java.lang.String id)
          Returns a debug string for the session
 ByteStreamCache getSessionStore()
          Returns the session store.
 long getSessionTimeout()
          Returns the default session timeout in milliseconds.
 long getSessionTimeoutCount()
          Returns the timeout sessions.
 java.lang.String getSSLCookieName()
          Returns the SSL cookie name.
 void handleAlarm(Alarm alarm)
          Timeout for reaping old sessions
 void init()
           
 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 isCookieSecure()
          Returns the secure of the session cookie.
 boolean isDestroyOnLru()
           
 boolean isHessianSerialization()
          Returns true for Hessian serialization.
 boolean isHttpOnly()
           
 boolean isInvalidateAfterListener()
          True if the session should be invalidated after the listener.
 boolean isOwner(java.lang.String id)
           
 boolean isPersistenceEnabled()
           
 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.
 boolean isSecure()
           
 boolean isUsePersistentStore()
           
 void notifyRemove(java.lang.String id)
          Notification from the cluster.
 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 setComment(java.lang.String comment)
           
 void setCookieAppendServerIndex(boolean isAppend)
          Sets module session id generation.
 void setCookieDomain(java.lang.String domain)
          Sets the default session cookie domain.
 void setCookieDomainRegexp(java.lang.String regexp)
           
 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 setCookieName(java.lang.String cookieName)
           
 void setCookiePath(java.lang.String path)
          Sets the default session cookie domain.
 void setCookiePort(java.lang.String port)
          Sets the cookie ports.
 void setCookieSecure(boolean isSecure)
          Sets the secure of the session cookie.
 void setCookieUseContextPath(boolean isCookieUseContextPath)
          Sets the cookie ports.
 void setCookieVersion(int cookieVersion)
          Sets the cookie version.
 void setDestroyOnLru(boolean isDestroy)
           
 void setDistributionId(java.lang.String distributionId)
           
 void setDomain(java.lang.String domain)
           
 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 setHttpOnly(boolean httpOnly)
           
 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 setMaxAge(int maxAge)
           
 void setName(java.lang.String name)
           
 void setPath(java.lang.String path)
           
 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 setSecure(boolean secure)
           
 void setSerializationType(java.lang.String type)
          Sets the serialization type.
 void setSerializeCollectionType(boolean isEnable)
           
 void setSessionMax(int max)
          Returns the maximum number of sessions.
 void setSessionTimeout(long timeout)
          Set the default session timeout in minutes
 void setUsePersistentStore(boolean enable)
          Sets the cluster store.
 void start()
           
 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 webApp)
               throws java.lang.Exception
Creates and initializes a new session manager

Parameters:
webApp - the web-webApp webApp
Throws:
java.lang.Exception
Method Detail

getAdmin

public SessionManagerMXBean getAdmin()
Returns the admin.


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.


setCookieUseContextPath

public void setCookieUseContextPath(boolean isCookieUseContextPath)
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


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.


setSerializeCollectionType

public void setSerializeCollectionType(boolean isEnable)

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

isClosed

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


setUsePersistentStore

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

Throws:
java.lang.Exception

isUsePersistentStore

public boolean isUsePersistentStore()

isPersistenceEnabled

public boolean isPersistenceEnabled()

setDestroyOnLru

public void setDestroyOnLru(boolean isDestroy)

isDestroyOnLru

public boolean isDestroyOnLru()

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.


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.


setName

public void setName(java.lang.String name)
Specified by:
setName in interface SessionCookieConfig

getName

public java.lang.String getName()
Specified by:
getName in interface SessionCookieConfig

setDomain

public void setDomain(java.lang.String domain)
Specified by:
setDomain in interface SessionCookieConfig

getDomain

public java.lang.String getDomain()
Specified by:
getDomain in interface SessionCookieConfig

setPath

public void setPath(java.lang.String path)
Specified by:
setPath in interface SessionCookieConfig

getPath

public java.lang.String getPath()
Specified by:
getPath in interface SessionCookieConfig

setComment

public void setComment(java.lang.String comment)
Specified by:
setComment in interface SessionCookieConfig

getComment

public java.lang.String getComment()
Specified by:
getComment in interface SessionCookieConfig

setHttpOnly

public void setHttpOnly(boolean httpOnly)
Specified by:
setHttpOnly in interface SessionCookieConfig

isHttpOnly

public boolean isHttpOnly()
Specified by:
isHttpOnly in interface SessionCookieConfig

setSecure

public void setSecure(boolean secure)
Specified by:
setSecure in interface SessionCookieConfig

isSecure

public boolean isSecure()
Specified by:
isSecure in interface SessionCookieConfig

setMaxAge

public void setMaxAge(int maxAge)
Specified by:
setMaxAge in interface SessionCookieConfig

getMaxAge

public int getMaxAge()
Specified by:
getMaxAge in interface SessionCookieConfig

setCookieName

public void setCookieName(java.lang.String cookieName)

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.


getCookieDomainRegexp

public java.lang.String getCookieDomainRegexp()

setCookieDomainRegexp

public void setCookieDomainRegexp(java.lang.String regexp)

setCookiePath

public void setCookiePath(java.lang.String path)
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.


isCookieSecure

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


setCookieSecure

public void setCookieSecure(boolean isSecure)
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 ByteStreamCache getSessionStore()
Returns the session store.


createSessionSerializer

public SessionSerializer createSessionSerializer(java.io.OutputStream os)
                                          throws java.io.IOException
Throws:
java.io.IOException

createSessionDeserializer

public SessionDeserializer createSessionDeserializer(java.io.InputStream is)
                                              throws java.io.IOException
Throws:
java.io.IOException

containsSession

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


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:
request - current request

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:
request - current request

createCookieValue

public java.lang.String createCookieValue()

createSessionIdImpl

public java.lang.String createSessionIdImpl(HttpServletRequest request)

isOwner

public boolean isOwner(java.lang.String id)

createCookieValue

protected java.lang.String createCookieValue(java.lang.Object owner)

createSession

public SessionImpl createSession(boolean isCreate,
                                 HttpServletRequest request,
                                 java.lang.String sessionId,
                                 long now,
                                 boolean fromCookie)
Finds a session in the session store, creating one if 'create' is true

Parameters:
isCreate - if the session doesn't exist, create it
request - current request
now - the time in milliseconds
fromCookie - true if the session id comes from a cookie
Returns:
the cached session.

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.

getSession

public SessionImpl getSession(java.lang.String key)

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.
request - - current HttpServletRequest
fromCookie -

notifyRemove

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


getSessionSerializationDebug

public java.lang.String getSessionSerializationDebug(java.lang.String id)
Returns a debug string for the session


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