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/containerkit/src/java/org/apache/excalibur/containerkit/kernel ComponentEntry.java AbstractServiceKernel.java
Date Tue, 18 Jun 2002 08:13:18 GMT
donaldp     2002/06/18 01:13:18

  Modified:    containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        AbstractServiceKernel.java
  Added:       containerkit/src/java/org/apache/excalibur/containerkit/kernel
                        ComponentEntry.java
  Log:
  Start of a generic container that failed .. committing in so can move computers...
  
  Revision  Changes    Path
  1.2       +197 -3    jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/AbstractServiceKernel.java
  
  Index: AbstractServiceKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/AbstractServiceKernel.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- AbstractServiceKernel.java	14 Jun 2002 08:00:47 -0000	1.1
  +++ AbstractServiceKernel.java	18 Jun 2002 08:13:18 -0000	1.2
  @@ -7,6 +7,19 @@
    */
   package org.apache.excalibur.containerkit.kernel;
   
  +import java.util.Arrays;
  +import java.util.HashMap;
  +import java.util.List;
  +import org.apache.avalon.excalibur.i18n.ResourceManager;
  +import org.apache.avalon.excalibur.i18n.Resources;
  +import org.apache.avalon.framework.activity.Initializable;
  +import org.apache.avalon.framework.activity.Startable;
  +import org.apache.avalon.framework.context.Contextualizable;
  +import org.apache.avalon.framework.logger.AbstractLogEnabled;
  +import org.apache.excalibur.containerkit.dependency.DependencyGraph;
  +import org.apache.excalibur.containerkit.lifecycle.LifecycleHelper;
  +import org.apache.excalibur.containerkit.lifecycle.ResourceProvider;
  +
   /**
    *
    *
  @@ -14,8 +27,189 @@
    * @version $Revision$ $Date$
    */
   public abstract class AbstractServiceKernel
  +    extends AbstractLogEnabled
  +    implements Contextualizable, Initializable, Startable
   {
  -    protected abstract Object getComponent( String name );
  +    private final static Resources REZ =
  +        ResourceManager.getPackageResources( AbstractServiceKernel.class );
  +
  +    /**
  +     * The resource provider to use to provide resources
  +     * for all the components.
  +     */
  +    private ResourceProvider m_resourceProvider;
  +
  +    /**
  +     * The component that is responsible for running components
  +     * through their lifecycle stages.
  +     */
  +    private LifecycleHelper m_lifecycleHelper;
  +
  +    /**
  +     * The map of all entrys present in application.
  +     */
  +    private final HashMap m_entrys = new HashMap();
  +
  +    public void initialize()
  +        throws Exception
  +    {
  +        m_resourceProvider = prepareResourceProvider();
  +        m_lifecycleHelper = prepareLifecycleHelper();
  +    }
  +
  +    protected abstract ResourceProvider prepareResourceProvider();
  +
  +    protected LifecycleHelper prepareLifecycleHelper()
  +    {
  +        final LifecycleHelper lifecycleHelper = new LifecycleHelper();
  +        setupLogger( lifecycleHelper, "lifecycle" );
  +        return lifecycleHelper;
  +    }
  +
  +    protected final void startupAllComponents()
  +        throws Exception
  +    {
  +        //final String[] order = DependencyGraph.walkGraph( true, components );
  +        //processComponents( true, order );
  +    }
  +
  +    protected final void shutdownAllComponents()
  +        throws Exception
  +    {
  +//        final String[] order = DependencyGraph.walkGraph( false, components );
  +//        processComponents( false, order );
  +    }
  +
  +    protected final void startupComponent( final String name )
  +        throws Exception
  +    {
  +//        final String[] order = DependencyGraph.walkGraph( false, components );
  +//        processComponents( false, order );
  +    }
  +
  +    protected final void shutdownComponent( final String name )
  +        throws Exception
  +    {
  +    }
  +
  +    /**
  +     * Process a whole assembly through a lifecycle phase
  +     * (ie startup or shutdown). The components should be processed
  +     * in order specified by the dependency graph.
  +     *
  +     * @param startup true if application startup phase, false if shutdown phase
  +     * @param order
  +     * @throws Exception if there is error processing any of the components
  +     *         through the phases
  +     */
  +    private void processComponents( final boolean startup,
  +                                    final String[] order )
  +        throws Exception
  +    {
  +        processComponentsNotice( order, startup );
  +
  +        for( int i = 0; i < order.length; i++ )
  +        {
  +            processComponent( order[ i ], startup );
  +        }
  +    }
  +
  +    /**
  +     * Process a component through a lifecycle phase
  +     * (ie startup or shutdown). If it is startup phase then
  +     * it is expected that all the providers for the components
  +     * dependencies have been process. If it is the shutdown phase
  +     * it is expected that all of the consumers of services provided
  +     * by this component have already been shutdown.
  +     *
  +     * @param name the name of the component
  +     * @param startup true if application startup phase, false if shutdown phase
  +     * @throws Exception if there is error processing any of the components
  +     *         through the phases
  +     */
  +    private void processComponent( final String name,
  +                                   final boolean startup )
  +        throws Exception
  +    {
  +        processComponentNotice( startup, name, false );
  +
  +        try
  +        {
  +            final ComponentEntry entry =
  +                (ComponentEntry)m_entrys.get( name );
  +            if( startup )
  +            {
  +                final Object object =
  +                    m_lifecycleHelper.startup( name,
  +                                               entry,
  +                                               m_resourceProvider );
  +                entry.setObject( object );
  +            }
  +            else
  +            {
  +                final Object object = entry.getObject();
  +                entry.setObject( null );
  +                m_lifecycleHelper.shutdown( name, object );
  +            }
  +        }
  +        catch( final Exception e )
  +        {
  +            final String message =
  +                REZ.getString( "app.error.run-phase",
  +                               startup ? "0":"1",
  +                               name,
  +                               e.getMessage() );
  +            getLogger().error( message, e );
  +            throw e;
  +        }
  +
  +        processComponentNotice( startup, name, true );
  +    }
  +
  +    /**
  +     * Log message describing the number of components
  +     * the phase in and the order in which they will be
  +     * processed
  +     *
  +     * @param order the order the components will be processed in
  +     * @param startup true if application startup phase, false if shutdown phase
  +     */
  +    private void processComponentsNotice( final String[] order,
  +                                          final boolean startup )
  +    {
  +
  +        if( getLogger().isInfoEnabled() )
  +        {
  +            final Integer count = new Integer( order.length );
  +            final List pathList = Arrays.asList( order );
  +            final String message =
  +                REZ.getString( "components-processing",
  +                               count,
  +                               startup ? "0":"1",
  +                               pathList );
  +            getLogger().info( message );
  +        }
  +    }
   
  -    protected abstract Object getContextValue( String name, Object entry );
  +    /**
  +     * Log processing of component.
  +     *
  +     * @param name the name of component processing
  +     * @param startup true if application startup phase, false if shutdown phase
  +     */
  +    private void processComponentNotice( final boolean startup,
  +                                         final String name,
  +                                         final boolean completed )
  +    {
  +        if( getLogger().isDebugEnabled() )
  +        {
  +            final String key =
  +                completed ? "processed-component": "process-component";
  +            final String message =
  +                REZ.getString( key,
  +                               startup ? "0":"1",
  +                               name );
  +            getLogger().debug( message );
  +        }
  +    }
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/containerkit/src/java/org/apache/excalibur/containerkit/kernel/ComponentEntry.java
  
  Index: ComponentEntry.java
  ===================================================================
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included  with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.excalibur.containerkit.kernel;
  
  import org.apache.excalibur.containerkit.metadata.ComponentMetaData;
  import org.apache.avalon.framework.configuration.Configuration;
  
  /**
   * This is the structure that Components are contained within when
   * loaded into Container.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/06/18 08:13:18 $
   */
  public class ComponentEntry
  {
      /**
       * The {@link ComponentMetaData} that describes
       * this component.
       */
      private final ComponentMetaData m_metaData;
  
      /**
       * The instance of this component.
       */
      private Object m_object;
  
      /**
       * The configuration for component.
       * Should be null if component does not implement Configurable.
       */
      private Configuration m_configuration;
  
      public ComponentEntry( final ComponentMetaData metaData )
      {
          m_metaData = metaData;
      }
  
      public String getName()
      {
          return getMetaData().getName();
      }
  
      public ComponentMetaData getMetaData()
      {
          return m_metaData;
      }
  
      public Configuration getConfiguration()
      {
          return m_configuration;
      }
  
      public void setConfiguration( final Configuration configuration )
      {
          m_configuration = configuration;
      }
  
      public Object getObject()
      {
          return m_object;
      }
  
      public void setObject( final Object object )
      {
          m_object = object;
      }
  }
  
  
  

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