package samples.example1;
import alt.jiapi.InstrumentationContext;
import alt.jiapi.InstrumentationDescriptor;
import alt.jiapi.event.MethodEvent;
import alt.jiapi.event.MethodEventProducer;
import alt.jiapi.event.MethodListener;
import alt.jiapi.util.Bootstrapper;
public class Example1 implements MethodListener {
public static void main(String args[]) throws Exception {
new Example1();
}
public Example1() throws Exception {
// Configure:
InstrumentationContext ctx = new InstrumentationContext();
InstrumentationDescriptor id = new InstrumentationDescriptor();
id.addInclusionRule("test.*");
ctx.addInstrumentationDescriptor(id);
// Use event API:
MethodEventProducer eventProducer = new MethodEventProducer(id);
eventProducer.addMethodListener(this);
// Launch:
Bootstrapper.launch("test.Foo", null, ctx,
getClass().getClassLoader());
}
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.");
}
}