Package samples.jazzpect

Source Code of samples.jazzpect.Sample1

package samples.jazzpect;

import org.aopalliance.intercept.MethodInterceptor;
import org.aopalliance.intercept.MethodInvocation;

import alt.jiapi.jazzpect.Initializer;

/**
* Class Sample1.
*
* @author Mika Riekkinen
*/
public class Sample1 implements MethodInterceptor {
    public static void main(String args[]) throws Exception {
        String className = "samples.Foo";
        if (args.length > 0) {
            className = args[0];
        }

        new Sample1(className);
    }


    public Sample1(String className) throws Exception {
        // For some reason, if resolution is "*", instrumentation fails
        // Initializer i = new Initializer("samples.*", this);
        Initializer i =
            new Initializer(new String[] {"samples.*"}, null,
                            "samples.*", this);
        // Run the main method of class
        i.runMainMethod(className, null);

        // alternatively, we could get the classloader from initializer
        // and load the class manually. If done this way, care must
        // be taken, that *all* the relevant(application) classes are loaded
        // by i.getClassLoader().
    }


    // Interface MethodInterceptor:  ---------------------------
    public Object invoke(MethodInvocation mi) throws Throwable {
        // return mi.proceed();
        long l1 = System.currentTimeMillis();
        // Object[] args = mi.getArguments();
        Object o = mi.proceed();
        long l2 = System.currentTimeMillis();

        System.out.println("It took " + (l2-l1) + " ms to invoke " +
                           mi.getMethod().getName());

        return o;
    }
}
TOP

Related Classes of samples.jazzpect.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.