You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2003/03/07 18:46:02 UTC

cvs commit: avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/handler ComponentFactory.java

bloritsch    2003/03/07 09:46:02

  Modified:    fortress default.properties
               fortress/src/java/org/apache/avalon/fortress/impl
                        AbstractContainer.java
               fortress/src/java/org/apache/avalon/fortress/impl/handler
                        ComponentFactory.java
  Added:       fortress/src/java/org/apache/avalon/fortress/impl/extensions
                        InstrumentableCreator.java
  Log:
  use InstrumentableCreator as the method to register instrumentables
  
  Revision  Changes    Path
  1.66      +1 -1      avalon-excalibur/fortress/default.properties
  
  Index: default.properties
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/default.properties,v
  retrieving revision 1.65
  retrieving revision 1.66
  diff -u -r1.65 -r1.66
  --- default.properties	6 Mar 2003 13:12:57 -0000	1.65
  +++ default.properties	7 Mar 2003 17:46:01 -0000	1.66
  @@ -93,7 +93,7 @@
   # ----- Excalibur datasource, version 1.0 or later -----
   excalibur-datasource.home=${basedir}/../datasource/dist
   excalibur-datasource.lib=${excalibur-datasource.home}
  -excalibur-datasource.jar=${excalibur-datasource.lib}/excalibur-datasource-1.0.jar
  +excalibur-datasource.jar=${excalibur-datasource.lib}/excalibur-datasource-1.1.jar
   
   # ----- Excalibur Pool, version 1.0 or later -----
   excalibur-pool.home=${basedir}/../pool/dist
  
  
  
  1.12      +22 -4     avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/AbstractContainer.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AbstractContainer.java	7 Mar 2003 13:14:21 -0000	1.11
  +++ AbstractContainer.java	7 Mar 2003 17:46:01 -0000	1.12
  @@ -58,6 +58,7 @@
   import org.apache.avalon.fortress.Container;
   import org.apache.avalon.fortress.RoleEntry;
   import org.apache.avalon.fortress.RoleManager;
  +import org.apache.avalon.fortress.impl.extensions.InstrumentableCreator;
   import org.apache.avalon.fortress.impl.handler.ComponentFactory;
   import org.apache.avalon.fortress.impl.handler.ComponentHandler;
   import org.apache.avalon.fortress.impl.handler.LEAwareComponentHandler;
  @@ -194,11 +195,29 @@
                   final String message =
                       "No Container.LIFECYCLE_EXTENSION_MANAGER is given, " +
                       "installing default lifecycle extension manager with " +
  -                    "0 extensions";
  +                    "1 extensions";
                   getLogger().debug( message );
               }
           }
   
  +        /* Add all the standard extensions if they have not already been
  +         * done.
  +         */
  +        boolean isInstrumentEnabled = false;
  +        Iterator it = m_extManager.creatorExtensionsIterator();
  +        while(it.hasNext())
  +        {
  +            if (it.next() instanceof InstrumentableCreator)
  +            {
  +                isInstrumentEnabled = true;
  +            }
  +        }
  +        
  +        if ( ! isInstrumentEnabled )
  +        {
  +            m_extManager.addCreatorExtension(new InstrumentableCreator(m_instrumentManager));
  +        }
  +
           if( serviceManager.hasService( Queue.ROLE ) )
           {
               m_commandQueue = (Queue)serviceManager.lookup( Queue.ROLE );
  @@ -410,8 +429,7 @@
           final ComponentFactory componentFactory =
               new ComponentFactory( clazz, configuration,
                                     m_serviceManager, m_context,
  -                                  m_loggerManager, m_extManager,
  -                                  m_instrumentManager );
  +                                  m_loggerManager, m_extManager );
           return new ProxyObjectFactory( componentFactory );
       }
   
  
  
  
  1.1                  avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/extensions/InstrumentableCreator.java
  
  Index: InstrumentableCreator.java
  ===================================================================
  /* ====================================================================
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 2003 The Apache Software Foundation. All rights
   * reserved.
   *
   * Redistribution and use in source and binary forms, with or without
   * modification, are permitted provided that the following conditions
   * are met:
   *
   * 1. Redistributions of source code must retain the above copyright
   *    notice, this list of conditions and the following disclaimer.
   *
   * 2. Redistributions in binary form must reproduce the above copyright
   *    notice, this list of conditions and the following disclaimer in
   *    the documentation and/or other materials provided with the
   *    distribution.
   *
   * 3. The end-user documentation included with the redistribution,
   *    if any, must include the following acknowledgment:
   *    "This product includes software developed by the
   *    Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowledgment may appear in the software
   *    itself, if and wherever such third-party acknowledgments
   *    normally appear.
   *
   * 4. The names "D-Haven" and "Apache Software Foundation"
   *    must not be used to endorse or promote products derived from this
   *    software without prior written permission. For written
   *    permission, please contact apache@apache.org.
   *
   * 5. Products derived from this software may not be called "Apache",
   *    nor may "Apache" appear in their name, without prior written
   *    permission of the Apache Software Foundation.
   *
   * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
   * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
   * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
   * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
   * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
   * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
   * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
   * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
   * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
   * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
   * SUCH DAMAGE.
   * ====================================================================
   *
   * This software consists of voluntary contributions made by many
   * individuals on behalf of the Apache Software Foundation. For more
   * information on the Apache Software Foundation, please see
   * <http://www.apache.org/>.
   */
  package org.apache.avalon.fortress.impl.extensions;
  
  import org.apache.avalon.framework.context.Context;
  import org.apache.excalibur.container.lifecycle.Creator;
  import org.apache.excalibur.instrument.InstrumentManageable;
  import org.apache.excalibur.instrument.InstrumentManager;
  import org.apache.excalibur.instrument.Instrumentable;
  
  /**
   * The InstrumentableCreator is used as a standard lifecycle
   * extension for containers that support it.
   */
  public class InstrumentableCreator implements Creator
  {
      private final InstrumentManager m_instrumentManager;
      private final boolean m_instrumentEnabled;
      
      public InstrumentableCreator(InstrumentManager instrumentManager)
      {
          m_instrumentManager = instrumentManager;
          m_instrumentEnabled = instrumentManager != null;
      }
      
      /**
       * Assign the instrumentables and InstrumentManageables
       */
      public void create(Object object, Context context) throws Exception
      {
          if( m_instrumentEnabled && object instanceof Instrumentable )
          {
              String instrumentableName = (String)context.get("component.name");
              final Instrumentable instrumentable = (Instrumentable)object;
              instrumentable.setInstrumentableName( instrumentableName );
  
              // Get the name from the instrumentable in case it was changed since being set above.
              m_instrumentManager.registerInstrumentable(
                  instrumentable, instrumentable.getInstrumentableName() );
  
          }
          
          if( m_instrumentEnabled && object instanceof InstrumentManageable )
          {
              ( (InstrumentManageable)object ).setInstrumentManager( m_instrumentManager );
          }
  
      }
      
      /**
       * Not used.
       */
      public void destroy(Object object, Context context)
      {}
  }
  
  
  
  1.8       +20 -59    avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java
  
  Index: ComponentFactory.java
  ===================================================================
  RCS file: /home/cvs/avalon-excalibur/fortress/src/java/org/apache/avalon/fortress/impl/handler/ComponentFactory.java,v
  retrieving revision 1.7
  retrieving revision 1.8
  diff -u -r1.7 -r1.8
  --- ComponentFactory.java	7 Mar 2003 13:14:22 -0000	1.7
  +++ ComponentFactory.java	7 Mar 2003 17:46:01 -0000	1.8
  @@ -54,19 +54,15 @@
   import org.apache.avalon.framework.configuration.Configuration;
   import org.apache.avalon.framework.container.ContainerUtil;
   import org.apache.avalon.framework.context.Context;
  -import org.apache.avalon.framework.logger.LogEnabled;
  +import org.apache.avalon.framework.context.DefaultContext;
   import org.apache.avalon.framework.logger.LogKit2AvalonLoggerAdapter;
   import org.apache.avalon.framework.logger.Loggable;
   import org.apache.avalon.framework.logger.Logger;
  -import org.apache.avalon.framework.parameters.Parameterizable;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.excalibur.container.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.instrument.AbstractLogEnabledInstrumentable;
   import org.apache.excalibur.instrument.CounterInstrument;
  -import org.apache.excalibur.instrument.InstrumentManageable;
  -import org.apache.excalibur.instrument.InstrumentManager;
  -import org.apache.excalibur.instrument.Instrumentable;
   import org.apache.excalibur.mpool.ObjectFactory;
   
   /**
  @@ -115,9 +111,8 @@
        */
       private final LifecycleExtensionManager m_extManager;
   
  -    /** InstrumentManager
  +    /** The component's logger
        */
  -    private final InstrumentManager m_instrumentManager;
       private Logger m_componentLogger;
   
       /**
  @@ -134,18 +129,17 @@
                                final ServiceManager serviceManager,
                                final Context context,
                                final LoggerManager loggerManager,
  -                             final LifecycleExtensionManager extManager,
  -                             final InstrumentManager instrumentManager )
  +                             final LifecycleExtensionManager extManager )
       {
           m_componentClass = componentClass;
           m_configuration = configuration;
           m_serviceManager = serviceManager;
  -        m_context = context;
  +        m_context = new DefaultContext(context);
  +        ((DefaultContext)m_context).put("component.name", configuration.getAttribute("id", componentClass.getName()));
  +        ((DefaultContext)m_context).makeReadOnly();
           m_loggerManager = loggerManager;
           m_extManager = extManager;
           enableLogging( m_loggerManager.getLoggerForCategory( "system.factory" ) );
  -        m_instrumentManager = instrumentManager;
  -        m_instrumentableName = configuration.getAttribute( "id", componentClass.getName() );
           m_componentLogger = aquireLogger();
   
           m_newInstance = new CounterInstrument( "creates" );
  @@ -179,64 +173,31 @@
               getLogger().debug( message );
           }
   
  -        if( component instanceof LogEnabled ||
  -            component instanceof Loggable )
  -        {
  -
  -            if( component instanceof LogEnabled )
  -            {
  -                ContainerUtil.enableLogging( component, m_componentLogger );
  -            }
  -            else
  -            {
  -                final String message = "WARNING: " + m_componentClass.getName() +
  -                    " implements the Loggable lifecycle stage. This is " +
  -                    " a deprecated feature that will be removed in the future. " +
  -                    " Please upgrade to using LogEnabled.";
  -                getLogger().warn( message );
  -                System.out.println( message );
  -
  -                final org.apache.log.Logger logkitLogger =
  -                    LogKit2AvalonLoggerAdapter.createLogger( m_componentLogger );
  -                ( (Loggable)component ).setLogger( logkitLogger );
  -            }
  -        }
  -
  -        // Set the name of the instrumentable before initialization.
  -        if( component instanceof Instrumentable )
  -        {
  -            final Instrumentable instrumentable = (Instrumentable)component;
  -            instrumentable.setInstrumentableName( m_instrumentableName );
  -        }
  +        ContainerUtil.enableLogging(component, m_componentLogger);
           
  -        if( component instanceof InstrumentManageable )
  +        if( component instanceof Loggable )
           {
  -            ( (InstrumentManageable)component ).setInstrumentManager( m_instrumentManager );
  +            final String message = "WARNING: " + m_componentClass.getName() +
  +                " implements the Loggable lifecycle stage. This is " +
  +                " a deprecated feature that will be removed in the future. " +
  +                " Please upgrade to using LogEnabled.";
  +            getLogger().warn( message );
  +            System.out.println( message );
  +
  +            final org.apache.log.Logger logkitLogger =
  +                LogKit2AvalonLoggerAdapter.createLogger( m_componentLogger );
  +            ( (Loggable)component ).setLogger( logkitLogger );
           }
   
           ContainerUtil.contextualize( component, m_context );
           ContainerUtil.compose( component, new WrapperComponentManager( m_serviceManager ) );
           ContainerUtil.service( component, m_serviceManager );
           ContainerUtil.configure( component, m_configuration );
  -
  -        if( component instanceof Parameterizable )
  -        {
  -            Parameters parameters = Parameters.fromConfiguration( m_configuration );
  -            ContainerUtil.parameterize( component, parameters );
  -        }
  +        ContainerUtil.parameterize(component, Parameters.fromConfiguration(m_configuration));
   
           m_extManager.executeCreationExtensions( component, m_context );
   
           ContainerUtil.initialize( component );
  -
  -        if( component instanceof Instrumentable )
  -        {
  -            final Instrumentable instrumentable = (Instrumentable)component;
  -            
  -            // Get the name from the instrumentable in case it was changed since being set above.
  -            m_instrumentManager.registerInstrumentable(
  -                instrumentable, instrumentable.getInstrumentableName() );
  -        }
   
           ContainerUtil.start( component );
   
  
  
  

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