org.apache.jserv
Class JServServletManager

java.lang.Object
  |
  +--org.apache.jserv.JServServletManager

public class JServServletManager
extends java.lang.Object
implements javax.servlet.http.HttpSessionContext, java.lang.Runnable, JServLogChannels

Class that encapsulates the loading and managing of servlets per servlet zone.

Note about synchronization :

All the method that modifies the servlet table are synchronized on the JServServletManager. Since this table is private there no needs to synchronized on it anymore.


Field Summary
protected  java.io.File confFile
          The file that contains the servlet properties.
protected  Configurations confs
          The configurations containing information for these servlets.
protected  java.util.Properties defaultArgs
          The default init arguments for all the servlets in this name space.
protected  long lastInitialization
          The time of the last initialization.
protected  AdaptiveClassLoader loader
          The class loader used for loading new servlets
static long maxRandomLen
           
static long maxSessionLifespanTics
           
protected  java.lang.String name
          The name of this ServletManager.
protected  java.util.Vector servletNames
          The names of all the named servlet.
protected  java.lang.String session_identifier
          A (slightly more) unique session identifier derived from SESSION_IDENTIFIER_BASE and name.
protected  java.util.Hashtable sessions
          The sessions in this manager.
protected  java.lang.String[] startups
          The servlets to load on startup.
protected  java.lang.ThreadGroup tGroup
          The ThreadGroup in which the servlets are run.
static long ticDifference
           
 
Fields inherited from interface org.apache.jserv.JServLogChannels
CH_CONTAINER_EXCEPTION, CH_CRITICAL, CH_DEBUG, CH_INFO, CH_SERVLET_EXCEPTION, CH_SERVLET_LOG, CH_WARNING
 
Method Summary
 void checkReload(org.apache.jserv.JServSendError errorHandler)
          Reinstantiate the classloader if necessary.
 JServSession createSession(javax.servlet.http.HttpServletResponse response)
          Creates a new session.
 JServSession createSession(javax.servlet.http.HttpServletResponse response, java.lang.String route)
          Creates a new session.
 void destroyServlet(java.lang.String servletName)
          Destroy one servlet or a set of SingleThreadModel servlets.
 void destroyServlets()
          Destroy all the servlets and servlet contexts.
 java.lang.String encodeUrl(java.lang.String url, java.lang.String id)
          Encode a URL with a session identifier.
 java.lang.String getCookieSessionId(javax.servlet.http.Cookie[] cookies)
          Get the session identifier set in cookies.
 java.util.Enumeration getIds()
          Returns an enumeration of all of the session IDs in this context.
 java.util.Enumeration getLoadedServlets()
          Get an enumeration of all the servlets that have been loaded.
 java.lang.String getName()
          Get the name of this ServletManager.
 java.util.Enumeration getServletNames()
          Get all the name that are defined in this ServletManager
 javax.servlet.http.HttpSession getSession(java.lang.String sessionId)
          Returns the session bound to the specified session ID.
 java.lang.String getUrlSessionId(java.lang.String queryStr)
          Get the session identifier in a query string.
 void init(org.apache.jserv.JServSendError errorHandler)
          Load the configuration from the property file and load the startup servlets.
protected  org.apache.jserv.JServContext load_init(java.lang.String name, org.apache.jserv.JServSendError se)
           
 org.apache.jserv.JServContext loadServlet(java.lang.String name, org.apache.jserv.JServSendError se)
          Loads and initialize a servlet.
 void removeSession(JServSession s)
          Remove a session from the context.
 void run()
          The housekeeping thread Checks for sessions that have not been used for a certain amount of time and invalidates them.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

confFile

protected java.io.File confFile
The file that contains the servlet properties.

lastInitialization

protected long lastInitialization
The time of the last initialization.

confs

protected Configurations confs
The configurations containing information for these servlets.

defaultArgs

protected java.util.Properties defaultArgs
The default init arguments for all the servlets in this name space.

loader

protected AdaptiveClassLoader loader
The class loader used for loading new servlets

tGroup

protected java.lang.ThreadGroup tGroup
The ThreadGroup in which the servlets are run.

session_identifier

protected java.lang.String session_identifier
A (slightly more) unique session identifier derived from SESSION_IDENTIFIER_BASE and name.

name

protected java.lang.String name
The name of this ServletManager.

