Enhydra 5.1 API

org.enhydra.servlet.servletManager
Class ServletManager

java.lang.Object
  |
  +--org.enhydra.servlet.servletManager.ServletManager
All Implemented Interfaces:
java.lang.Runnable

public class ServletManager
extends java.lang.Object
implements java.lang.Runnable

This class loads Servlet classes, creates instances of Servlets, caches the Servlets, and returns pointers to them. The Servlets are refered to by an identifer string (a symbolic name).

First Servlets are registered via add(). Then they are started via start(). Then they are available for use via get().

The ServletManager will call init() on the Servlet. It will also call destoroy(). Other classes which use Servlets returned by get() must not call these two methods. When get() returns a Servlet, it is ready to accept service() calls.

Author:
Andy John
See Also:
Servlet, ServletStatus

Field Summary
protected static org.apache.log4j.Logger loggerSys
          The logger that logs on System.out.
static java.lang.String SESSION_MANAGER_KEY
          Attribute key to store session manager in context.
 
Constructor Summary
ServletManager()
          Create a new ServletManager, initially containing no Servlets.
 
Method Summary
 void add(java.lang.String servletID, java.lang.String className, java.lang.String[] classPath, java.lang.String docRoot, java.util.Properties initArgs, boolean runOnInit, java.lang.String description, boolean isWar)
          Register a new Servlet with the ServletManager.
 void addFilter(java.lang.String servletID, java.lang.String filterID)
          Adds the given filter to the list of filters to be applied to the given servlet when the Context is built.
 void delete(java.lang.String servletID)
          Unregister a Servlet from the ServletManager.
 void destroy()
          Shut down the ServletManager.
 javax.servlet.Servlet get(java.lang.String servletID)
          Fetch a Servlet.
 javax.servlet.Servlet get(java.lang.String servletID, boolean counter)
          Fetch a Servlet, with optional control over the counter.
 org.apache.tomcat.core.Context getContextByServletID(java.lang.String id)
          Return the Context for the given servlet id.
protected  java.lang.String getMimeType(java.lang.String file)
          This is for internal use only.
 java.lang.String getServerInfoString()
          Get server info string to pass to the contexts
 java.lang.String[] getServletIDs()
          Get the names of all the Servlets in the ServletManager.
 java.util.Enumeration getServletNames()
          Get the names of all the Servlets in the ServletManager.
 ServletStatistics getStatistics(java.lang.String servletID)
          Get the current request-per-minute statistics of a Servlet.
 ServletStatus getStatus(java.lang.String servletID)
          Get the current status of a Servlet.
 org.apache.tomcat.core.Context lookuptContextByPath(java.lang.String path)
           
 void recordContextPath(java.lang.String servletID, java.lang.String urlPrefix)
          Record the url prefix that will be used by the context The url path for the context is set when the channel is defined.
 void recordSessionConfig(java.lang.String servletID, Config sessionConfig)
          The context may have configuration information relating to the sessionManager
 void recordWarOnlySettings(java.lang.String servletID, java.lang.String defaultSessionTimeout, java.lang.String isWARExpanded, java.lang.String isWARValidated, java.lang.String isInvokerEnabled, java.lang.String isWorkDirPersistent)
          These are values that only apply to a WAR
 void removeContextPath(java.lang.String servletID, java.lang.String urlPrefix)
          A channel has been closed remove the context.
 void removeFilter(java.lang.String servletID, java.lang.String filterID)
           
 void resetRefCount(java.lang.String servletID)
          Reset the reference count for a particular Servlet.
 void resetStats(java.lang.String servletID)
          Resets the maxmimum requests per minute to the current value, and the time of the maximum to now.
 void run()
          This function is for internal use only.
 void service(Channel channel, org.apache.tomcat.core.Request rrequest, org.apache.tomcat.core.Response rresponse)
          Service the request.
 void setWorkDir(java.lang.String workDir)
           
 void start(java.lang.String servletID)
          Force the instantiation of a Servlet.
 void startAllContexts()
          After all the configuration information has been collected it's safe to start all contexts that have been marked as runOnInit in the multiserver configuration file
 void stop(java.lang.String servletID)
          Stop a Servlet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SESSION_MANAGER_KEY

public static final java.lang.String SESSION_MANAGER_KEY
Attribute key to store session manager in context.

See Also:
Constant Field Values

loggerSys

protected static org.apache.log4j.Logger loggerSys
The logger that logs on System.out.

Constructor Detail

ServletManager

public ServletManager()
Create a new ServletManager, initially containing no Servlets.

Method Detail

setWorkDir

public void setWorkDir(java.lang.String workDir)

destroy

public void destroy()
Shut down the ServletManager. This stops all the Servlets, then deletes all the Servlets, then kills the statistics gathering thread. There is no way to restart the thread.


run

