cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: rev 56221 - cocoon/trunk/src/core/java/org/apache/cocoon/core/container
Date Mon, 01 Nov 2004 09:57:38 GMT
Author: cziegeler
Date: Mon Nov  1 01:57:38 2004
New Revision: 56221

Modified:
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/PoolableComponentHandler.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/SingleThreadedComponentHandler.java
   cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ThreadSafeComponentHandler.java
Log:
PoolableHandler can pool plain objects now
Remove unused code
Clean up exception messages

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractComponentHandler.java
Mon Nov  1 01:57:38 2004
@@ -236,4 +236,20 @@
             this.logger.debug( "ThreadSafeComponentHandler initialized for: " + this.factory.getCreatedClass().getName()
);
         }
     }
+    
+    /**
+     * Decommission a component
+     * @param component Object to be decommissioned
+     */
+    protected void decommission( final Object component ) {
+        try {
+            this.factory.decommission( component );
+        } catch( final Exception e ) {
+            if( this.logger.isWarnEnabled() ) {
+                this.logger.warn( "Error decommissioning component: "
+                    + this.factory.getCreatedClass().getName(), e );
+            }
+        }
+    }
+    
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/AbstractServiceManager.java
Mon Nov  1 01:57:38 2004
@@ -154,9 +154,9 @@
 
             throw new ConfigurationException( message, ce );
         } catch( final Exception e ) {
-            final String message = "Unexpected exception for role: " + role;
+            final String message = "Unexpected exception for role [" + role + "]";
             if( this.getLogger().isErrorEnabled() ) {
-                this.getLogger().error( "Unexpected exception for role: " + role, e );
+                this.getLogger().error( message, e );
             }
             throw new ConfigurationException( message, e );
         }        

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceManager.java
Mon Nov  1 01:57:38 2004
@@ -124,9 +124,9 @@
                     } catch (ServiceException se) {
                         throw se;
                     } catch( final Exception e ) {
-                        final String message = "Could not find component";
+                        final String message = "Could not find component for role [" + role
+ "]";
                         if( this.getLogger().isDebugEnabled() ) {
-                            this.getLogger().debug( message + " for role: " + role, e );
+                            this.getLogger().debug( message, e );
                         }
                         throw new ServiceException( role, message, e );
                     }
@@ -140,9 +140,9 @@
         }
 
         if( handler == null ) {
-            final String message = "Could not find component";
+            final String message = "Could not find component for role: [" + role + "]";
             if( this.getLogger().isDebugEnabled() ) {
-                this.getLogger().debug( message + " for role: " + role );
+                this.getLogger().debug( message );
             }
             throw new ServiceException( role, message );
         }
