You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by pr...@apache.org on 2001/03/03 17:00:40 UTC

cvs commit: xml-cocoon/src/org/apache/cocoon DefaultComponentManager.java CocoonComponentSelector.java

prussell    01/03/03 08:00:40

  Modified:    src/org/apache/cocoon Tag: xml-cocoon2
                        DefaultComponentManager.java
                        CocoonComponentSelector.java
  Log:
  Fixed lifecycle semantic, and added handling for Disposable components.
  
  Revision  Changes    Path
  No                   revision
  
  
  No                   revision
  
  
  1.1.2.23  +17 -3     xml-cocoon/src/org/apache/cocoon/Attic/DefaultComponentManager.java
  
  Index: DefaultComponentManager.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/DefaultComponentManager.java,v
  retrieving revision 1.1.2.22
  retrieving revision 1.1.2.23
  diff -u -r1.1.2.22 -r1.1.2.23
  --- DefaultComponentManager.java	2001/02/28 17:40:25	1.1.2.22
  +++ DefaultComponentManager.java	2001/03/03 16:00:35	1.1.2.23
  @@ -24,6 +24,7 @@
   import org.apache.avalon.ThreadSafe;
   import org.apache.avalon.Poolable;
   import org.apache.avalon.Recyclable;
  +import org.apache.avalon.Disposable;
   import org.apache.avalon.Configurable;
   import org.apache.avalon.Configuration;
   import org.apache.avalon.Composer;
  @@ -41,7 +42,7 @@
   
   /** Default component manager for Cocoon's non sitemap components.
    * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
  - * @version CVS $Revision: 1.1.2.22 $ $Date: 2001/02/28 17:40:25 $
  + * @version CVS $Revision: 1.1.2.23 $ $Date: 2001/03/03 16:00:35 $
    */
   public class DefaultComponentManager implements ComponentManager, Loggable, Configurable, Contextualizable {
   
  @@ -295,14 +296,27 @@
       }
   
       public void release(Component component) {
  +        if (component instanceof Disposable) {
  +            try { 
  +                ((Disposable) component).dispose();
  +            } catch ( Exception e ) {
  +                this.log.warn(
  +                    "Exception while disposing of an instance of " + component.getClass().getName() + ".",
  +                    e
  +                );
  +            }
  +        }
  +        
  +        if (component instanceof Recyclable) {
  +            ((Recyclable) component).recycle();
  +        }
  +        
           if (component instanceof Poolable) {
               ComponentPool pool = (ComponentPool) pools.get(component.getClass());
   
               if (pool != null) {
                   pool.put((Poolable) component);
               }
  -        } else if (component instanceof Recyclable) {
  -            ((Recyclable) component).recycle();
           }
       }
   
  
  
  
  1.1.2.26  +18 -3     xml-cocoon/src/org/apache/cocoon/Attic/CocoonComponentSelector.java
  
  Index: CocoonComponentSelector.java
  ===================================================================
  RCS file: /home/cvs/xml-cocoon/src/org/apache/cocoon/Attic/CocoonComponentSelector.java,v
  retrieving revision 1.1.2.25
  retrieving revision 1.1.2.26
  diff -u -r1.1.2.25 -r1.1.2.26
  --- CocoonComponentSelector.java	2001/03/01 15:45:26	1.1.2.25
  +++ CocoonComponentSelector.java	2001/03/03 16:00:36	1.1.2.26
  @@ -28,6 +28,7 @@
   import org.apache.avalon.SingleThreaded;
   import org.apache.avalon.ThreadSafe;
   import org.apache.avalon.Poolable;
  +import org.apache.avalon.Disposable;
   import org.apache.avalon.Configurable;
   import org.apache.avalon.Configuration;
   import org.apache.avalon.Composer;
  @@ -43,7 +44,7 @@
   /** Default component manager for Cocoon's non sitemap components.
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
    * @author <a href="mailto:paul@luminas.co.uk">Paul Russell</a>
  - * @version CVS $Revision: 1.1.2.25 $ $Date: 2001/03/01 15:45:26 $
  + * @version CVS $Revision: 1.1.2.26 $ $Date: 2001/03/03 16:00:36 $
    */
   public class CocoonComponentSelector implements Contextualizable, ComponentSelector, Composer, Configurable, ThreadSafe, Loggable {
       protected Logger log;
  @@ -259,6 +260,21 @@
       }
   
       public void release(Component component) {
  +        if (component instanceof Disposable) {
  +            try {
  +                ((Disposable) component).dispose();
  +            } catch (Exception e) {
  +                this.log.warn(
  +                    "Could not dispose of instance of component " + component.getClass().getName() + ".",
  +                    e
  +                );
  +            }
  +        }
  +        
  +        if (component instanceof Recyclable) {
  +            ((Recyclable) component).recycle();
  +        }
  +        
           if (component instanceof Poolable) {
               ComponentPool pool = (ComponentPool) pools.get(component.getClass());
   
  @@ -267,9 +283,8 @@
               } else {
                   log.debug("Could not find pool for:" + component.getClass());
               }
  -        } else if (component instanceof Recyclable) {
  -            ((Recyclable) component).recycle();
           }
  +
       }
   
       /** Configure a new component.
  
  
  

Re: cvs commit: xml-cocoon/src/org/apache/cocoon DefaultComponentManager.java CocoonComponentSelector.java

Posted by Paul Russell <pr...@apache.org>.
* Berin Loritsch (bloritsch@apache.org) wrote :
> The release() method is a Composer's way of stating that "I am done
> using this Component".  It does NOT mean that the Component should be
> destroyed.  This could cause dire issues with Components that are both
> ThreadSafe and Disposable.  When the ComponentManager/Selector is
> finally disposed, it should call those End of Life events for the
> housed Components.

Argh. Good point. Will fix if you haven't.

> If a Component is simply Recyclable, but not Poolable (I think this is
> impossible), then we should explicitly call recycle().

That's impossible, hence my change -- misunderstood what your code was
attempting to do. Again, will fix if you haven't already. (not got that
far through my mail yet)


P.

Cocoon Components (was Re: cvs commit: xml-cocoon/src/org/apache/cocoon DefaultComponentManager.java CocoonComponentSelector.java)

Posted by Berin Loritsch <bl...@apache.org>.
Berin Loritsch wrote:
> 
> > > Right, this now fixed. Sorry about that. Is there any documentation
> > > anywhere about who is actually _responsible_ for maintaining the
> > > lifecycle of these components?

The new (temporary) location for this documentation is
http://jakarta.apache.org/avalon.new/

It will become the main documentation when the links are fully tested.

Re: cvs commit: xml-cocoon/src/org/apache/cocoon DefaultComponentManager.java CocoonComponentSelector.java

Posted by Berin Loritsch <bl...@apache.org>.
> > * Berin Loritsch (bloritsch@apache.org) wrote :
> > > WARNING! WARNING! WARNING!
> >
> > Right, this now fixed. Sorry about that. Is there any documentation
> > anywhere about who is actually _responsible_ for maintaining the
> > lifecycle of these components?
> 
> The Avalon docs (now at http://jakarta.apache.org/avalon)
> State that the entity (class/component) that instantiated the object is
> responsible
> for managing it's lifecycle.

Oops.  it USED to say that.  It looks like not all the documentation
was added to the new site.  I sent a message to the Avalon developers
list asking why this is.  If only I had 48 hours a day.... I might be able
to get some real stuff done then!


Re: cvs commit: xml-cocoon/src/org/apache/cocoon DefaultComponentManager.java CocoonComponentSelector.java

Posted by Berin Loritsch <bl...@apache.org>.
----- Original Message -----
From: Paul Russell <pr...@apache.org>
To: <co...@xml.apache.org>
Sent: Saturday, March 03, 2001 6:32 PM
Subject: Re: cvs commit: xml-cocoon/src/org/apache/cocoon
DefaultComponentManager.java CocoonComponentSelector.java


> * Berin Loritsch (bloritsch@apache.org) wrote :
> > WARNING! WARNING! WARNING!
>
> Right, this now fixed. Sorry about that. Is there any documentation
> anywhere about who is actually _responsible_ for maintaining the
> lifecycle of these components?

The Avalon docs (now at http://jakarta.apache.org/avalon)
State that the entity (class/component) that instantiated the object is
responsible
for managing it's lifecycle.

Hence the convenience of using the ComponentFactory for both Factory and
Poolable code.

lookup(...) {
  return factory.newInstance()
}

return(...) {
  factory.decommission(...)
}

The Threadsafe components should only be disposed of when the entity that
created
them is disposed.


Re: cvs commit: xml-cocoon/src/org/apache/cocoon DefaultComponentManager.java CocoonComponentSelector.java

Posted by Paul Russell <pr...@apache.org>.
* Berin Loritsch (bloritsch@apache.org) wrote :
> WARNING! WARNING! WARNING!

Right, this now fixed. Sorry about that. Is there any documentation
anywhere about who is actually _responsible_ for maintaining the
lifecycle of these components?


P.

Re: cvs commit: xml-cocoon/src/org/apache/cocoon DefaultComponentManager.java CocoonComponentSelector.java

Posted by Berin Loritsch <bl...@apache.org>.
prussell@apache.org wrote:
>        public void release(Component component) {
>   +        if (component instanceof Disposable) {
>   +            try {
>   +                ((Disposable) component).dispose();
>   +            } catch (Exception e) {
>   +                this.log.warn(
>   +                    "Could not dispose of instance of component " + component.getClass().getName() + ".",
>   +                    e
>   +                );
>   +            }
>   +        }
>   +
>   +        if (component instanceof Recyclable) {
>   +            ((Recyclable) component).recycle();
>   +        }
>   +

WARNING! WARNING! WARNING!

The release() method is a Composer's way of stating that "I am done using this
Component".  It does NOT mean that the Component should be destroyed.  This
could cause dire issues with Components that are both ThreadSafe and Disposable.
When the ComponentManager/Selector is finally disposed, it should call those
End of Life events for the housed Components.

The exceptions to this are Poolable and SingleThreaded Components.  SingleThreaded
Components should be derived from the ComponentFactory (That's what it's there
for), and when they are returned, they should be decommissioned by the ComponentFactory.
When an object is Poolable, the Pool takes care of calling Recyclable, and preparing/
destroying the Components as they are returned.

If a Component is simply Recyclable, but not Poolable (I think this is impossible),
then we should explicitly call recycle().

This will cause a serious mess in a busy system--and possibly not so busy system.