Package samples.event

Source Code of samples.event.Sample1

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.");
    }
}
TOP

Related Classes of samples.event.Sample1

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.