avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Robert Mouat <rob...@mouat.net>
Subject Re: [proposal] custom component lookup
Date Sat, 22 Jun 2002 00:02:49 GMT
Peter Donald wrote:

> >but I also was wondering if there is any container extension mechanism
> >that is shared by the Avalon containers - or if there are plans for
> >anything like that?
> It would be neat to have a generic interceptor architecture. For a 
> buisness-esque type layer you could have interceptor interface such as
> interface Interceptor
> {
>    Object invoke( InterceptorContext ctx, Object[] args ) throws Exception;
> }
> interface InterceptorContext
> {
>    ComponentMetaData getCaller();
>    ComponentMetaData getCallee();
>    DependencyMetaData getCalledInterface();
>    String getMethodSignature();
>    Object invokeNext( Object[] args ) throws Exception;
> }

this is actually closer to what I was originally thinking -- I was
thinking about a generic mechanism to allow for dynamic proxies -- my
original idea was to have a component implement a subclass of
InvocationHandler, then have the container create a proxy from the
InvocationHandler each lookup... but then I thought that allowing the
component to implement a lookup() method might be more flexible... but
then I wondered if this might be too flexible since it would step on the
toes of the component manager.... but I digress :)

I have a couple questions about this Interceptor...

1. would it be a component? i.e. do you imagine it being looked up like
other components?  This seems like it would be a good idea, e.g. in the
case of the AuthorizingInterceptor you described, it might be handy if
another component could look it up and set some security settings.

2. Does this Interceptor interface have any benefits over dynamic proxies?  
[the container will need to generate a dynamic proxy to intercept the
calls in order to pass them onto the interceptor].

  e.g. the same result could be achieved with:

    interface ProxyHandler implements InvocationHandler

      public void associateContext(
          Object proxy,
          ComponentMetaData caller,
          ComponentMetaData callee,
          Object next

      // from InvocationHandler
      public Object invoke( Object proxy, Method method, Object[] args ) throws Throwable;


    where the proxy the container creates is passed in to the
    associateContext method.  And to pass the method on the invoke method
    could do:

      Context ctx = (Context) m_contexts.get( proxy );
      result = method.invoke( ctx.getNext(), args );

> Possible impls...
> class MyAuthorizingInterceptor implements Interceptor
> {
>    Object invoke( InterceptorContext ctx, Object[] args ) throws Exception
>    {
>       if( !isAuthorized( ctx.getCaller() ) ) throw SecurityException("...");
>       return ctx.invokeNext( args );
>    }
> }
> class MyTimingInterceptor implements Interceptor
> {
>    Object invoke( InterceptorContext ctx, Object[] args ) throws Exception
>    {
>       final long key = startTimer();
>       try { return ctx.invokeNext( args ); }
>       finally
>       {
>        final long time = endTimer( key );
>        reportTime( time );
>       }
>    }
> }
> This would be particular useful to people who are using Avalon for Buisness 
> level prgramming (in contrast to System-level programming).
> However I don't know of any plans to implement this unless you want to 
> volunteer ;)

unfortunately not until after I finish writing my thesis...

Robert (who avoids writing his thesis by hanging out on avalon-dev :).

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