You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by do...@apache.org on 2002/11/09 04:46:40 UTC

cvs commit: jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler AbstractComponentHandler.java ComponentHandler.java PoolableComponentHandler.java ThreadSafeComponentHandler.java

donaldp     2002/11/08 19:46:40

  Modified:    fortress/src/java/org/apache/excalibur/fortress/container
                        AbstractContainer.java
               fortress/src/java/org/apache/excalibur/fortress/handler
                        AbstractComponentHandler.java ComponentHandler.java
                        PoolableComponentHandler.java
                        ThreadSafeComponentHandler.java
  Added:       fortress/src/java/org/apache/excalibur/fortress/container/commands
                        PrepareHandlerCommand.java
  Removed:     fortress/src/java/org/apache/excalibur/fortress/container/commands
                        InitializeComponentHandlerCommand.java
  Log:
  Make it so that ComponentHandler does not implement initializable but instead has a prepare method that did much the same. That way the object does not mess with semantics of Lifecycle interfaces.
  
  Revision  Changes    Path
  1.5       +8 -9      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java
  
  Index: AbstractContainer.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/AbstractContainer.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- AbstractContainer.java	9 Nov 2002 03:19:00 -0000	1.4
  +++ AbstractContainer.java	9 Nov 2002 03:46:39 -0000	1.5
  @@ -72,8 +72,7 @@
   import org.apache.excalibur.event.Queue;
   import org.apache.excalibur.fortress.Container;
   import org.apache.excalibur.fortress.ContainerConstants;
  -import org.apache.excalibur.fortress.container.commands.DisposeComponentHandlerCommand;
  -import org.apache.excalibur.fortress.container.commands.InitializeComponentHandlerCommand;
  +import org.apache.excalibur.fortress.container.commands.PrepareHandlerCommand;
   import org.apache.excalibur.fortress.handler.ComponentHandler;
   import org.apache.excalibur.fortress.lifecycle.LifecycleExtensionManager;
   import org.apache.excalibur.fortress.lookup.FortressServiceManager;
  @@ -430,26 +429,25 @@
       public void initialize()
           throws Exception
       {
  -        Iterator i = m_components.iterator();
  -        BoundedFifoBuffer buffer = new BoundedFifoBuffer( m_components.size() );
  +        final Iterator i = m_components.iterator();
  +        final BoundedFifoBuffer buffer = new BoundedFifoBuffer( m_components.size() );
   
           while( i.hasNext() )
           {
               try
               {
                   final ComponentHandler handler = (ComponentHandler)i.next();
  -
                   if( !handler.isLazy() )
                   {
                       if( null != m_commandQueue )
                       {
                           m_commandQueue.enqueue(
  -                            new InitializeComponentHandlerCommand( handler, getLogger() )
  +                            new PrepareHandlerCommand( handler, getLogger() )
                           );
                       }
                       else
                       {
  -                        ContainerUtil.initialize( handler );
  +                        handler.prepareHandler();
                       }
                   }
                   else
  @@ -468,7 +466,8 @@
               {
                   if( getLogger().isWarnEnabled() )
                   {
  -                    getLogger().warn( "Could not initialize component", e );
  +                    final String message = "Could not initialize component";
  +                    getLogger().warn( message, e );
                   }
                   buffer.add( e );
               }
  
  
  
  1.1                  jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/container/commands/PrepareHandlerCommand.java
  
  Index: PrepareHandlerCommand.java
  ===================================================================
  /*
  
   ============================================================================
                     The Apache Software License, Version 1.1
   ============================================================================
  
   Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
  
   Redistribution and use in source and binary forms, with or without modifica-
   tion, 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 "Jakarta", "Avalon", "Excalibur" 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 (INCLU-
   DING, 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.excalibur.fortress.container.commands;
  
  import org.apache.avalon.framework.container.ContainerUtil;
  import org.apache.avalon.framework.logger.Logger;
  import org.apache.avalon.framework.logger.NullLogger;
  import org.apache.excalibur.event.command.Command;
  import org.apache.excalibur.fortress.handler.ComponentHandler;
  
  /**
   * This is the command class to initialize a ComponentHandler
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/11/09 03:46:39 $
   */
  public final class PrepareHandlerCommand implements Command
  {
      private final ComponentHandler m_handler;
      private final Logger m_logger;
  
      public PrepareHandlerCommand( final ComponentHandler handler,
                                                final Logger logger )
      {
          m_handler = handler;
          m_logger = ( null == logger ) ? new NullLogger() : logger;
      }
  
      public void execute()
          throws Exception
      {
          try
          {
              m_handler.prepareHandler();
          }
          catch( final Exception e )
          {
              if( m_logger.isErrorEnabled() )
              {
                  m_logger.error( "Could not prepare ComponentHandler", e );
              }
  
              throw e;
          }
      }
  }
  
  
  
  
  1.31      +15 -24    jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java
  
  Index: AbstractComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/AbstractComponentHandler.java,v
  retrieving revision 1.30
  retrieving revision 1.31
  diff -u -r1.30 -r1.31
  --- AbstractComponentHandler.java	9 Nov 2002 03:12:36 -0000	1.30
  +++ AbstractComponentHandler.java	9 Nov 2002 03:46:39 -0000	1.31
  @@ -73,7 +73,7 @@
    */
   public abstract class AbstractComponentHandler
       extends AbstractInstrumentable
  -    implements Initializable, Disposable, ComponentHandler
  +    implements Disposable, ComponentHandler
   {
       /**
        * The instance of the ComponentFactory that creates and disposes of the
  @@ -85,7 +85,7 @@
        * State management boolean stating whether the Handler is initialized or
        * not
        */
  -    protected boolean m_initialized = false;
  +    protected boolean m_prepared = false;
   
       /**
        * State management boolean stating whether the Handler is disposed or
  @@ -145,18 +145,6 @@
       }
   
       /**
  -     * Determines whether or not the ComponentHandler has been initialized
  -     * yet or not.
  -     *
  -     * @return <code>true</code> if the ComponentHandler has already been
  -     *         initialized.
  -     */
  -    public boolean isInitialized()
  -    {
  -        return m_initialized;
  -    }
  -
  -    /**
        * Determines whether or not the ComponentHandler has lazy initialization
        * or not.
        *
  @@ -169,17 +157,20 @@
       }
   
       /**
  -     * Initialize the ComponentHandler.
  +     * Actually prepare the handler and make it ready to
  +     * handle component access.
  +     *
  +     * @throws Exception if unable to prepare handler
        */
  -    public synchronized void initialize()
  +    public void prepareHandler()
           throws Exception
       {
  -        if( m_initialized )
  +        if( m_prepared )
           {
               return;
           }
   
  -        doInitialize();
  +        doPrepare();
   
           if( m_logger.isDebugEnabled() )
           {
  @@ -188,14 +179,14 @@
               m_logger.debug( message );
           }
   
  -        m_initialized = true;
  +        m_prepared = true;
       }
   
       /**
        * Initialize the ComponentHandler.
        * Subclasses should overide this to do their own initialization.
        */
  -    protected void doInitialize()
  +    protected void doPrepare()
           throws Exception
       {
       }
  @@ -208,9 +199,9 @@
       {
           synchronized( this )
           {
  -            if( !m_initialized )
  +            if( !m_prepared )
               {
  -                initialize();
  +                prepareHandler();
               }
           }
   
  @@ -241,7 +232,7 @@
        */
       public void put( final Object component )
       {
  -        if( !m_initialized )
  +        if( !m_prepared )
           {
               final String message =
                   "You cannot put a component in an uninitialized holder";
  
  
  
  1.17      +10 -8     jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentHandler.java
  
  Index: ComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ComponentHandler.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- ComponentHandler.java	8 Nov 2002 00:54:14 -0000	1.16
  +++ ComponentHandler.java	9 Nov 2002 03:46:39 -0000	1.17
  @@ -75,13 +75,6 @@
       };
   
       /**
  -     * Sometimes Components call other components during their initialization
  -     * process.  This is a quick test that the ComponentLocator will perform
  -     * before attempting to use the the ComponentHandler.
  -     */
  -    boolean isInitialized();
  -
  -    /**
        * Indicates whether this ComponentHandler will be initialized using a
        * <i>lazy</i> policy (ie. upon first use), or during container startup.
        *
  @@ -89,6 +82,15 @@
        * false otherwise
        */
       boolean isLazy();
  +
  +    /**
  +     * Actually prepare the handler and make it ready to
  +     * handle component access.
  +     *
  +     * @throws Exception if unable to prepare handler
  +     */
  +    void prepareHandler()
  +        throws Exception;
   
       /**
        * Gets the current reference to a Component according to the policy of
  
  
  
  1.38      +2 -2      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java
  
  Index: PoolableComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/PoolableComponentHandler.java,v
  retrieving revision 1.37
  retrieving revision 1.38
  diff -u -r1.37 -r1.38
  --- PoolableComponentHandler.java	8 Nov 2002 02:32:31 -0000	1.37
  +++ PoolableComponentHandler.java	9 Nov 2002 03:46:39 -0000	1.38
  @@ -101,7 +101,7 @@
       /**
        * Initialize the ComponentHandler.
        */
  -    protected void doInitialize()
  +    protected void doPrepare()
           throws Exception
       {
           m_pool = m_poolManager.getManagedPool( m_factory, m_poolMin );
  
  
  
  1.36      +2 -2      jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java
  
  Index: ThreadSafeComponentHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/fortress/src/java/org/apache/excalibur/fortress/handler/ThreadSafeComponentHandler.java,v
  retrieving revision 1.35
  retrieving revision 1.36
  diff -u -r1.35 -r1.36
  --- ThreadSafeComponentHandler.java	8 Nov 2002 00:33:41 -0000	1.35
  +++ ThreadSafeComponentHandler.java	9 Nov 2002 03:46:39 -0000	1.36
  @@ -89,7 +89,7 @@
       /**
        * Initialize the ComponentHandler.
        */
  -    protected void doInitialize()
  +    protected void doPrepare()
           throws Exception
       {
           m_instance = newComponent();
  
  
  

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>