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:[EMAIL PROTECTED] 
Sent: Monday, September 20, 2004 10:00 PM
To: [email protected]
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to