commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Christian Essl <>
Subject [HiveMind] New interceptor support
Date Tue, 25 Nov 2003 12:37:41 GMT
Javassist is fast and impressingly easy for byte-code generation, however 
it is by no way that comfortable (to code, test and debugg) as plain java. 
Therefore I've implemented an abstract ServiceInterceptorFactory which 
allows the user to attach MethodInterceptors to the methods of an 
interface. (A common pattern used by aopalliance, spring, cglib etc). Ie a 
simple tracing interceptor looks like this:

public class TracingMethodInterceptor implements MethodInterceptor

 public Object invoke(Invocation invocation, Object target, Object[] args) 
throws Throwable
    System.out.println("method: "+invocation.getMethod()+" is called with 
args: "+args);
    Object ret = invocation.proceed(target, args); //this invokes the next 
method in the interceptor chain
    System.out.println("method: "+invocation.getMethod()+" returned: 
    return ret;

Both the interceptor and the Invocation are created using Javassist, 
therefore it is in terms of speed (according to my rudimentary testings) 
between a plain Javaassist interceptor and a dyna-proxy interceptor.

Comparing the existing Hivemind Logging with the same code using the 
MethodInterceptor and with a DynaProxy for 5.000.000 repetitions the times 
(ms) are as follows: (The numbers are not stable but the direction is quite 

method: Object getObject()
executing MethodLog took: 1000
executing HivemindLog took: 359
executing DynaProxyLog took: 1360

method: void setObject(Object);
executing MethodLog took: 968
executing HivemindLog took: 516
executing DynaProxyLog took: 1766

method (9 prim params): int add(int,int,byte,short,char,double,long,float);
executing MethodLog took: 3063 (more primitives and arguments means bigger 
args[] and boxing/unboxing)
executing HivemindLog took: 594
executing DynaProxyLog took: 4031

As I see interceptors for general use should be created using javaassist, 
however other interceptors (which just add some custom AOP for some 
components) could well be implemented using MethodInterceptors. Here the 
higher convinience pays off.

Christian Essl

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message