avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dona...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util ContextManager.java
Date Thu, 07 Nov 2002 06:57:53 GMT
donaldp     2002/11/06 22:57:53

  Modified:    fortress/src/java/org/apache/excalibur/fortress/util
                        ContextManager.java
  Log:
  Use ServiceManager internally.
  
  Revision  Changes    Path
  1.45      +99 -109   jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java
  
  Index: ContextManager.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/util/ContextManager.java,v
  retrieving revision 1.44
  retrieving revision 1.45
  diff -u -r1.44 -r1.45
  --- ContextManager.java	24 Oct 2002 11:25:10 -0000	1.44
  +++ ContextManager.java	7 Nov 2002 06:57:53 -0000	1.45
  @@ -54,13 +54,9 @@
   import org.apache.avalon.excalibur.logger.LogKitLoggerManager;
   import org.apache.avalon.excalibur.logger.LoggerManager;
   import org.apache.avalon.framework.activity.Initializable;
  -import org.apache.avalon.framework.component.ComponentManager;
  -import org.apache.avalon.framework.component.DefaultComponentManager;
  -import org.apache.avalon.framework.component.DefaultComponentSelector;
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.configuration.DefaultConfiguration;
   import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
  -import org.apache.avalon.framework.configuration.DefaultConfigurationSerializer;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
   import org.apache.avalon.framework.context.ContextException;
  @@ -70,6 +66,7 @@
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.DefaultServiceManager;
  +import org.apache.avalon.framework.service.DefaultServiceSelector;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.event.Sink;
   import org.apache.excalibur.event.command.CommandManager;
  @@ -94,19 +91,19 @@
    * further operations will be possible on it.</p>
    *
    * <p>You can get two different contexts from the ContextManager: the child
  - * context and the container manager context. The former contains all
  - * managers, such as the pool manager etc. necessary for a child container to
  - * create additional child containers. The container manager context contains
  + * context and the container m_manager context. The former contains all
  + * managers, such as the pool m_manager etc. necessary for a child container to
  + * create additional child containers. The container m_manager context contains
    * all of the child context, but also initialization parameters for the
    * container, such as a Configuration object, a ComponentLocator, etc., that
    * the container wants, but does not want to pass on to its children.</p>
    *
  - * <p>You would typically use the container manager context to initialize
  - * the container manager, and let it pass the child context on to the
  + * <p>You would typically use the container m_manager context to initialize
  + * the container m_manager, and let it pass the child context on to the
    * container.</p>
    *
    * <p>The ContextManager will sometimes create new components, such as a
  - * component manager, a pool manager, etc. It will manage these components
  + * component m_manager, a pool m_manager, etc. It will manage these components
    * and dispose of them properly when it itself is disposed .</p>
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  @@ -119,7 +116,6 @@
   public class ContextManager
       implements ContextManagerConstants, Initializable
   {
  -
       private static final Configuration EMPTY_CONFIG;
   
       static
  @@ -133,21 +129,21 @@
       /**
        * The root context.
        */
  -    private final Context rootContext;
  +    private final Context m_rootContext;
   
       /**
        * The context of the new container. This context has the rootContext
        * as its parent. Put everything here that you want the new container
        * to have in its own context.
        */
  -    private final DefaultContext childContext;
  +    private final DefaultContext m_childContext;
   
       /**
  -     * Container manager's context. This context has the child context
  -     * as parent. Put things here that you want the container manager
  +     * Container m_manager's context. This context has the child context
  +     * as parent. Put things here that you want the container m_manager
        * to see, but do not wish to expose to the container.
        */
  -    private final DefaultContext containerManagerContext;
  +    private final DefaultContext m_containerManagerContext;
   
       /**
        * New context passed in, maybe from a ContextBuilder.
  @@ -155,13 +151,13 @@
        * other pointers. The ContextManager inspects it for
        * elements it can use to create component managers etc.
        */
  -    private Logger logger;
  -    private final Logger primordialLogger;
  -    private ComponentManager manager;
  +    private Logger m_logger;
  +    private final Logger m_primordialLogger;
  +    private ServiceManager m_manager;
   
       /**
        * The components that are "owned" by this context and should
  -     * be disposed by it. Any manager that is created as a result
  +     * be disposed by it. Any m_manager that is created as a result
        * of it not being in the rootContext, or having been created
        * by the ContextManager should go in here.
        */
  @@ -173,9 +169,6 @@
        */
       private DefaultConfigurationBuilder configBuilder;
   
  -    private final DefaultConfigurationSerializer configSerializer =
  -        new DefaultConfigurationSerializer();
  -
       /**
        * Create a new ContextManager.
        *
  @@ -184,26 +177,26 @@
        */
       public ContextManager( Context rootContext, Logger logger )
       {
  -        this.rootContext = rootContext;
  -        this.childContext = new OverridableContext( this.rootContext );
  -        this.containerManagerContext = new OverridableContext( childContext );
  -        this.logger = logger;
  +        this.m_rootContext = rootContext;
  +        this.m_childContext = new OverridableContext( this.m_rootContext );
  +        this.m_containerManagerContext = new OverridableContext( m_childContext );
  +        this.m_logger = logger;
   
           // The primordial logger is used for all output up until the point where
  -        //  the logger manager has been initialized.  However it is set into
  +        //  the logger m_manager has been initialized.  However it is set into
           //  two objects used to load the configuration resource files within
           //  the ContextManager.  Any problems loading these files will result in
           //  warning or error messages.  However in most cases, the debug
           //  information should not be displayed, so turn it off by default.
           //  Unfortunately, there is not a very good place to make this settable.
  -        this.primordialLogger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
  +        this.m_primordialLogger = new ConsoleLogger( ConsoleLogger.LEVEL_INFO );
       }
   
       /**
        * Method to assume ownership of one of the managers the
        * <code>ContextManager</code> created.  Ownership means that the
        * <code>ContextManager</code> is responsible for destroying the
  -     * manager when the <code>ContextManager</code> is destroyed.
  +     * m_manager when the <code>ContextManager</code> is destroyed.
        *
        * FIXME: We should throw a NullPointerException instead.
        *
  @@ -239,8 +232,8 @@
           initializeInstrumentManager();
           initializeConfiguration();
   
  -        childContext.makeReadOnly();
  -        containerManagerContext.makeReadOnly();
  +        m_childContext.makeReadOnly();
  +        m_containerManagerContext.makeReadOnly();
       }
   
       /**
  @@ -252,7 +245,7 @@
       {
           try
           {
  -            containerManagerContext.put( CONFIGURATION, rootContext.get( CONFIGURATION
) );
  +            m_containerManagerContext.put( CONFIGURATION, m_rootContext.get( CONFIGURATION
) );
           }
           catch( ContextException ce )
           {
  @@ -260,10 +253,10 @@
               if( containerConfig == null )
               {
                   // No config.
  -                // Does the parent supply a logger manager?
  +                // Does the parent supply a logger m_manager?
                   try
                   {
  -                    containerManagerContext.get( CONFIGURATION );
  +                    m_containerManagerContext.get( CONFIGURATION );
   
                       // OK, done.
                       return;
  @@ -276,7 +269,7 @@
               }
               else
               {
  -                containerManagerContext.put( CONFIGURATION, containerConfig );
  +                m_containerManagerContext.put( CONFIGURATION, containerConfig );
               }
           }
       }
  @@ -307,7 +300,7 @@
        */
       protected void copyEntry( String key ) throws ContextException
       {
  -        containerManagerContext.put( key, rootContext.get( key ) );
  +        m_containerManagerContext.put( key, m_rootContext.get( key ) );
       }
   
       /**
  @@ -360,7 +353,7 @@
        *
        * <p>The postcondition is that
        * <code>childContext.get( Container.SERVICE_MANAGER )</code> should
  -     * return a valid logger manager.</p>
  +     * return a valid logger m_manager.</p>
        *
        * @throws Exception if the ServiceManager could not be instantiated.
        */
  @@ -368,7 +361,7 @@
       {
           try
           {
  -            childContext.put( SERVICE_MANAGER, rootContext.get( SERVICE_MANAGER ) );
  +            m_childContext.put( SERVICE_MANAGER, m_rootContext.get( SERVICE_MANAGER ) );
               return;
           }
           catch( ContextException ce )
  @@ -378,7 +371,7 @@
           // See if we can inherit from the parent...
           try
           {
  -            childContext.get( SERVICE_MANAGER );
  +            m_childContext.get( SERVICE_MANAGER );
   
               // OK, done.
               return;
  @@ -388,13 +381,13 @@
               // No ComponentLocator available anywhere. (Set one up.)
           }
   
  -        final ServiceManager parent = (ServiceManager)get( rootContext, SERVICE_MANAGER_PARENT,
null );
  +        final ServiceManager parent = (ServiceManager)get( m_rootContext, SERVICE_MANAGER_PARENT,
null );
   
           if( null != parent )
           {
               ServiceManager sm = new DefaultServiceManager( parent );
               assumeOwnership( sm );
  -            containerManagerContext.put( SERVICE_MANAGER, sm );
  +            m_containerManagerContext.put( SERVICE_MANAGER, sm );
           }
       }
   
  @@ -408,7 +401,7 @@
       {
           try
           {
  -            childContext.put( COMMAND_QUEUE, rootContext.get( COMMAND_QUEUE ) );
  +            m_childContext.put( COMMAND_QUEUE, m_rootContext.get( COMMAND_QUEUE ) );
               return;
           }
           catch( ContextException ce )
  @@ -417,7 +410,7 @@
   
           try
           {
  -            childContext.get( COMMAND_QUEUE );
  +            m_childContext.get( COMMAND_QUEUE );
               return;
           }
           catch( ContextException ce )
  @@ -425,7 +418,7 @@
           }
   
           // No CommandQueue specified, create a default one
  -        childContext.put( COMMAND_QUEUE, createCommandSink() );
  +        m_childContext.put( COMMAND_QUEUE, createCommandSink() );
       }
   
       /**
  @@ -443,9 +436,9 @@
           assumeOwnership( tm );
   
           // Get the context Logger Manager
  -        LoggerManager loggerManager = (LoggerManager)childContext.get( LOGGER_MANAGER );
  +        LoggerManager loggerManager = (LoggerManager)m_childContext.get( LOGGER_MANAGER
);
   
  -        // Get the logger for the thread manager
  +        // Get the logger for the thread m_manager
           Logger tmLogger = loggerManager.getLoggerForCategory( "system.threadmgr" );
   
           ContainerUtil.enableLogging( tm, tmLogger );
  @@ -471,7 +464,7 @@
   
           try
           {
  -            Integer processors = (Integer)rootContext.get( "processors" );
  +            Integer processors = (Integer)m_rootContext.get( "processors" );
               p.setParameter( "processors", processors.toString() );
           }
           catch( ContextException e )
  @@ -480,7 +473,7 @@
   
           try
           {
  -            threadsPerProcessor = (Integer)rootContext.get( THREADS_CPU );
  +            threadsPerProcessor = (Integer)m_rootContext.get( THREADS_CPU );
           }
           catch( ContextException e )
           {
  @@ -491,7 +484,7 @@
   
           try
           {
  -            threadBlockTimeout = (Long)rootContext.get( THREAD_TIMEOUT );
  +            threadBlockTimeout = (Long)m_rootContext.get( THREAD_TIMEOUT );
           }
           catch( ContextException e )
           {
  @@ -512,16 +505,16 @@
       {
           try
           {
  -            childContext.put( POOL_MANAGER, rootContext.get( POOL_MANAGER ) );
  +            m_childContext.put( POOL_MANAGER, m_rootContext.get( POOL_MANAGER ) );
               return;
           }
           catch( ContextException ce )
           {
           }
   
  -        PoolManager pm = new DefaultPoolManager( (Sink)childContext.get( COMMAND_QUEUE
) );
  +        PoolManager pm = new DefaultPoolManager( (Sink)m_childContext.get( COMMAND_QUEUE
) );
           assumeOwnership( pm );
  -        childContext.put( POOL_MANAGER, pm );
  +        m_childContext.put( POOL_MANAGER, pm );
       }
   
       /**
  @@ -533,7 +526,7 @@
       {
           try
           {
  -            childContext.put( ROLE_MANAGER, rootContext.get( ROLE_MANAGER ) );
  +            m_childContext.put( ROLE_MANAGER, m_rootContext.get( ROLE_MANAGER ) );
               return;
           }
           catch( ContextException ce )
  @@ -548,7 +541,7 @@
               // See if we can inherit from the parent...
               try
               {
  -                childContext.get( ROLE_MANAGER );
  +                m_childContext.get( ROLE_MANAGER );
   
                   // OK, done.
                   return;
  @@ -561,27 +554,27 @@
           }
   
           // Get the context Logger Manager
  -        LoggerManager loggerManager = (LoggerManager)childContext.get( LOGGER_MANAGER );
  +        LoggerManager loggerManager = (LoggerManager)m_childContext.get( LOGGER_MANAGER
);
   
  -        // Create a logger for the role manager
  +        // Create a logger for the role m_manager
           Logger rmLogger = loggerManager.getLoggerForCategory(
               roleConfig.getAttribute( "logger", "system.roles" ) );
   
           // Lookup the context class loader
  -        ClassLoader classLoader = (ClassLoader)containerManagerContext.get( CONTEXT_CLASSLOADER
);
  +        ClassLoader classLoader = (ClassLoader)m_containerManagerContext.get( CONTEXT_CLASSLOADER
);
   
  -        // Create a parent role manager with all the default roles
  +        // Create a parent role m_manager with all the default roles
           ExcaliburRoleManager erm = new ExcaliburRoleManager( null, classLoader );
           erm.enableLogging( rmLogger.getChildLogger( "defaults" ) );
           erm.initialize();
   
  -        // Create a role manager with the configured roles
  +        // Create a role m_manager with the configured roles
           ConfigurableRoleManager rm = new ConfigurableRoleManager( erm, classLoader );
           rm.enableLogging( rmLogger );
           rm.configure( roleConfig );
   
           assumeOwnership( rm );
  -        childContext.put( ROLE_MANAGER, rm );
  +        m_childContext.put( ROLE_MANAGER, rm );
       }
   
       /**
  @@ -593,19 +586,18 @@
        */
       protected void initializeOwnComponentManager() throws Exception
       {
  -        DefaultComponentManager manager = new DefaultComponentManager();
  -
  -        DefaultComponentSelector selector = new DefaultComponentSelector();
  -        ResourceSourceFactory resource = new ResourceSourceFactory();
  +        final DefaultServiceManager manager = new DefaultServiceManager();
  +        final DefaultServiceSelector selector = new DefaultServiceSelector();
  +        final ResourceSourceFactory resource = new ResourceSourceFactory();
           resource.enableLogging( getLogger() );
           selector.put( "resource", resource );
   
           manager.put( resource.ROLE + "Selector", selector );
   
  -        SourceResolverImpl resolver = new SourceResolverImpl();
  -        resolver.enableLogging( getLogger() );
  -        resolver.contextualize( this.childContext );
  -        resolver.compose( manager );
  +        final SourceResolverImpl resolver = new SourceResolverImpl();
  +        ContainerUtil.enableLogging( resolver, getLogger() );
  +        ContainerUtil.contextualize( resolver, m_childContext );
  +        ContainerUtil.service( resolver, manager );
   
           manager.put( resolver.ROLE, resolver );
   
  @@ -613,7 +605,7 @@
   
           assumeOwnership( manager );
   
  -        this.manager = manager;
  +        m_manager = manager;
       }
   
       /**
  @@ -625,13 +617,9 @@
        */
       protected Configuration getConfiguration( String configKey, String uriKey )
       {
  -        Configuration config = null;
  -        SourceResolver resolver = null;
  -        Source src = null;
  -
           try
           {
  -            return (Configuration)rootContext.get( configKey );
  +            return (Configuration)m_rootContext.get( configKey );
           }
           catch( ContextException ce )
           {
  @@ -640,16 +628,18 @@
           String configUri = null;
           try
           {
  -            configUri = (String)rootContext.get( uriKey );
  +            configUri = (String)m_rootContext.get( uriKey );
           }
           catch( ContextException ce )
           {
               return null;
           }
   
  +        SourceResolver resolver = null;
  +        Source src = null;
           try
           {
  -            resolver = (SourceResolver)manager.lookup( SourceResolver.ROLE );
  +            resolver = (SourceResolver)m_manager.lookup( SourceResolver.ROLE );
               src = resolver.resolveURI( configUri );
               if( configBuilder == null )
               {
  @@ -666,7 +656,7 @@
           finally
           {
               resolver.release( src );
  -            manager.release( resolver );
  +            m_manager.release( resolver );
           }
       }
   
  @@ -677,7 +667,7 @@
        */
       public Context getContainerManagerContext()
       {
  -        return containerManagerContext;
  +        return m_containerManagerContext;
       }
   
       /**
  @@ -687,7 +677,7 @@
        */
       public Context getChildContext()
       {
  -        return childContext;
  +        return m_childContext;
       }
   
       /**
  @@ -697,13 +687,13 @@
        */
       protected Logger getLogger()
       {
  -        if( logger == null )
  +        if( m_logger == null )
           {
  -            return primordialLogger;
  +            return m_primordialLogger;
           }
           else
           {
  -            return logger;
  +            return m_logger;
           }
       }
   
  @@ -713,7 +703,7 @@
        *
        * <p>The postcondition is that
        * <code>childContext.get( Container.LOGGER_MANAGER )</code> should
  -     * return a valid logger manager.</p>
  +     * return a valid logger m_manager.</p>
        *
        * @throws Exception if it cannot instantiate the LoggerManager
        */
  @@ -721,9 +711,9 @@
       {
           try
           {
  -            // Try copying an already existing logger manager from the override context.
  +            // Try copying an already existing logger m_manager from the override context.
   
  -            childContext.put( LOGGER_MANAGER, rootContext.get( LOGGER_MANAGER ) );
  +            m_childContext.put( LOGGER_MANAGER, m_rootContext.get( LOGGER_MANAGER ) );
           }
           catch( ContextException ce )
           {
  @@ -735,10 +725,10 @@
               {
                   // No config specified.
   
  -                // Does the parent supply a logger manager?
  +                // Does the parent supply a logger m_manager?
                   try
                   {
  -                    childContext.get( LOGGER_MANAGER );
  +                    m_childContext.get( LOGGER_MANAGER );
   
                       // OK, done.
                       return;
  @@ -752,8 +742,8 @@
               }
   
               // Resolve the prefix to use for this Logger Manager
  -            String logPrefix = (String)get( rootContext, LOG_CATEGORY,
  -                                            get( childContext, LOG_CATEGORY, null ) );
  +            String logPrefix = (String)get( m_rootContext, LOG_CATEGORY,
  +                                            get( m_childContext, LOG_CATEGORY, null ) );
   
               // Resolve a name for the logger, taking the logPrefix into account
               String lmDefaultLoggerName;
  @@ -787,23 +777,23 @@
               LogKitLoggerManager logManager = new LogKitLoggerManager(
                   logPrefix, Hierarchy.getDefaultHierarchy(),
                   new LogKitLogger( lmDefaultLogger ), new LogKitLogger( lmLogger ) );
  -            logManager.contextualize( rootContext );
  +            logManager.contextualize( m_rootContext );
               logManager.configure( loggerManagerConfig );
   
               assumeOwnership( logManager );
   
  -            childContext.put( LOGGER_MANAGER, logManager );
  +            m_childContext.put( LOGGER_MANAGER, logManager );
           }
   
           // Since we now have a LoggerManager, we can update the this.logger field
           // if it is null and start logging to the "right" logger.
   
  -        if( this.logger == null )
  +        if( this.m_logger == null )
           {
               getLogger().debug( "Switching to default Logger provided by LoggerManager."
);
   
  -            LoggerManager loggerManager = (LoggerManager)childContext.get( LOGGER_MANAGER
);
  -            this.logger = loggerManager.getDefaultLogger();
  +            LoggerManager loggerManager = (LoggerManager)m_childContext.get( LOGGER_MANAGER
);
  +            this.m_logger = loggerManager.getDefaultLogger();
           }
       }
   
  @@ -813,7 +803,7 @@
        *
        * <p>The postcondition is that
        * <code>childContext.get( Container.LOGGER_MANAGER )</code> should
  -     * return a valid logger manager.</p>
  +     * return a valid logger m_manager.</p>
        *
        * @throws Exception if it cannot instantiate the LoggerManager
        */
  @@ -821,9 +811,9 @@
       {
           try
           {
  -            // Try copying an already existing instrument manager from the override context.
  +            // Try copying an already existing instrument m_manager from the override context.
   
  -            childContext.put( INSTRUMENT_MANAGER, rootContext.get( INSTRUMENT_MANAGER )
);
  +            m_childContext.put( INSTRUMENT_MANAGER, m_rootContext.get( INSTRUMENT_MANAGER
) );
           }
           catch( ContextException ce )
           {
  @@ -833,10 +823,10 @@
               if( instrumentConfig == null )
               {
                   // No config.
  -                // Does the parent supply a logger manager?
  +                // Does the parent supply a logger m_manager?
                   try
                   {
  -                    childContext.get( INSTRUMENT_MANAGER );
  +                    m_childContext.get( INSTRUMENT_MANAGER );
   
                       // OK, done.
                       return;
  @@ -849,9 +839,9 @@
               }
   
               // Get the context Logger Manager
  -            LoggerManager loggerManager = (LoggerManager)childContext.get( LOGGER_MANAGER
);
  +            LoggerManager loggerManager = (LoggerManager)m_childContext.get( LOGGER_MANAGER
);
   
  -            // Get the logger for the instrument manager
  +            // Get the logger for the instrument m_manager
               Logger imLogger = loggerManager.getLoggerForCategory(
                   instrumentConfig.getAttribute( "logger", "system.instrument" ) );
   
  @@ -863,7 +853,7 @@
   
               assumeOwnership( instrumentManager );
   
  -            childContext.put( INSTRUMENT_MANAGER, instrumentManager );
  +            m_childContext.put( INSTRUMENT_MANAGER, instrumentManager );
           }
       }
   
  @@ -872,7 +862,7 @@
        *
        * <p>The postcondition is that
        * <code>childContext.get( Container.LOGGER_MANAGER )</code> should
  -     * return a valid logger manager.</p>
  +     * return a valid logger m_manager.</p>
        *
        * @throws Exception if it cannot instantiate the LoggerManager
        */
  @@ -880,7 +870,7 @@
       {
           try
           {
  -            containerManagerContext.put( ASSEMBLY_CONFIGURATION, rootContext.get( ASSEMBLY_CONFIGURATION
) );
  +            m_containerManagerContext.put( ASSEMBLY_CONFIGURATION, m_rootContext.get( ASSEMBLY_CONFIGURATION
) );
           }
           catch( ContextException ce )
           {
  @@ -888,10 +878,10 @@
               if( containerConfig == null )
               {
                   // No config.
  -                // Does the parent supply a logger manager?
  +                // Does the parent supply a logger m_manager?
                   try
                   {
  -                    containerManagerContext.get( ASSEMBLY_CONFIGURATION );
  +                    m_containerManagerContext.get( ASSEMBLY_CONFIGURATION );
   
                       // OK, done.
                       return;
  @@ -904,7 +894,7 @@
               }
               else
               {
  -                containerManagerContext.put( ASSEMBLY_CONFIGURATION, containerConfig );
  +                m_containerManagerContext.put( ASSEMBLY_CONFIGURATION, containerConfig
);
               }
           }
       }
  
  
  

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


Mime
View raw message