public void run()
This function is for internal use only. Do not call this method. When the request per minute monitoring thread starts, this is the code it starts executing. The thread sleeps, waking up once a minute to compute the current request per minute stats, and the maximum request per minute stats.

Specified by:
run in interface java.lang.Runnable

add

public void add(java.lang.String servletID,
                java.lang.String className,
                java.lang.String[] classPath,
                java.lang.String docRoot,
                java.util.Properties initArgs,
                boolean runOnInit,
                java.lang.String description,
                boolean isWar)
         throws javax.servlet.ServletException
Register a new Servlet with the ServletManager. You pass in everything needed to find and create the Servlet, but it is not created until start() is called on it. Requests for the Servlet inbetween the time it is added and started will return null. After this call, the name passed in as servletID should be used to refer to the Servlet.

Each element of classPath specifies a source of classes, either a .jar file, a .zip file, or a directory tree. Each of these sources has a set of class masks associated with it, initially null. If a source's set of class masks is null (the normal condition), then classes are loaded normally. If the set is not null, then it contains a set of class masks. Each class mask is a string. Before a source is searched to see if it contains a given class, the name of the class is compared with the class masks. Only if the requested class name begins with one of the class masks will it be loaded from the source. This lets you specify, for example, a jar file, but limit access to a specific class, or a set of classes that start with a common string. The syntax for specifing class masks is (on Unix): pathname:mask,mask,...,mask. If no masks are specified (the normal usage), then any class found via the pathname is used. Be sure to use java.io.File.pathSeparatorChar between the pathname and the mask list (this will be : on Unix, and ; on Windows and Macintosh). If the class mask does not specifiy a full class name, you may want to end it with a period. For example, if your mask was com.lutris it would allow access to com.lutris.TheClass as well as com.lutrisMisc.UnwatedClass. If the mask was com.lutris. the class UnwantedClass would not be loaded from this source.

Parameters:
servletID - The identifier string used to refer to this Servlet.
className - The name of the class to instantiate. It must implement the Servlet interface.
classPath - An array of directories, .zip files or .jar files. The Servlet will be loaded by it's own class loader, which will look in these locations first. If a class is not found, the system class loader will be used (which uses the CLASSPATH Java started the MultiServer with).
docRoot - The root of the Servlet's filesystem on disk?
initArgs - The initial arguments to the Servlet. These will be made available to the Servlet's init() method. These names and values are accessed via the ServletConfig object passed to the Servlet's init() method.
description - A human readable description of this Servlet.
Throws:
javax.servlet.ServletException - If there is an error.
See Also:
Servlet

recordContextPath

public void recordContextPath(java.lang.String servletID,
                              java.lang.String urlPrefix)
                       throws ConnectionMethodException
Record the url prefix that will be used by the context The url path for the context is set when the channel is defined. This is after the application is defined in the .conf file.

Parameters:
servletID - The name of the context
urlPrefix - The start of the URL that leads to this context
ConnectionMethodException

removeContextPath

public void removeContextPath(java.lang.String servletID,
                              java.lang.String urlPrefix)
A channel has been closed remove the context.

Parameters:
servletID - The name of the context
urlPrefix - The start of the URL that leads to this context

recordWarOnlySettings

public void recordWarOnlySettings(java.lang.String servletID,
                                  java.lang.String defaultSessionTimeout,
                                  java.lang.String isWARExpanded,
                                  java.lang.String isWARValidated,
                                  java.lang.String isInvokerEnabled,
                                  java.lang.String isWorkDirPersistent)
These are values that only apply to a WAR

Parameters:
servletID - The id of the Context
defaultSessionTimeout -
isWARExpanded -
isWARValidated -
isInvokerEnabled -
isWorkDirPersistent -

recordSessionConfig

public void recordSessionConfig(java.lang.String servletID,
                                Config sessionConfig)
The context may have configuration information relating to the sessionManager

Parameters:
servletID - The id of the context.

startAllContexts

public void startAllContexts()
                      throws javax.servlet.ServletException
After all the configuration information has been collected it's safe to start all contexts that have been marked as runOnInit in the multiserver configuration file

Throws:
java.lang.Exception - If there is an error.
javax.servlet.ServletException

addFilter

public void addFilter(java.lang.String servletID,
                      java.lang.String filterID)
Adds the given filter to the list of filters to be applied to the given servlet when the Context is built.

Parameters:
servletID - a String id for the Context (Servlet).
filterID - a String id for the Filter to apply.

removeFilter

public void removeFilter(java.lang.String servletID,
                         java.lang.String filterID)

service

public void service(Channel channel,
                    org.apache.tomcat.core.Request rrequest,
                    org.apache.tomcat.core.Response rresponse)
             throws java.lang.Exception
