cocoon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Berin Loritsch <blorit...@apache.org>
Subject Re: single instance per context on avalon components
Date Fri, 28 Sep 2001 16:51:05 GMT
In order for a Component to be instantiated once per ComponentManager,
you must have your Component implement the ThreadSafe interface (which
means your Component must be thread safe).


The ExcaliburComponentManager/ExcaliburComponentSelector apply the
following logic:

1)If a Component implements ThreadSafe then the CM assumes that the
developer knows their stuff, and shares one instance of the Component
with all requestors.

2)If a Component implements Poolable (which is done if you implement
Recyclable), then the CM assumes again that the developer knows their
stuff but creates a pool of Components to share.  Each thread gets
a unique instance.  This works for 99% of all cases where a thread
needs a unique instance.

3)If a Component implements SingleThreaded then the CM assumes that
the developer knows what they are doing, and that Poolable does not
"cut the mustard" for this Component and it creates a new instance
of the Component for each request.  This is used for the 1% of the
time that a thread needs a unique instance, but the instance created
cannot be reused (i.e. the JaxpParser or XercesParser).

4)If a Component does not implement any of the afformentioned interfaces
the CM assumes the developer doesn't know all the details, and it treats
the Component as if it had implemented SingleThreaded.

5)If the developer explicitly adds a component to the CM before it is
initialized (after initialization the CM is "locked"), then the CM
assumes that the developer is managing the Component and that it is
ThreadSafe.

The last two cases are the safest assumptions concidering the context
that they are used within.  In 4, the CM makes no assumptions about
the code.  In 5, the CM assumes the Component is not to be managed by
it.


Stefano Mazzocchi wrote:
> 
> Working for finishing up the gallery code, I've come into the need to
> share the instance of an avalon component between two cocoon pipeline
> components, respectively a transformer and a generator.
> 
> This is the same need of the FragmentExtractor generator/transformer
> pair: one collects information at transformation stage and stores this
> information for later retrieval at generation stage. It's not a common
> need, but I assume this will turn out very useful for complex operations
> like pagination and path expansion (which is why I need this).
> 
> So, my code compiles and does what it should: the problem is that the
> two sitemap components (the generator and the transformer) get two
> different instances of the component so one stores correctly and the
> other retrieves correctly, the problem is that it never retrieves
> anything since it's the other instance that gets filled with data :(
> 
> how do I share a component without using static methods?
> 
> (oh, BTW, the FragmentExtractor is buggy in that respect since it uses a
> static hashtable instead of using a shared component, this could well
> create problems on situations where more than one cocoon is run in the
> same JVM! please, kill all static instances!)
> 
> Thanks much in advance.
> 
> --
> Stefano Mazzocchi      One must still have chaos in oneself to be
>                           able to give birth to a dancing star.
> <stefano@apache.org>                             Friedrich Nietzsche
> --------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
> For additional commands, email: cocoon-dev-help@xml.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: cocoon-dev-unsubscribe@xml.apache.org
For additional commands, email: cocoon-dev-help@xml.apache.org


Mime
View raw message