> From: Antti Koivunen [mailto:[EMAIL PROTECTED]]
> // DefaultInterfacer.java ---------------------------------------------
>
> import java.lang.reflect.Proxy;
> import java.lang.reflect.Method;
> import java.lang.reflect.InvocationHandler;
>
> import org.apache.avalon.framework.thread.ThreadSafe;
>
> public class DefaultInterfacer implements Interfacer
> {
> private ComponentSource m_source;
>
> public DefaultInterfacer(ComponentSource source)
> {
> m_source = source;
> }
>
> public Object lookup(String role) throws Exception
> {
> Object component = m_source.lookup( role );
> if ( component instanceof ThreadSafe ) {
> return component;
> }
> Class[] interfaces = new Class[] { Class.forName( role ) };
> InvocationHandler handler =
> new ReleaseHandler( m_source, role );
> return Proxy.newProxyInstance(
> Thread.currentThread().getContextClassLoader(),
> interfaces, handler );
> }
>
> private static class ReleaseHandler implements InvocationHandler
> {
> ComponentSource source;
> String role;
>
> ReleaseHandler( ComponentSource source, String role )
> {
> this.source = source;
> this.role = role;
> }
>
> public Object invoke(Object proxy, Method method, Object[] args)
> throws Throwable
> {
> Object component = this.source.lookup( this.role );
> Object result = method.invoke( component, args );
> this.source.release( component );
> return result;
Antti,
it appears as if the proxy does a lookup/release for each method
invocation. This assumes that the component is not
a) brought out
b) configured via a set of setThis, setThat
c) finally used via a call to execute() or similar.
d) (released)
since calling several methods on an obtained component is not
guaranteed to invoke the method on the same component.
The problem is to find the beginning and end of each duty
cycle without the composer notifying the component or component manager
of that.
/LS
> }
> }
> }
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>