@@ -160,19 +160,20 @@
                 // Rethrow instead of wrapping a ServiceException with another one
                 throw ce;
             } catch( final Exception e ) {
-                final String message = "Could not access the Component";
+                final String message = "Could not access the component for role [" + role
+ "]";
                 if( this.getLogger().isDebugEnabled() ) {
-                    this.getLogger().debug( message + " for role [" + role + "]", e );
+                    this.getLogger().debug( message, e );
                 }
 
                 throw new ServiceException( role, message, e );
             }
         } catch ( ServiceException se) {
+            // Rethrow insteand of wrapping it again
             throw se;
         } catch( final Exception e ) {
-            final String message = "Could not access the Component";
+            final String message = "Could not access the component for role [" + role + "]";
             if( this.getLogger().isDebugEnabled() ) {
-                this.getLogger().debug( message + " for role [" + role + "]", e );
+                this.getLogger().debug( message, e );
             }
 
             throw new ServiceException( role, message, e );

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/CocoonServiceSelector.java
Mon Nov  1 01:57:38 2004
@@ -51,8 +51,8 @@
     /** The role of this selector. Set in <code>configure()</code>. */
     protected String roleName;
 
-    /** The default hint */
-    protected String defaultHint;
+    /** The default key */
+    protected String defaultKey;
 
     /** Create the selector */
     public CocoonServiceSelector() {
@@ -64,36 +64,39 @@
      */
     public Object select( Object hint )
     throws ServiceException {
+        final String key;
+        if (hint == null) {
+            key = this.defaultKey;
+        } else {
+            key = hint.toString();
+        }
+
         if( !this.initialized ) {
             if( this.getLogger().isWarnEnabled() ) {
-                this.getLogger().warn( "Looking up component on an uninitialized ComponentLocator
"
-                    + "with hint [" + hint + "]" );
+                this.getLogger().warn( "Selecting a component on an uninitialized service
selector "
+                    + "with key [" + key + "]" );
             }
         }
 
         if( this.disposed ) {
             throw new IllegalStateException(
-                "You cannot select a Component from a disposed ServiceSelector" );
-        }
-
-        if (hint == null) {
-            hint = this.defaultHint;
+                "You cannot select a component from a disposed service selector." );
         }
 
-        AbstractComponentHandler handler = (AbstractComponentHandler)this.componentHandlers.get(
hint );
+        AbstractComponentHandler handler = (AbstractComponentHandler)this.componentHandlers.get(
key );
 
         // Retrieve the instance of the requested component
         if( null == handler ) {
             // Doesn't exist here : try in parent selector
             if ( this.parentSelector != null ) {
-                return this.parentSelector.select(hint);                
+                return this.parentSelector.select(key);                
             }
             final String message = this.roleName
-                + ": ServiceSelector could not find the component for hint [" + hint + "]";
+                + ": service selector could not find the component for key [" + key + "]";
             if( this.getLogger().isDebugEnabled() ) {
                 this.getLogger().debug( message );
             }
-            throw new ServiceException( hint.toString(), message );
+            throw new ServiceException( key, message );
         }
 
         Object component = null;
@@ -105,25 +108,25 @@
             throw ce;
         } catch( final Exception e ) {
             final String message = this.roleName
-                + ": ServiceSelector could not access the Component for hint [" + hint +
"]";
+                + ": service selector could not access the component for key [" + key + "]";
 
             if( this.getLogger().isDebugEnabled() ) {
                 this.getLogger().debug( message, e );
             }
-            throw new ServiceException( hint.toString(), message, e );
+            throw new ServiceException( key, message, e );
         }
 
         if( null == component ) {
             // Doesn't exist here : try in parent selector
             if ( this.parentSelector != null ) {
-                component = this.parentSelector.select(hint);
+                component = this.parentSelector.select(key);
             } else {
                 final String message = this.roleName
-                    + ": ServiceSelector could not find the component for hint [" + hint
+ "]";
+                    + ": service selector could not find the component for key [" + key +
"]";
                 if( this.getLogger().isDebugEnabled() ) {
                     this.getLogger().debug( message );
                 }
-                throw new ServiceException( hint.toString(), message );
+                throw new ServiceException( key, message );
             }
         }
 
@@ -136,24 +139,27 @@
      * @see org.apache.avalon.framework.service.ServiceSelector#isSelectable(java.lang.Object)
      */
     public boolean isSelectable( Object hint ) {
-        if( !this.initialized ) return false;
-        if( this.disposed ) return false;
-
+        final String key;
         if (hint == null) {
-            hint = this.defaultHint;
+            key = this.defaultKey;
+        } else {
+            key = hint.toString();
         }
 
+        if( !this.initialized ) return false;
+        if( this.disposed ) return false;
+
         boolean exists = false;
 
         try {
-            AbstractComponentHandler handler = (AbstractComponentHandler)this.componentHandlers.get(
hint );
+            AbstractComponentHandler handler = (AbstractComponentHandler)this.componentHandlers.get(
key );
             exists = (handler != null);
         } catch( Throwable t ) {
             // We can safely ignore all exceptions
         }
 
         if ( !exists && this.parentSelector != null ) {
-            exists = this.parentSelector.isSelectable( hint );
+            exists = this.parentSelector.isSelectable( key );
         }
         return exists;
     }
@@ -218,8 +224,8 @@
     throws ConfigurationException {
         this.roleName = getRoleName(config);
 
-        // Get default hint
-        this.defaultHint = config.getAttribute(this.getDefaultHintAttributeName(), null);
+        // Get default key
+        this.defaultKey = config.getAttribute(this.getDefaultKeyAttributeName(), null);
 
         // Add components
         String compInstanceName = getComponentInstanceName();
@@ -260,7 +266,7 @@
                 throw new ConfigurationException(message);
             }
             
-            this.addComponent( className, hint, instance );
+            this.addComponent( className, hint.toString(), instance );
         }
     }
 
