avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Leo Simons <leosim...@apache.org>
Subject RE: [proposal] avalon 5 ComponentManager interface
Date Tue, 11 Jun 2002 16:04:52 GMT
> > Same way as you deal with all resources. ie call close(), 
> > release() etc. 
> So can I assume that every component, or every XXXXManager 
> has a close() or release() method?

I'd not suggest that...if you want to isolate the client from
determining whether the component has/needs the close()/release(), use a

>   "Every pair of component C and its associated CManager interfaces
>    must define a method that, when called by the client, indicates 
>    that the client is finished using the component C. The method 
>    may be in the CManager interface - for example, 
>    CManager.release (C c) - or in the C interface - for example, 
>    C.close (). Note that this contract applies to component
> *interfaces*.
>    even if the implementation does not require an end-of-transaction
>    signal from the client, the method must be specified so
> implementations
>    that do require such a signal can recieve them."
> How about that?

make that:

A component must define a method with the following signature:

public void release();

or a component's manager (if it exists) must define a method with the
following signature:

public void release( Object );

at the interface level, that, when called by a client, indicates that
the client is finished using the component if it has any resources that
require releasing.

You can even write a ReleaseUtil that uses some minimal reflection to
determine whether the method exists and calls it if it does, then always
use that in all of your components (have this in C++ project of mine).

ReleaseUtil::release( component, manager  )
	if component has method "public void release()"

	if manager has method "public void release(Object)"
		manager.release( component )

I would prefer though (cleaner, no reflection):

 * If an object implements this interface, it is the responsibility
 * of anyone that uses it to call the release() method when it is done
 * using it.
interface RequiresRelease
	public void release();

so you get

class ReleaseUtil
	public static release( Object obj )
		if( obj instanceof RequiresRelease )

class SomeComponent
	SomeManager m; // presumably a pool...

	compose( ComponentManager cm ) throws ComponentException
		m = cm.lookup( SomeManager.ROLE );

			SomeObject comp = m.getObject();

		catch( Throwable t )
			ReleaseUtil.release( comp );

point is: release() is not made part of the lifecycle part of the
framework or any of those interfaces.

This should probably become a part of a generic pooling solution.


- Leo

To unsubscribe, e-mail:   <mailto:avalon-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:avalon-dev-help@jakarta.apache.org>

View raw message