avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Albert Kwong <mandr...@yahoo.com>
Subject Container supported interceptable service
Date Mon, 19 Apr 2004 10:49:27 GMT
Avalon is so great!  It makes almost everything
pluggable.  Besides pluggable, I find it also useful
to make component operations interceptable, so that
external logic can be inserted before and after
operations.  It would be even better if the container
can support it and make all components easily
interceptable.

I have drafted some ideas here.  What do you think?

Albert Kwong (Mandr)

=========
Objective
=========
Allow components (interceptors) to intercept the
operations of another component using a Chain of
Responsibility pattern.  Better support for SOC.


Component
=========

/**
 *@avalon.interceptor type='AbcServiceInterceptor'
 */
public interface AbcService
{
    String doAbc (String param);

    /** @avalon.interceptor.skip */
    String doDef ();
}

/**
 * Automatically generated from AbcService meta tags.
 */
public interface AbcServiceInterceptor
{
    String doAbc (String param, Iterator chain);
}

/**
 * To be deployed as abcService.
 */
public class AbcServiceImpl implements AbcService
{
    String doAbc (String param) {};
}

/**
 * to be deployed as abcInterceptor
 */
public class AbcServiceInterceptorImpl implements
AbcServiceInterceptor
{
    String doAbc (String param, Iterator chain)
    {
        /* pre processing interception */
        ((AbcServiceInterceptor) chain.next()).doAbc
(param, chain);
        /* post processing interception */
    }
}


Deployment
==========

<!-- Order of interception depends on the order
attribute. -->
<targets>
    <target name='abcInterceptor'>
        <intercept
order='1000'><source>abcService</source></intercept>
    </target>
</targets>


Proxy processing
================
1. Application calls abcService.doAbc (param)
2. Proxy creates the Iterator chain [abcInterceptor,
Proxy(abcService)]     (note: Proxy(abcService)
implements AbcServiceInterceptor)
3. Container calls abcInterceptor.doAbc (param, chain)
4. abcInterceptor pre processing
5. abcInterceptor calls Proxy(abcService).doAbc
(param, chain)
5. Proxy(abcService) calls abcService.doAbc(param)
6. abcService returns
7. Proxy(abcService) returns
8. abcInterceptor post processing
9. abcInterceptor returns
10. ...



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


Mime
View raw message