@@ -334,7 +340,7 @@
     }
 
     /** Add a new component to the manager.
-     * @param hint the hint name for the new component.
+     * @param hint the key for the new component.
      * @param component the class of this component.
      * @param configuration the configuration for this component.
      */
@@ -342,9 +348,10 @@
                               final Class component,
                               final Configuration configuration )
     throws ServiceException {
+        final String key = hint.toString();
         if( this.initialized ) {
-            throw new ServiceException( hint.toString(),
-                "Cannot add components to an initialized ServiceSelector", null );
+            throw new ServiceException( key,
+                "Cannot add components to an initialized service selector" );
         }
 
         try {
@@ -353,22 +360,22 @@
                                                                   this.serviceManager);
 
             handler.initialize();
-            this.componentHandlers.put( hint, handler );
+            this.componentHandlers.put( key, handler );
 
             if( this.getLogger().isDebugEnabled() ) {
                 this.getLogger().debug(
-                    "Adding " + component.getName() + " for hint [" + hint.toString() + "]"
);
+                    "Adding " + component.getName() + " for key [" + key + "]" );
             }
         } catch (ServiceException se) {
             throw se;
         } catch( final Exception e ) {
             final String message =
-                "Could not set up Component for hint [ " + hint + "]";
+                "Could not set up component for key [ " + key + "]";
             if( this.getLogger().isErrorEnabled() ) {
                 this.getLogger().error( message, e );
             }
 
-            throw new ServiceException( hint.toString(), message, e );
+            throw new ServiceException(key, message, e );
         }
     }
 
@@ -397,14 +404,14 @@
     }
 
     /**
-     * Get the name of the attribute giving the default hint to use if
+     * Get the name of the attribute giving the default key to use if
      * none is given. The default here is "default", but this can be
      * overriden in subclasses. If this method returns <code>null</code>,
-     * no default hint can be specified.
+     * no default key can be specified.
      *
      * @return "<code>default</code>", but can be changed by subclasses
      */
-    protected String getDefaultHintAttributeName() {
+    protected String getDefaultKeyAttributeName() {
         return "default";
     }
     
@@ -422,28 +429,6 @@
         }
 
         return name;
