hivemind-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Hensley, Richard" <Richard.Hens...@McKesson.com>
Subject RE: Reflection vs. Javassist
Date Tue, 21 Sep 2004 15:41:42 GMT
Damon, 

Here you go! It's almost a direct rip off from the example logging
interceptor on the web site.

package com.mckesson.adept.hivemind;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Proxy;
import java.util.List;
import org.apache.hivemind.InterceptorStack;
import org.apache.hivemind.ServiceInterceptorFactory;
import org.apache.hivemind.internal.Module;

public class TimerInterceptorFactory implements ServiceInterceptorFactory {

    public TimerInterceptorFactory() {
        super();
    }

    public void createInterceptor(InterceptorStack stack,
            Module invokingModule, List parameters) {
        InvocationHandler handler = new TimerInvocationHandler(stack.peek(),
                stack.getServiceInterface());
        Object interceptor = Proxy.newProxyInstance(invokingModule
                .getClassResolver().getClassLoader(), new Class[]{stack
                .getServiceInterface()}, handler);
        stack.push(interceptor);
    }
}

package com.mckesson.adept.hivemind;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import com.mckesson.common.util.Timer;

public class TimerInvocationHandler implements InvocationHandler {

    private String className;

    private Object inner;

    public TimerInvocationHandler(Object inner, Class intf) {
        super();
        this.inner = inner;
        this.className = inner.getClass().getName();
        if (this.className.startsWith("$")) {
            this.className = intf.getName();
        }
        this.className += '.';
    }

    public Object invoke(Object proxy, Method method, Object[] args)
            throws Throwable {
        String timer = this.className + method.getName();
        Timer.startTimer(timer);
        try {
            Object result = method.invoke(this.inner, args);
            return result;
        }
        catch (InvocationTargetException ex) {
            throw ex.getTargetException();
        }
        finally {
            Timer.stopTimer(timer);
        }
    }
}
-----Original Message-----
From: Damon Rolfs [mailto:drolfs@gmail.com] 
Sent: Monday, September 20, 2004 10:00 PM
To: hivemind-user@jakarta.apache.org
Subject: Re: Reflection vs. Javassist


Richard, 

Could you please distribute your reflection/proxy - based interceptor?
 (Or at least send me a version?)

Cheers, ~dmr


---------------------------------------------------------------------
To unsubscribe, e-mail: hivemind-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: hivemind-user-help@jakarta.apache.org


Mime
View raw message