package samples.event;
import alt.jiapi.InstrumentationContext;
import alt.jiapi.InstrumentationDescriptor;
import alt.jiapi.reflect.Loader;
import alt.jiapi.reflect.JiapiClass;
import alt.jiapi.event.MethodEvent;
import alt.jiapi.event.MethodEventProducer;
import alt.jiapi.event.MethodListener;
import alt.jiapi.util.Bootstrapper;
import alt.jiapi.util.InstrumentingClassLoader;
public class Sample1 implements MethodListener {
public static void main(String args[]) throws Exception {
new Sample1();
}
public Sample1() throws Exception {
// Configure:
InstrumentationContext ctx = new InstrumentationContext();
InstrumentationDescriptor id = new InstrumentationDescriptor();
id.addInclusionRule("samples.*");
ctx.addInstrumentationDescriptor(id);
// Use event API:
MethodEventProducer eventProducer = new MethodEventProducer(id);
eventProducer.addMethodListener(this);
Bootstrapper.launch("samples.Foo", null, ctx,
InstrumentingClassLoader.createClassLoader(ctx));
}
public void methodEntered(MethodEvent event) {
System.out.println("Method " + event.getClassName() + "." +
event.getMethodName() + " entered.");
}
public void methodExited(MethodEvent event) {
System.out.println("Method " + event.getClassName() + "." +
event.getMethodName() + " exited.");
}
}