org.apache.avalon.excalibur.component.servlet
Class ExcaliburComponentManagerServlet

java.lang.Object
  extended by javax.servlet.GenericServlet
      extended by org.apache.avalon.excalibur.component.servlet.ExcaliburComponentManagerServlet
All Implemented Interfaces:
java.io.Serializable, javax.servlet.Servlet, javax.servlet.ServletConfig

Deprecated. ECM is no longer supported

public class ExcaliburComponentManagerServlet
extends javax.servlet.GenericServlet

Makes it possible for servlets to work with Avalon components without having to do any coding to setup and manage the lifecycle of the ServiceManager (ComponentManager).

To make use of the ExcaliburComponentManagerServet. You will need to define the servlet in your web.xml file as follows:

  <!-- ExcaliburComponentManagerServlet (for initializing ComponentManager).   -->
  <servlet>
      <servlet-name>ExcaliburComponentManagerServlet</servlet-name>
      <display-name>ExcaliburComponentManagerServlet</display-name>
      <description>Creates component manager, does not service requests.</description>
      <servlet-class>
          org.apache.avalon.excalibur.component.servlet.ExcaliburComponentManagerServlet
      </servlet-class>

      <!-- This parameter points to the logkit configuration file.             -->
      <!-- Note that the path is specified in absolute notation but it will be -->
      <!-- resolved relative to the servlets webapp context path               -->
      <init-param>
          <param-name>logkit</param-name>
          <param-value>/WEB-INF/logkit.xml</param-value>
      </init-param>

      <!-- This parameter points to the components configuration file.         -->
      <init-param>
          <param-name>components</param-name>
          <param-value>/WEB-INF/components.xml</param-value>
      </init-param>

      <!-- Roles file supplements configuration file to make the latter        -->
      <!-- more readable. Most likely you don't want to change the roles       -->
      <!-- file -->
      <init-param>
          <param-name>roles</param-name>
          <param-value>/WEB-INF/roles.xml</param-value>
      </init-param>

      <!-- This parameter points to the instrument manager configuration file. -->
      <init-param>
          <param-name>instrument</param-name>
          <param-value>/WEB-INF/instrument.xml</param-value>
      </init-param>

      <load-on-startup>1</load-on-startup>
  </servlet>
 
Please pay particular attention to the load-on-startup element. It is used to control the order in which servlets are started by the servlet engine. It must have a value which is less than any other servlets making use of the ServiceManager. This is to ensure that the ServiceManager is initialized before any other servlets attempt to start using it.

All of the configuration files are located in the WEB-INF directory by default. The instrument configuration file is optional. Please see the ExcaliburComponentManagerCreator class for details on what goes into these configuration files. Note that the lifecycle of the ExcaliburComponentManagerCreator is managed automatically by this servlet, so there is no need to access the class directly.

Once the servlet has been configured, other servlets may gain access to the ServiceManager (ComponentManager), InstrumentManager and LoggerManager via the ServletContext using the following code within a servlet:

  // Get a reference to the ServletContext
  ServletContext servletContext = getServletContext();

  // Acquire the LoggerManager
  LoggerManager loggerManager =
      (LoggerManager)m_servletContext.getAttribute( LoggerManager.class.getName() );

  // Acquire the InstrumentManager
  InstrumentManager instrumentManager =
      (InstrumentManager)m_servletContext.getAttribute( InstrumentManager.class.getName() );

  // Acquire the ServiceManager
  ServiceManager serviceManager =
      (ServiceManager)m_servletContext.getAttribute( ServiceManager.class.getName() );

  // Acquire the ComponentManager ( Deprecated )
  ComponentManager componentManager =
      (ComponentManager)m_servletContext.getAttribute( ComponentManager.class.getName() );
 
The ExcaliburComponentManagerServlet makes use of a proxy system to manage reference to the above managers, so it is not necessary to release them when a servlet is done using them.

