Leif Mortenson wrote:
> 
> 
> Peter Donald wrote:
> 
>> On Wed, 13 Feb 2002 19:57, Leif Mortenson wrote:
>>
>>> Wouldn't it also be possible just to keep track of the number of lookups
>>> - releases.  Then when you want to dispose the ComponentManager go into
>>> a loop.  Call dispose on any components whose count is 0. Disposing them
>>> should release other components.  Repeat.  If you reach a point where
>>> you don't have any components with a count of 0, then this is an error
>>> and a warning should be displayed before going ahead and disposing the
>>> rest of them.
>>>
>>
>> Yep ... but it is a strategy I recall from my C++/COM days which I 
>> still shudder at ;) I remember quite a few cases where I had to debug 
>> each others code because components where forced to be shutdown and 
>> couldn't gracefully go down. Especially when there is circular 
>> dependencies that creep in without you noticing ;)
>>
> I don't think that you can start things up with circular dependencies. 
> If Component A obtaines a reference to Component B in A's initialize 
> method, that will work.  But if B also tries to obtain a reference to 
> Component A that will fail because A has not yet been initialized.  (I 
> think that it actually creates another copy of Compnent A which in turn 
> creates a second copy of B etc... Going into an infinite loop... ??  I 
> ran into this creating the datasource.cluster package.)
> 
> As long as components are looked up and released in the initialize and 
> dispose methods you shouldn't be able to get into any circular 
> dependency problems.


Keep in mind that the ECM uses the Lifestyle interfaces (ThreadSafe, SingleThreaded,
and Poolable).  If the instance is ThreadSafe, the component instance never changes.
That might work for you.  Also, SingleThreaded (the default) creates a new instance
per request--probably not what you want.  Lastly, Poolable has a pool of components
that it will pull the instance from.

In the case outlined above, If one of the components is ThreadSafe, you won't
get an infinite loop of instance creation.  It will happen if it is either ThreadSafe
or SingleThreaded.

That is why many components (at least in Cocoon world) wait until run-time to actually
get the component--everything is initialized then.


-- 

"They that give up essential liberty to obtain a little temporary safety
  deserve neither liberty nor safety."
                 - Benjamin Franklin


--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to