Service the request. The servletManager is taking over the role that the ContextManager plays in Tomcat. So this routine is a close copy of the ContextManager's service(). The main diffirence is that contexts can be found ny name rather than by path. Which allows us to have two contexts with the same urlprefix but diffirent channel's e.g. diffirent ports.

Parameters:
channel - The channel that called us
rrequest -
rresponse -
java.lang.Exception

start

public void start(java.lang.String servletID)
           throws javax.servlet.ServletException
Force the instantiation of a Servlet. It will be created, and it's init() method will be called.

Parameters:
servletID - Which Servlet to start.
Throws:
javax.servlet.ServletException - If there is an error.

stop

public void stop(java.lang.String servletID)
          throws javax.servlet.ServletException
Stop a Servlet. This calls the Servlet's destroy() method, then discards the Servlet (making it available for garbage collection). After calling this, you may call start() to cause a new instance of the Servlet to be created.

Parameters:
servletID - Which Servlet to stop.
Throws:
javax.servlet.ServletException - If there is an error.

get

public javax.servlet.Servlet get(java.lang.String servletID)
                          throws javax.servlet.ServletException
Fetch a Servlet. If the identifier string can not be found, an exception will be thrown. If the Servlet has not been started, or if it failed to start up, then null will be returned. The counters will be incremented to reflect this access.

This is the prefered version of get(). Only call the other version if you need to get the Servlet and you will not be calling it's service() method.

Parameters:
servletID - Which Servlet to get.
Returns:
The specified Servlet.
Throws:
javax.servlet.ServletException - If the name was not found.

get

public javax.servlet.Servlet get(java.lang.String servletID,
                                 boolean counter)
                          throws javax.servlet.ServletException
Fetch a Servlet, with optional control over the counter. This is exactly like get(String servletID), except when counter is false, in which case the total references counter, and the requests per minute counter are not incremented.
This should only be used if you are not going to call service() on the Servlet. It is assumed that the number of get(String servletID) is exactly the same as the number of times service() was called on the Servlet.

Parameters:
servletID - Which Servlet to get.
counter - Should the counters be updated? This should only be false if you are not going to call service() on the returned Servlet.
Returns:
The specified Servlet.
Throws:
javax.servlet.ServletException - If the name was not found.

getStatus

public ServletStatus getStatus(java.lang.String servletID)
Get the current status of a Servlet.

Parameters:
servletID - Which Servlet to get the status of.
Returns:
A ServletStatus object describing the Servlet, or null if the name was not found.
See Also:
ServletStatus

getStatistics

public ServletStatistics getStatistics(java.lang.String servletID)
Get the current request-per-minute statistics of a Servlet. This returns a copy of all the stored data! In the future we should return a sub-range of the data.

Parameters:
servletID - Which Servlet to get the status of.
Returns:
A ServletStatistics object all the historical request-per-minute data for the Servlet, or null if the name was not found.
See Also:
ServletStatistics

resetStats

public void resetStats(java.lang.String servletID)
                throws javax.servlet.ServletException
Resets the maxmimum requests per minute to the current value, and the time of the maximum to now.

Parameters:
servletID - Which Servlet to reset the maximum request per minute stats for.
Throws:
javax.servlet.ServletException - If there is an error, or if the Servlet ID is not found.

delete

public void delete(java.lang.String servletID)
            throws javax.servlet.ServletException
Unregister a Servlet from the ServletManager. stop() is called on the Servlet, then it is removed from the set of Servlets. The name servletID is no longer valid.

Parameters:
servletID - Which Servlet to delete.
Throws:
javax.servlet.ServletException - If there is an error, or if the Servlet ID is not found.

getServletIDs

public java.lang.String[] getServletIDs()
Get the names of all the Servlets in the ServletManager.

Returns:
All the serverIDs currently in use.

getServletNames

public java.util.Enumeration getServletNames()
Get the names of all the Servlets in the ServletManager.

Returns:
A vector containing the serverIDs currently in use.

resetRefCount

public void resetRefCount(java.lang.String servletID)
                   throws javax.servlet.ServletException
Reset the reference count for a particular Servlet. This is the count of how many times the Servlet was asked for by get().

Parameters:
servletID - Which Servlet's counter to reset.
Throws:
javax.servlet.ServletException - If there is an error, or if the Servlet ID is not found.
See Also:
ServletStatus

getMimeType

protected java.lang.String getMimeType(java.lang.String file)
This is for internal use only. It is part of the Servlet initalization.


lookuptContextByPath

public org.apache.tomcat.core.Context lookuptContextByPath(java.lang.String path)

getServerInfoString

public java.lang.String getServerInfoString()
Get server info string to pass to the contexts


getContextByServletID

public org.apache.tomcat.core.Context getContextByServletID(java.lang.String id)
Return the Context for the given servlet id.

Parameters:
id - Serlvet id string.
Returns:
the Context that handles the servlet.

Enhydra 5.1 API