It may be necessary to add the following code to the end of the dispose method of any servlets referencing any of the above proxies. This is because on some containers, like Tomcat, the classloader is immediately invalidated after the last servlet is disposed. If this happens before the managers have all been disposed, then you may see errors in the console like: WebappClassLoader: Lifecycle error : CL stopped

  System.gc();
  try
  {
      Thread.sleep(250);
  }
  catch ( InterruptedException e ) {}
 
Note that servlets which extend the AbstractComponentManagerServlet will behave correctly.

Since:
4.2
Version:
CVS $Revision: 1.4 $ $Date: 2004/02/28 11:47:16 $
Author:
Avalon Development Team
See Also:
Serialized Form

Nested Class Summary
private static class ExcaliburComponentManagerServlet.Latch
          Deprecated.  
 
Field Summary
private  ExcaliburComponentManagerCreator m_componentManagerCreator
          Deprecated.  
private  ExcaliburComponentManagerServlet.Latch m_latch
          Deprecated. Latch used to shutdown the ExcaliburComponentManagerCreator cleanly.
 
Constructor Summary
ExcaliburComponentManagerServlet()
          Deprecated.  
 
Method Summary
 void destroy()
          Deprecated. Called by the servlet container to destroy the servlet.
private  java.io.InputStream getStreamFromParameter(javax.servlet.ServletConfig servletConfig, java.lang.String resourceName, boolean required)
          Deprecated. Looks up a specified resource name and returns it as an InputStream.
 void init(javax.servlet.ServletConfig servletConfig)
          Deprecated. Builds the component manager and stores references to the ComponentManager, LoggerManager, and InstrumentManager into the ServletContext.
 void service(javax.servlet.ServletRequest servletRequest, javax.servlet.ServletResponse servletResponse)
          Deprecated. This servlet does not accept requests.
 
Methods inherited from class javax.servlet.GenericServlet
getInitParameter, getInitParameterNames, getServletConfig, getServletContext, getServletInfo, getServletName, init, log, log
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_componentManagerCreator

private ExcaliburComponentManagerCreator m_componentManagerCreator
Deprecated. 

m_latch

private ExcaliburComponentManagerServlet.Latch m_latch
Deprecated. 
Latch used to shutdown the ExcaliburComponentManagerCreator cleanly.

Constructor Detail

ExcaliburComponentManagerServlet

public ExcaliburComponentManagerServlet()
Deprecated. 
Method Detail

init

public void init(javax.servlet.ServletConfig servletConfig)
          throws javax.servlet.ServletException
Deprecated. 
Builds the component manager and stores references to the ComponentManager, LoggerManager, and InstrumentManager into the ServletContext.

Specified by:
init in interface javax.servlet.Servlet
Overrides:
init in class javax.servlet.GenericServlet
Parameters:
servletConfig - Servlet configuration
Throws:
javax.servlet.ServletException - If there are any problems initializing the servlet.

destroy

public void destroy()
Deprecated. 
Called by the servlet container to destroy the servlet.

Specified by:
destroy in interface javax.servlet.Servlet
Overrides:
destroy in class javax.servlet.GenericServlet

service

public void service(javax.servlet.ServletRequest servletRequest,
                    javax.servlet.ServletResponse servletResponse)
             throws javax.servlet.UnavailableException
Deprecated. 
This servlet does not accept requests. It will complain if called.

Specified by:
service in interface javax.servlet.Servlet
Specified by:
service in class javax.servlet.GenericServlet
Parameters:
req - servlet request
res - servlet response
Throws:
javax.servlet.UnavailableException - always

getStreamFromParameter

private java.io.InputStream getStreamFromParameter(javax.servlet.ServletConfig servletConfig,
                                                   java.lang.String resourceName,
                                                   boolean required)
                                            throws javax.servlet.ServletException
Deprecated. 
Looks up a specified resource name and returns it as an InputStream. It is the responsibility of the caller to close the stream.

Parameters:
servletConfig - ServletConfig.
resourceName - Name of the resource to be loaded.
required - True if an error should be thrown if the property is missing.
Returns:
InputStream used to read the contents of the resource.
Throws:
javax.servlet.ServletException - If the specified resource does not exist, or could not be opened.