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.

Version:
$Revision: 1.56 $ $Date: 2000/04/19 21:59:20 $

Inner Class Summary
(package private)  class JServServletManager.ACLObjectInputStream
          When deserializing the sessions during a class loader reload, override the resolveClass() method so that it uses the AdaptiveClassLoader to deserialize the sessions.
 
Field Summary
(package private)  boolean checkClasses
          Determines whether to check the classes for changes.
(package private)  boolean checkFile
          Determines wheter to check the property file for changes.
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.
(package private)  long destroyTimeout
          The amount of time to wait before giving up on lock when destroying servlet.
(package private)  long initTimeout
          The amount of time to wait before giving up on lock when initializing a servlet.
protected  long lastInitialization
          The time of the last initialization.
private static long lastTimeVal
           
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.
private static int NAME
           
(package private)  long newSessionTimeout
          The amount of time to wait before invalidating a new session that has never been "used" by the client.
private static java.util.Random randomSource
           
private  java.util.Hashtable servletContexts
          The cache of loaded servlets
protected  java.util.Vector servletNames
          The names of all the named servlet.
private static int session_count
           
protected  java.lang.String session_identifier
          A (slightly more) unique session identifier derived from SESSION_IDENTIFIER_BASE and name.
(package private) static java.lang.String SESSION_IDENTIFIER_BASE
          The name of the session parameter.
(package private)  long sessionCheckFrequency
          How frequently to check for the existence of timed-out sessions.
protected  java.util.Hashtable sessions
          The sessions in this manager.
(package private)  long sessionTimeout
          The amount of time to wait before invalidating an unused session.
(package private)  boolean sessionUseCookies
          This flag determines how sessions are created.
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
           
private static int VALUE
           
 
Constructor Summary
(package private) JServServletManager(java.lang.String name, java.lang.String confFile)
          Creates a new servlet manager.
 
Method Summary
 void checkReload(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.
private static java.lang.String getIdentifier()
           
private  java.lang.String getIdentifier(java.lang.String jsIdent)
           
 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(JServSendError errorHandler)
          Load the configuration from the property file and load the startup servlets.
protected  JServContext load_init(java.lang.String name, JServSendError se)
           
 JServContext loadServlet(java.lang.String name, JServSendError se)
          Loads and initialize a servlet.
private  void loadStartupServlets(JServSendError se)
          Loads and initialize all the startup servlets.
 void removeSession(JServSession s)
          Remove a session from the context.
(package private)  void returnSTMS(java.lang.String servletname, JServContext context)
          Return a context into a set of SingleThredModel servlets.
 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, registerNatives, toString, wait, wait, wait
 

Field Detail

NAME

private static final int NAME

VALUE

private static final int VALUE

SESSION_IDENTIFIER_BASE

static final java.lang.String SESSION_IDENTIFIER_BASE
The name of the session parameter.

initTimeout

long initTimeout
The amount of time to wait before giving up on lock when initializing a servlet. This is taken from the property init.timeout and defaults to 10000 (10 seconds).

destroyTimeout

long destroyTimeout
The amount of time to wait before giving up on lock when destroying servlet. This is taken from the property destroy.timeout and defaults to 10000 (10 seconds).

sessionTimeout

long sessionTimeout
The amount of time to wait before invalidating an unused session. This is taken from the property session.timeout and defaults to 1800000 (30 minutes)

newSessionTimeout

long newSessionTimeout
The amount of time to wait before invalidating a new session that has never been "used" by the client. Setting this lower than sessionTimeout can help avoid an attack based on filling available memory with new sessions. This is taken from the property session.newtimeout and defaults to 1800000 (30 minutes)

sessionCheckFrequency

long sessionCheckFrequency
How frequently to check for the existence of timed-out sessions. This is taken from the property session.checkFrequency and defaults to 5000 (5 seconds)

checkFile

boolean checkFile
Determines wheter to check the property file for changes.

checkClasses

boolean checkClasses
Determines whether to check the classes for changes.

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

servletContexts

private java.util.Hashtable servletContexts
The cache of loaded 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.

sessionUseCookies

boolean sessionUseCookies
This flag determines how sessions are created. By default, cookies are used if possible, else URL-rewriting will be used. By setting this flag to false (session.useCookies=false) you can force Apache JServ to use URL-rewriting only. Default value : true

session_count

private static int session_count

lastTimeVal

private static long lastTimeVal

randomSource

private static java.util.Random randomSource

maxRandomLen

public static final long maxRandomLen

maxSessionLifespanTics

public static final long maxSessionLifespanTics

ticDifference

public static final long ticDifference
Constructor Detail

JServServletManager

JServServletManager(java.lang.String name,
                    java.lang.String confFile)
Creates a new servlet manager.
Parameters:
name - The name of this ServletManager.
propFile - The name of the property file to use.
Method Detail

init

public void init(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(JServSendError errorHandler)
                 throws java.lang.Exception
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 JServContext loadServlet(java.lang.String name,
                                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 JServContext load_init(java.lang.String name,
                                 JServSendError se)
                          throws javax.servlet.ServletException

loadStartupServlets

private void loadStartupServlets(JServSendError se)
Loads and initialize all the startup servlets.
Parameters:
se - The sendError handler to call back in case of error.

getName

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

returnSTMS

void returnSTMS(java.lang.String servletname,
                JServContext context)
Return a context into a set of SingleThredModel servlets.

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.

getIdentifier

private static java.lang.String getIdentifier()

getIdentifier

private java.lang.String getIdentifier(java.lang.String jsIdent)

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