com.caucho.quercus.lib.session
Class QuercusSessionManager

java.lang.Object
  extended by com.caucho.quercus.lib.session.QuercusSessionManager
All Implemented Interfaces:
AlarmListener, java.util.EventListener
Direct Known Subclasses:
ProSessionManager

public class QuercusSessionManager
extends java.lang.Object
implements AlarmListener

Stripped down version of com.caucho.server.session.SessionManager, customized to PHP instead of J2EE sessions.


Field Summary
protected  boolean _isClosed
           
protected  long _sessionCreateCount
           
protected  java.util.Iterator<SessionArrayValue> _sessionIter
           
protected  java.util.ArrayList<SessionArrayValue> _sessionList
           
protected  int _sessionMax
           
protected  LruCache<java.lang.String,SessionArrayValue> _sessions
           
protected  long _sessionTimeoutCount
           
protected  java.lang.Object _statisticsLock
           
 
Constructor Summary
QuercusSessionManager(QuercusContext quercus)
          Creates and initializes a new session manager.
 
Method Summary
 void close()
          Cleans up the sessions when the Application shuts down gracefully.
protected  SessionArrayValue create(Env env, java.lang.String key, long now)
          Creates a session.
 SessionArrayValue createSession(Env env, java.lang.String oldId, long now)
          Create a new session.
 java.lang.String createSessionId(Env env)
          Creates a pseudo-random session id.
protected  SessionArrayValue createSessionValue(java.lang.String key, long now, long sessionTimeout)
          Creates a new SessionArrayValue instance.
 int getActiveSessionCount()
          Returns the current number of active sessions.
 int getReuseSessionId()
          True if the server should reuse the current session id if the session doesn't exist.
 boolean getSaveOnlyOnShutdown()
          True if sessions should only be saved on shutdown.
 SessionArrayValue getSession(Env env, java.lang.String key, long now)
          Returns a session from the session store, returning null if there's no cached session.
 long getSessionCreateCount()
          Returns the created sessions.
 int getSessionMax()
          Returns the maximum number of sessions.
 long getSessionTimeoutCount()
          Returns the timeout sessions.
 void handleAlarm(Alarm alarm)
          Timeout for reaping old sessions.
 boolean isClosed()
          Returns true if the sessions are closed.
 boolean isEmpty(java.lang.Object obj)
          Checks if the session is empty.
protected  boolean load(Env env, SessionArrayValue session, long now)
          Loads the session from the backing store.
 void load(java.io.ObjectInputStream in, 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.
protected  void remove(java.lang.String sessionId)
           
 void removeSession(java.lang.String sessionId)
          Removes a session from the cache and deletes it from the backing store, if applicable.
 void saveSession(Env env, SessionArrayValue session)
           
 void setAlwaysLoadSession(boolean load)
          True if sessions should always be loadd.
 void setAlwaysSaveSession(boolean save)
          True if sessions should always be saved.
 void setCookieAppendServerIndex(boolean isAppend)
          Sets module session id generation.
 void setCookieLength(int cookieLength)
          Sets the cookie length
 void setReuseSessionId(java.lang.String reuse)
          True if the server should reuse the current session id if the session doesn't exist.
 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 setSessionMax(int max)
          Returns the maximum number of sessions.
protected  void setSessionTimeout(long sessionTimeout)
           
 void store(java.io.OutputStream out, java.lang.Object obj)
          Saves the session.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_sessions

protected LruCache<java.lang.String,SessionArrayValue> _sessions

_sessionIter

protected java.util.Iterator<SessionArrayValue> _sessionIter

_sessionList

protected java.util.ArrayList<SessionArrayValue> _sessionList

_sessionMax

protected int _sessionMax

_isClosed

protected boolean _isClosed

_statisticsLock

protected java.lang.Object _statisticsLock

_sessionCreateCount

protected long _sessionCreateCount

_sessionTimeoutCount

protected long _sessionTimeoutCount
Constructor Detail

QuercusSessionManager

public QuercusSessionManager(QuercusContext quercus)
Creates and initializes a new session manager.

Method Detail

setAlwaysSaveSession

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


setAlwaysLoadSession

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


getSaveOnlyOnShutdown

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


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.


setCookieLength

public void setCookieLength(int cookieLength)
Sets the cookie length


setSessionTimeout

protected void setSessionTimeout(long sessionTimeout)

getActiveSessionCount

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


getSessionCreateCount

public long getSessionCreateCount()
Returns the created sessions.


getSessionTimeoutCount

public long getSessionTimeoutCount()
Returns the timeout sessions.


getReuseSessionId

public int getReuseSessionId()
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.


getSessionMax

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


setSessionMax

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


removeSession

public void removeSession(java.lang.String sessionId)
Removes a session from the cache and deletes it from the backing store, if applicable.


remove

protected void remove(java.lang.String sessionId)

load

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

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.


setCookieAppendServerIndex

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


createSession

public SessionArrayValue createSession(Env env,
                                       java.lang.String oldId,
                                       long now)
Create a new session.

Parameters:
oldId - the id passed to the request. Reuse if possible.
now - the current date

createSessionId

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


getSession

public SessionArrayValue getSession(Env env,
                                    java.lang.String key,
                                    long now)
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. now == 0 implies that we're just checking for the existence of such a session in the cache and do not intend actually to load it if it is not.
Returns:
the cached session.

saveSession

public void saveSession(Env env,
                        SessionArrayValue session)

create

protected SessionArrayValue create(Env env,
                                   java.lang.String key,
                                   long now)
Creates a session. It's already been established that the key does not currently have a session.


createSessionValue

protected SessionArrayValue createSessionValue(java.lang.String key,
                                               long now,
                                               long sessionTimeout)
Creates a new SessionArrayValue instance.


load

protected boolean load(Env env,
                       SessionArrayValue session,
                       long now)
Loads the session from the backing store.

Parameters:
session - the session to load.
now - current time in milliseconds. now == 0 implies that we're just checking for the existence of such a session in the cache and do not intend actually to load it if it is not.

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 Application shuts down gracefully.


notifyRemove

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


notifyUpdate

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


store

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

Throws:
java.io.IOException