startups

protected java.lang.String[] startups
The servlets to load on startup.

servletNames

protected java.util.Vector servletNames
The names of all the named servlet.

sessions

protected java.util.Hashtable sessions
The sessions in this manager.

maxRandomLen

public static final long maxRandomLen

maxSessionLifespanTics

public static final long maxSessionLifespanTics

ticDifference

public static final long ticDifference
Method Detail

init

public void init(org.apache.jserv.JServSendError errorHandler)
Load the configuration from the property file and load the startup servlets.
Parameters:
JServSendError - An object that can handle errors.

checkReload

public void checkReload(org.apache.jserv.JServSendError errorHandler)
Reinstantiate the classloader if necessary. Check if any of the classes has changed or if the property file has been modified. If this is the case, this method does the following :
  1. Destroy all the loaded servlets.
  2. Re-read its configuration file.
  3. Reload the startup servlets.
Parameters:
errorHandler - The object that knows what to do with errors.

getServletNames

public java.util.Enumeration getServletNames()
Get all the name that are defined in this ServletManager

getLoadedServlets

public java.util.Enumeration getLoadedServlets()
Get an enumeration of all the servlets that have been loaded.

loadServlet

public org.apache.jserv.JServContext loadServlet(java.lang.String name,
                                                 org.apache.jserv.JServSendError se)
                                          throws javax.servlet.ServletException
Loads and initialize a servlet. If the servlet is already loaded and initialized, a reference to the existing context is returned.
Parameters:
servletName - The name of the servlet to load.
errorHandler - The error handler to call back if there is an error.
Returns:
the ServletContext object for the servlet.
Throws:
javax.servlet.ServletException - If there is an error while initializing the servlet.

load_init

protected org.apache.jserv.JServContext load_init(java.lang.String name,
                                                  org.apache.jserv.JServSendError se)
                                           throws javax.servlet.ServletException

getName

public java.lang.String getName()
Get the name of this ServletManager.

destroyServlet

public void destroyServlet(java.lang.String servletName)
Destroy one servlet or a set of SingleThreadModel servlets.
Parameters:
servletName - the name of the servlet

destroyServlets

public void destroyServlets()
Destroy all the servlets and servlet contexts.

getUrlSessionId

public final java.lang.String getUrlSessionId(java.lang.String queryStr)
Get the session identifier in a query string.
Parameters:
queryStr - The query string that came in from the url.
Returns:
The session identifier encoded in the url, or null if there is no session identifier in the url.

getCookieSessionId

public final java.lang.String getCookieSessionId(javax.servlet.http.Cookie[] cookies)
Get the session identifier set in cookies.
Parameters:
cookies - The cookies to search for a session identifier.
Returns:
The session identifier found in the cookies, or null if there is none.

encodeUrl

public java.lang.String encodeUrl(java.lang.String url,
                                  java.lang.String id)
Encode a URL with a session identifier.
Parameters:
url - The url to encode.
id - The session identifier to encode with the url.

getSession

public javax.servlet.http.HttpSession getSession(java.lang.String sessionId)
Returns the session bound to the specified session ID.
Specified by:
getSession in interface javax.servlet.http.HttpSessionContext
Parameters:
sessionID - the ID of a particular session object.
Returns:
the session name. Returns null if the session ID does not refer to a valid session.

getIds

public java.util.Enumeration getIds()
Returns an enumeration of all of the session IDs in this context.
Specified by:
getIds in interface javax.servlet.http.HttpSessionContext
Returns:
an enumeration of all session IDs in this context.

createSession

public JServSession createSession(javax.servlet.http.HttpServletResponse response)
Creates a new session.
Parameters:
response - The response used to send a cookie to the client.
Returns:
A new session.

createSession

public JServSession createSession(javax.servlet.http.HttpServletResponse response,
                                  java.lang.String route)
Creates a new session.
Parameters:
response - The response used to send a cookie to the client.
route - Label to append to the id sent from jserv client.
Returns:
A new session.

removeSession

public void removeSession(JServSession s)
Remove a session from the context. This is called by the session when it is invalidated.
Parameters:
s - The session to remove from this context.

run

public void run()
The housekeeping thread Checks for sessions that have not been used for a certain amount of time and invalidates them.
Specified by:
run in interface java.lang.Runnable