-    }
-
-    /**
-     * Get the default hint, if any for this selector.
-     */
-    public String getDefaultHint() {
-        return this.defaultHint;
-    }
-
-    /**
-     * Does this selector declare a given hint? Check is performed on the components declared
for this
-     * selector only, and <strong>not</strong> those potentially inherited from
the parent selector.
-     * 
-     * @param hint the hint to check for
-     * @return <code>true</code> if this selector has the specified hint
-     */
-    protected boolean hasDeclaredComponent(Object hint) {
-        if (hint == null) {
-            hint = this.defaultHint;
-        }
-
-        return this.isSelectable(hint);
     }
 
     /**

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java	(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ComponentFactory.java	Mon
Nov  1 01:57:38 2004
@@ -20,13 +20,11 @@
 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.context.Contextualizable;
 import org.apache.avalon.framework.logger.LogEnabled;
 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.avalon.framework.service.Serviceable;
 
 /**
  * Factory for Avalon based components.
@@ -114,14 +112,8 @@
             }
         }
 
-
-        if( component instanceof Contextualizable ) {
-            ContainerUtil.contextualize( component, this.context );
-        }
-
-        if( component instanceof Serviceable ) {
-            ContainerUtil.service( component, this.serviceManager );
-        }
+        ContainerUtil.contextualize( component, this.context );
+        ContainerUtil.service( component, this.serviceManager );
 
         if ( component instanceof CocoonServiceSelector ) {
             ((CocoonServiceSelector)component).setLoggerManager(this.loggerManager);

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/PoolableComponentHandler.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/PoolableComponentHandler.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/PoolableComponentHandler.java
Mon Nov  1 01:57:38 2004
@@ -19,7 +19,6 @@
 import java.util.Iterator;
 import java.util.LinkedList;
 
-import org.apache.avalon.excalibur.pool.Poolable;
 import org.apache.avalon.excalibur.pool.Recyclable;
 import org.apache.avalon.framework.configuration.Configuration;
 import org.apache.avalon.framework.logger.Logger;
@@ -115,10 +114,10 @@
         synchronized( this.semaphore ) {
             // Remove objects in the ready list.
             for( Iterator iter = this.ready.iterator(); iter.hasNext(); ) {
-                Poolable poolable = (Poolable)iter.next();
+                Object poolable = (Object)iter.next();
                 iter.remove();
                 this.readySize--;
-                permanentlyRemovePoolable( poolable );
+                this.permanentlyRemovePoolable( poolable );
             }
 
             if( ( this.size > 0 ) && this.logger.isDebugEnabled() ) {
@@ -136,26 +135,7 @@
      */
     protected void permanentlyRemovePoolable( Object poolable ) {
         this.size--;
-        this.removePoolable( poolable );
-    }
-
-    /**
-     * Called when an object is being removed permanently from the pool.
-     * This is the method to override when you need to enforce destructional
-     * policies.
-     * <p>
-     * This method is only called by threads that have m_semaphore locked.
-     *
-     * @param poolable Poolable to be completely removed from the pool.
-     */
-    protected void removePoolable( Object poolable ) {
-        try {
-            this.factory.decommission( poolable );
-        } catch( Exception e ) {
-            if( this.logger.isDebugEnabled() ) {
-                this.logger.debug( "Error decommissioning object", e );
-            }
-        }
+        this.decommission( poolable );
     }
 
     /**
@@ -174,7 +154,7 @@
             // Look for a Poolable at the end of the m_ready list
             if( this.readySize > 0 ){
                 // A poolable is ready and waiting in the pool
-                poolable = (Poolable)this.ready.removeLast();
+                poolable = this.ready.removeLast();
                 this.readySize--;
             } else {
                 // Create a new poolable.  May throw an exception if the poolable can not
be

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/SingleThreadedComponentHandler.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/SingleThreadedComponentHandler.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/SingleThreadedComponentHandler.java
Mon Nov  1 01:57:38 2004
@@ -59,15 +59,7 @@
      * @param component Component to be be put/released back to the handler.
      */
     protected void doPut( final Object component ) {
-        try {
-            this.factory.decommission( component );
-        } catch( final Exception e ) {
-            if( this.logger.isWarnEnabled() )
-            {
-                this.logger.warn( "Error decommissioning component: "
-                    + this.factory.getCreatedClass().getName(), e );
-            }
-        }
+        this.decommission( component );
     }
 
 }

Modified: cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ThreadSafeComponentHandler.java
==============================================================================
--- cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ThreadSafeComponentHandler.java
(original)
+++ cocoon/trunk/src/core/java/org/apache/cocoon/core/container/ThreadSafeComponentHandler.java
Mon Nov  1 01:57:38 2004
@@ -71,15 +71,9 @@
      * Dispose of the ComponentHandler and any associated Pools and Factories.
      */
     public void dispose() {
-        try {
-            this.factory.decommission( this.instance );
-            this.instance = null;
-        } catch( final Exception e ) {
-            if( this.logger.isWarnEnabled() ) {
-                this.logger.warn( "Error decommissioning component: " +
-                                  this.factory.getCreatedClass().getName(), e );
-            }
-        }
+        this.decommission( this.instance );
+        this.instance = null;
+
         super.dispose();
     }
 }

Mime
View raw message