Return-Path: Delivered-To: apmail-jakarta-commons-dev-archive@www.apache.org Received: (qmail 55747 invoked from network); 25 Nov 2003 12:36:31 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 25 Nov 2003 12:36:31 -0000 Received: (qmail 11073 invoked by uid 500); 25 Nov 2003 12:36:23 -0000 Delivered-To: apmail-jakarta-commons-dev-archive@jakarta.apache.org Received: (qmail 11044 invoked by uid 500); 25 Nov 2003 12:36:22 -0000 Mailing-List: contact commons-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Jakarta Commons Developers List" Reply-To: "Jakarta Commons Developers List" Delivered-To: mailing list commons-dev@jakarta.apache.org Received: (qmail 10969 invoked from network); 25 Nov 2003 12:36:22 -0000 Received: from unknown (HELO smtp001.mail.ukl.yahoo.com) (217.12.11.32) by daedalus.apache.org with SMTP; 25 Nov 2003 12:36:22 -0000 Received: from m1342p008.adsl.highway.telekom.at (HELO MEDION1) (christianessl@80.121.39.168 with login) by smtp1.mail.vip.ukl.yahoo.com with SMTP; 25 Nov 2003 12:36:20 -0000 Content-Type: text/plain; charset=iso-8859-15; format=flowed To: "commons-dev@jakarta.apache.org" Subject: [HiveMind] New interceptor support From: Christian Essl MIME-Version: 1.0 Date: Tue, 25 Nov 2003 13:37:41 +0100 Message-ID: User-Agent: Opera7.11/Win32 M2 build 2887 X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N 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: "+args); 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 clear) 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 http://jucas.sourceforge.net --------------------------------------------------------------------- To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: commons-dev-help@jakarta.apache.org