avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leif Mortenson <l...@tanukisoftware.com>
Subject [Commit] New Servlet and Creator tools in the component package
Date Wed, 21 Aug 2002 06:30:25 GMT
I went ahead and committed a couple of tools which I have been using for 
some time to ease the use of the ECM.

The first is the ExcaliburComponentManagerCreator class.  It is used to 
manage the entire lifecycle of the ECM, RoleManager, LoggerManager and
optionally the InstrumentManager.  And it can all be done with the
following code.  Much simpler than having to everything manually each
time it is used:

m_componentManagerCreator = new ExcaliburComponentManagerCreator(
    null, // Optional Context
    new File( "../conf/logkit.xml" ),
    new File( "../conf/roles.xml" ),
    new File( "../conf/components.xml"),
    new File( "../conf/instrument.xml" ) );

Accessing the ECM:
m_componentManager = m_componentManagerCreator.getComponentManager();
m_loggerManager = m_componentManagerCreator.getLoggerManager();
m_instrumentManager = m_componentManagerCreator.getInstrumentManager();

m_componentManagerCreator = null;

It is as easy as that.

The second utility class is the ExcaliburComponentManagerServlet.  It is 
located in the servlet subpackage and built into a seperate jar file: 
The ECMServlet allows users who wish to use the ECM in a Servlet 
environment to do so painlessly.

>From the javadocs: (Prettier in the javadocs)
Makes it possible for servlets to work with Avalon components without 
having to do any coding to setup and manage the lifecycle of the 
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). -->
<description>Creates component manager, does not service 

<!-- 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 -->

<!-- This parameter points to the components configuration file. -->

<!-- Roles file supplements configuration file to make the latter -->
<!-- more readable. Most likely you don't want to change the roles -->
<!-- file -->

<!-- This parameter points to the instrument manager configuration file. -->


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 ComponentManager. This is to ensure that the 
ComponentManager 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 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.class.getName() );

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

// Acquire the ComponentManager
ComponentManager componentManager =
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.


To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>

View raw message