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-phoenix/src/java/org/apache/avalon/phoenix/frontends CLIMain.java PhoenixServlet.java
Date Sat, 11 May 2002 06:32:41 GMT
donaldp     02/05/10 23:32:41

  Modified:    src/java/org/apache/avalon/phoenix/components/application
                        LifecycleHelper.java
               src/java/org/apache/avalon/phoenix/components/embeddor
                        DefaultEmbeddor.java
               src/java/org/apache/avalon/phoenix/components/kernel
                        DefaultKernel.java
               src/java/org/apache/avalon/phoenix/frontends CLIMain.java
                        PhoenixServlet.java
  Added:       src/java/org/apache/avalon/phoenix/components
                        ComponentUtil.java
  Removed:     src/java/org/apache/avalon/phoenix/components
                        LifecycleUtil.java
  Log:
  LifecycleUtil renamed to ComponentUtil in preparation for adding a
  generic LifecycleUtil or LifecycleHelper.
  
  Revision  Changes    Path
  1.1                  jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/ComponentUtil.java
  
  Index: ComponentUtil.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.avalon.phoenix.components;
  
  import org.apache.avalon.framework.activity.Disposable;
  import org.apache.avalon.framework.activity.Initializable;
  import org.apache.avalon.framework.activity.Startable;
  import org.apache.avalon.framework.component.ComponentException;
  import org.apache.avalon.framework.component.ComponentManager;
  import org.apache.avalon.framework.component.Composable;
  import org.apache.avalon.framework.configuration.Configurable;
  import org.apache.avalon.framework.configuration.Configuration;
  import org.apache.avalon.framework.configuration.ConfigurationException;
  import org.apache.avalon.framework.context.Context;
  import org.apache.avalon.framework.context.ContextException;
  import org.apache.avalon.framework.context.Contextualizable;
  import org.apache.avalon.framework.logger.LogEnabled;
  import org.apache.avalon.framework.logger.Loggable;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.parameters.ParameterException;
  import org.apache.avalon.framework.parameters.Parameterizable;
  import org.apache.avalon.framework.parameters.Parameters;
  import org.apache.avalon.framework.service.ServiceException;
  import org.apache.avalon.framework.service.ServiceManager;
  import org.apache.avalon.framework.service.Serviceable;
  
  /**
   * Utility class that makes it easier to transfer
   * a component throught it's lifecycle stages.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   * @version $Revision: 1.1 $ $Date: 2002/05/11 06:32:41 $
   * @todo Add a MissingResource exception and make all the method
   *       throw that if supplied resource (logger, context, etc)
   *       is null.
   */
  public final class ComponentUtil
  {
      /**
       * Private constructor to block instantiation.
       */
      private ComponentUtil()
      {
      }
  
      /**
       * Run specified object through shutdown lifecycle stages
       * (Stop and Dispose).
       *
       * @param object the object to shutdown
       * @throws Exception if there is a problem stoppping object
       */
      public static void shutdown( final Object object )
          throws Exception
      {
          stop( object );
          dispose( object );
      }
  
      /**
       * Supply specified object with Logger if it implements the
       * {@link Loggable} interface.
       *
       * @param object the object to Start
       * @param logger the logger to enable component with. May be null
       *        in which case the specified object must not implement Loggable.
       * @throws Exception if the object is Loggable but Logger is null
       * @deprecated Note that this is deprecated as it uses the deprecated
       *             Loggable interface.
       */
      public static void setupLoggable( final Object object,
                                        final org.apache.log.Logger logger )
          throws Exception
      {
          if( object instanceof Loggable )
          {
              if( null == logger )
              {
                  final String message = "Missing logger";
                  throw new Exception( message );
              }
              ( (Loggable)object ).setLogger( logger );
          }
      }
  
      /**
       * Supply specified object with ServiceManager if it implements the
       * {@link Serviceable} interface.
       *
       * @param object the object to Start
       * @param logger the logger to enable component with. May be null
       *        in which case the specified object must not implement LogEnabled.
       * @throws Exception if the object is LogEnabled but Logger is null
       */
      public static void logEnable( final Object object,
                                    final Logger logger )
          throws Exception
      {
          if( object instanceof LogEnabled )
          {
              if( null == logger )
              {
                  final String message = "Missing logger";
                  throw new Exception( message );
              }
              ( (LogEnabled)object ).enableLogging( logger );
          }
      }
  
      /**
       * Supply specified object with a Context object if it implements the
       * {@link Contextualizable} interface.
       *
       * @param object the object to contextualize
       * @param context the context object to use for object.
       *        May be null in which case the specified object must not
       *        implement Contextualizable.
       * @throws ContextException if there is a problem contextualizing object,
       *         or the object is Contextualizable but context is null
       */
      public static void contextualize( final Object object,
                                        final Context context )
          throws ContextException
      {
          if( object instanceof Contextualizable )
          {
              if( null == context )
              {
                  final String message = "Missing context";
                  throw new ContextException( message );
              }
              ( (Contextualizable)object ).contextualize( context );
          }
      }
  
      /**
       * Supply specified object with ServiceManager if it implements the
       * {@link Serviceable} interface.
       *
       * @param object the object to service
       * @param serviceManager the serviceManager object to use for object.
       *        May be null in which case the specified object must not
       *        implement Serviceable.
       * @throws ServiceException if there is a problem servicing object,
       *         or the object is Servicable but ServiceManager is null
       */
      public static void service( final Object object,
                                  final ServiceManager serviceManager )
          throws ServiceException
      {
          if( object instanceof Serviceable )
          {
              if( null == serviceManager )
              {
                  final String message = "Missing ServiceManager";
                  throw new ServiceException( message );
              }
              ( (Serviceable)object ).service( serviceManager );
          }
      }
  
      /**
       * Supply specified object with ComponentManager if it implements the
       * {@link Composable} interface.
       *
       * @param object the object to compose
       * @param componentManager the ComponentManager object to use for object.
       *        May be null in which case the specified object must not
       *        implement Composable.
       * @throws ComponentException if there is a problem composing object,
       *         or the object is Composable but ComponentManager is null
       * @deprecated compose() is no longer the preferred method via
       *             which components will be supplied with Components. Please
       *             Use service() from Serviceable instead.
       */
      public static void compose( final Object object,
                                  final ComponentManager componentManager )
          throws ComponentException
      {
          if( object instanceof Composable )
          {
              if( null == componentManager )
              {
                  final String message = "Missing ComponentManager";
                  throw new ComponentException( message );
              }
              ( (Composable)object ).compose( componentManager );
          }
      }
  
      /**
       * Configure specified object if it implements the
       * {@link Configurable} interface.
       *
       * @param object the object to Start
       * @param configuration the configuration object to use during
       *        configuration. May be null in which case the specified object
       *        must not implement Configurable
       * @throws ConfigurationException if there is a problem Configuring object,
       *         or the object is Configurable but Configuration is null
       */
      public static void configure( final Object object,
                                    final Configuration configuration )
          throws ConfigurationException
      {
          if( object instanceof Configurable )
          {
              if( null == configuration )
              {
                  final String message = "Missing configuration";
                  throw new ConfigurationException( message );
              }
              ( (Configurable)object ).configure( configuration );
          }
      }
  
      /**
       * Parameterize specified object if it implements the
       * {@link Parameterizable} interface.
       *
       * @param object the object to Parameterize.
       * @param parameters the parameters object to use during Parameterization.
       *        May be null in which case the specified object must not
       *        implement Parameterizable.
       * @throws ParameterException if there is a problem Parameterizing object,
       *         or the object is Parameterizable but parameters is null
       */
      public static void parameterize( final Object object,
                                       final Parameters parameters )
          throws ParameterException
      {
          if( object instanceof Parameterizable )
          {
              if( null == parameters )
              {
                  final String message = "Missing parameters";
                  throw new ParameterException( message );
              }
              ( (Parameterizable)object ).parameterize( parameters );
          }
      }
  
      /**
       * Initialize specified object if it implements the
       * {@link Initializable} interface.
       *
       * @param object the object to Initialize
       * @throws Exception if there is a problem Initializing object
       */
      public static void initialize( final Object object )
          throws Exception
      {
          if( object instanceof Initializable )
          {
              ( (Initializable)object ).initialize();
          }
      }
  
      /**
       * Start specified object if it implements the
       * {@link Startable} interface.
       *
       * @param object the object to Start
       * @throws Exception if there is a problem Starting object
       */
      public static void start( final Object object )
          throws Exception
      {
          if( object instanceof Startable )
          {
              ( (Startable)object ).start();
          }
      }
  
      /**
       * Stop specified object if it implements the
       * {@link Startable} interface.
       *
       * @param object the object to stop
       * @throws Exception if there is a problem stoppping object
       */
      public static void stop( final Object object )
          throws Exception
      {
          if( object instanceof Startable )
          {
              ( (Startable)object ).stop();
          }
      }
  
      /**
       * Dispose specified object if it implements the
       * {@link Disposable} interface.
       *
       * @param object the object to dispose
       */
      public static void dispose( final Object object )
      {
          if( object instanceof Disposable )
          {
              ( (Disposable)object ).dispose();
          }
      }
  }
  
  
  
  1.35      +14 -14    jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/LifecycleHelper.java
  
  Index: LifecycleHelper.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/application/LifecycleHelper.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- LifecycleHelper.java	10 May 2002 10:49:29 -0000	1.34
  +++ LifecycleHelper.java	11 May 2002 06:32:41 -0000	1.35
  @@ -36,7 +36,7 @@
   import org.apache.avalon.phoenix.BlockContext;
   import org.apache.avalon.phoenix.BlockEvent;
   import org.apache.avalon.phoenix.BlockListener;
  -import org.apache.avalon.phoenix.components.LifecycleUtil;
  +import org.apache.avalon.phoenix.components.ComponentUtil;
   import org.apache.avalon.phoenix.interfaces.Application;
   import org.apache.avalon.phoenix.interfaces.ApplicationContext;
   import org.apache.avalon.phoenix.metadata.BlockListenerMetaData;
  @@ -130,13 +130,13 @@
           if( listener instanceof LogEnabled )
           {
               final Logger logger = new LogKitLogger( m_context.getLogger( name ) );
  -            LifecycleUtil.logEnable( listener, logger );
  +            ComponentUtil.logEnable( listener, logger );
           }
   
           if( listener instanceof Configurable )
           {
               final Configuration configuration = getConfiguration( name, TYPE_LISTENER );
  -            LifecycleUtil.configure( listener, configuration );
  +            ComponentUtil.configure( listener, configuration );
           }
   
           // As ApplicationListners are BlockListeners then this is applicable for all
  @@ -214,7 +214,7 @@
               {
                   notice( name, stage );
                   final BlockContext context = createBlockContext( name );
  -                LifecycleUtil.contextualize( block, context );
  +                ComponentUtil.contextualize( block, context );
               }
   
               //Composition stage
  @@ -223,13 +223,13 @@
               {
                   notice( name, stage );
                   final ComponentManager componentManager = createComponentManager( metaData
);
  -                LifecycleUtil.compose( block, componentManager );
  +                ComponentUtil.compose( block, componentManager );
               }
               else if( block instanceof Serviceable )
               {
                   notice( name, stage );
                   final ServiceManager manager = createServiceManager( metaData );
  -                LifecycleUtil.service( block, manager );
  +                ComponentUtil.service( block, manager );
               }
   
               //Configuring stage
  @@ -238,7 +238,7 @@
               {
                   notice( name, stage );
                   final Configuration configuration = getConfiguration( name, TYPE_BLOCK
);
  -                LifecycleUtil.configure( block, configuration );
  +                ComponentUtil.configure( block, configuration );
               }
   
               //Parameterizing stage
  @@ -249,7 +249,7 @@
                   final Parameters parameters =
                       Parameters.fromConfiguration( getConfiguration( name, TYPE_BLOCK )
);
                   parameters.makeReadOnly();
  -                LifecycleUtil.parameterize( block, parameters );
  +                ComponentUtil.parameterize( block, parameters );
               }
   
               //Initialize stage
  @@ -257,7 +257,7 @@
               if( block instanceof Initializable )
               {
                   notice( name, stage );
  -                LifecycleUtil.initialize( block );
  +                ComponentUtil.initialize( block );
               }
   
               //Start stage
  @@ -265,7 +265,7 @@
               if( block instanceof Startable )
               {
                   notice( name, stage );
  -                LifecycleUtil.start( block );
  +                ComponentUtil.start( block );
               }
   
               entry.setState( State.STARTED );
  @@ -291,13 +291,13 @@
           if( block instanceof Loggable )
           {
               notice( name, stage );
  -            LifecycleUtil.setupLoggable( block, m_context.getLogger( name ) );
  +            ComponentUtil.setupLoggable( block, m_context.getLogger( name ) );
           }
           else if( block instanceof LogEnabled )
           {
               notice( name, stage );
               final Logger logger = new LogKitLogger( m_context.getLogger( name ) );
  -            LifecycleUtil.logEnable( block, logger );
  +            ComponentUtil.logEnable( block, logger );
           }
       }
   
  @@ -336,7 +336,7 @@
               try
               {
                   entry.setState( State.STOPPING );
  -                LifecycleUtil.stop( block );
  +                ComponentUtil.stop( block );
                   entry.setState( State.STOPPED );
               }
               catch( final Throwable t )
  @@ -353,7 +353,7 @@
               try
               {
                   entry.setState( State.DESTROYING );
  -                LifecycleUtil.dispose( block );
  +                ComponentUtil.dispose( block );
               }
               catch( final Throwable t )
               {
  
  
  
  1.61      +9 -9      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java
  
  Index: DefaultEmbeddor.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/embeddor/DefaultEmbeddor.java,v
  retrieving revision 1.60
  retrieving revision 1.61
  diff -u -r1.60 -r1.61
  --- DefaultEmbeddor.java	11 May 2002 02:05:13 -0000	1.60
  +++ DefaultEmbeddor.java	11 May 2002 06:32:41 -0000	1.61
  @@ -31,7 +31,7 @@
   import org.apache.avalon.framework.service.DefaultServiceManager;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.phoenix.Constants;
  -import org.apache.avalon.phoenix.components.LifecycleUtil;
  +import org.apache.avalon.phoenix.components.ComponentUtil;
   import org.apache.avalon.phoenix.interfaces.Deployer;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
   import org.apache.avalon.phoenix.interfaces.EmbeddorMBean;
  @@ -504,13 +504,13 @@
           throws Exception
       {
           final Logger childLogger = getLogger().getChildLogger( loggerName );
  -        LifecycleUtil.logEnable( object, childLogger );
  -        LifecycleUtil.contextualize( object, m_context );
  -        LifecycleUtil.service( object, getServiceManager() );
  -        LifecycleUtil.parameterize( object, m_parameters );
  -        LifecycleUtil.configure( object, config );
  -        LifecycleUtil.initialize( object );
  -        LifecycleUtil.start( object );
  +        ComponentUtil.logEnable( object, childLogger );
  +        ComponentUtil.contextualize( object, m_context );
  +        ComponentUtil.service( object, getServiceManager() );
  +        ComponentUtil.parameterize( object, m_parameters );
  +        ComponentUtil.configure( object, config );
  +        ComponentUtil.initialize( object );
  +        ComponentUtil.start( object );
       }
   
       private void shutdownComponents()
  @@ -521,7 +521,7 @@
           {
               final Object object = m_entrys[ i ].getObject();
               if( null == object ) continue;
  -            LifecycleUtil.shutdown( object );
  +            ComponentUtil.shutdown( object );
           }
       }
   
  
  
  
  1.62      +8 -8      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java
  
  Index: DefaultKernel.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/components/kernel/DefaultKernel.java,v
  retrieving revision 1.61
  retrieving revision 1.62
  diff -u -r1.61 -r1.62
  --- DefaultKernel.java	10 May 2002 11:08:56 -0000	1.61
  +++ DefaultKernel.java	11 May 2002 06:32:41 -0000	1.62
  @@ -20,7 +20,7 @@
   import org.apache.avalon.framework.service.ServiceException;
   import org.apache.avalon.framework.service.ServiceManager;
   import org.apache.avalon.framework.service.Serviceable;
  -import org.apache.avalon.phoenix.components.LifecycleUtil;
  +import org.apache.avalon.phoenix.components.ComponentUtil;
   import org.apache.avalon.phoenix.components.application.DefaultApplication;
   import org.apache.avalon.phoenix.interfaces.Application;
   import org.apache.avalon.phoenix.interfaces.ApplicationContext;
  @@ -128,13 +128,13 @@
                       new DefaultApplication( entry.getMetaData() );
   
                   final Logger childLogger = getLogger().getChildLogger( name );
  -                LifecycleUtil.logEnable( newApp, childLogger );
  +                ComponentUtil.logEnable( newApp, childLogger );
   
                   final ApplicationContext context = createApplicationContext( entry );
                   newApp.setApplicationContext( context );
   
  -                LifecycleUtil.initialize( newApp );
  -                LifecycleUtil.start( newApp );
  +                ComponentUtil.initialize( newApp );
  +                ComponentUtil.start( newApp );
   
                   entry.setApplication( newApp );
                   application = newApp;
  @@ -175,7 +175,7 @@
           if( null != application )
           {
               entry.setApplication( null );
  -            LifecycleUtil.shutdown( application );
  +            ComponentUtil.shutdown( application );
           }
           else
           {
  @@ -219,9 +219,9 @@
                                              entry.getClassLoader(),
                                              entry.getHierarchy() );
   
  -        LifecycleUtil.logEnable( context, createContextLogger( name ) );
  -        LifecycleUtil.service( context, createServiceManager() );
  -        LifecycleUtil.configure( context, entry.getConfiguration() );
  +        ComponentUtil.logEnable( context, createContextLogger( name ) );
  +        ComponentUtil.service( context, createServiceManager() );
  +        ComponentUtil.configure( context, entry.getConfiguration() );
           return context;
       }
   
  
  
  
  1.32      +7 -7      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/CLIMain.java
  
  Index: CLIMain.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/CLIMain.java,v
  retrieving revision 1.31
  retrieving revision 1.32
  diff -u -r1.31 -r1.32
  --- CLIMain.java	10 May 2002 11:40:04 -0000	1.31
  +++ CLIMain.java	11 May 2002 06:32:41 -0000	1.32
  @@ -22,7 +22,7 @@
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.parameters.Parameters;
   import org.apache.avalon.phoenix.Constants;
  -import org.apache.avalon.phoenix.components.LifecycleUtil;
  +import org.apache.avalon.phoenix.components.ComponentUtil;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
   import org.apache.log.Hierarchy;
   import org.apache.log.LogTarget;
  @@ -178,13 +178,13 @@
               final String embeddorClassname = configuration.getAttribute( "class" );
               m_embeddor = (Embeddor)Class.forName( embeddorClassname ).newInstance();
   
  -            LifecycleUtil.logEnable( m_embeddor,
  +            ComponentUtil.logEnable( m_embeddor,
                                        createLogger( parameters ) );
  -            LifecycleUtil.contextualize( m_embeddor,
  +            ComponentUtil.contextualize( m_embeddor,
                                            new DefaultContext( data ) );
  -            LifecycleUtil.parameterize( m_embeddor, parameters );
  -            LifecycleUtil.configure( m_embeddor, configuration );
  -            LifecycleUtil.initialize( m_embeddor );
  +            ComponentUtil.parameterize( m_embeddor, parameters );
  +            ComponentUtil.configure( m_embeddor, configuration );
  +            ComponentUtil.initialize( m_embeddor );
           }
           catch( final Throwable throwable )
           {
  @@ -266,7 +266,7 @@
   
               try
               {
  -                LifecycleUtil.shutdown( m_embeddor );
  +                ComponentUtil.shutdown( m_embeddor );
               }
               catch( final Throwable throwable )
               {
  
  
  
  1.13      +6 -6      jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/PhoenixServlet.java
  
  Index: PhoenixServlet.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-phoenix/src/java/org/apache/avalon/phoenix/frontends/PhoenixServlet.java,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -r1.12 -r1.13
  --- PhoenixServlet.java	10 May 2002 11:40:04 -0000	1.12
  +++ PhoenixServlet.java	11 May 2002 06:32:41 -0000	1.13
  @@ -21,7 +21,7 @@
   import org.apache.avalon.framework.logger.LogKitLogger;
   import org.apache.avalon.framework.logger.Logger;
   import org.apache.avalon.framework.parameters.Parameters;
  -import org.apache.avalon.phoenix.components.LifecycleUtil;
  +import org.apache.avalon.phoenix.components.ComponentUtil;
   import org.apache.avalon.phoenix.components.embeddor.SingleAppEmbeddor;
   import org.apache.avalon.phoenix.interfaces.Embeddor;
   import org.apache.log.Hierarchy;
  @@ -92,10 +92,10 @@
   
               m_embeddor = (SingleAppEmbeddor)Class.forName( embeddorClassname ).newInstance();
   
  -            LifecycleUtil.logEnable( m_embeddor, createLogger( m_parameters ) );
  -            LifecycleUtil.parameterize( m_embeddor, m_parameters );
  -            LifecycleUtil.configure( m_embeddor, embeddorConf );
  -            LifecycleUtil.initialize( m_embeddor );
  +            ComponentUtil.logEnable( m_embeddor, createLogger( m_parameters ) );
  +            ComponentUtil.parameterize( m_embeddor, m_parameters );
  +            ComponentUtil.configure( m_embeddor, embeddorConf );
  +            ComponentUtil.initialize( m_embeddor );
   
               final Thread thread = new Thread( this, "Phoenix-Monitor" );
               thread.start();
  @@ -138,7 +138,7 @@
   
           try
           {
  -            LifecycleUtil.shutdown( m_embeddor );
  +            ComponentUtil.shutdown( m_embeddor );
           }
           catch( final Throwable throwable )
           {
  
  
  

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