Class Instrumentor


  • public final class Instrumentor
    extends java.lang.Object

    Simple -javaagent compatible instrumentor. Provides a premain implementation which grabs a handle to the JVM Instrumentation and keeps a reference to it for use later on.

    Since:
    2.0 (0.3.3)
    Version:
    2.0
    Author:
    Michael Grove
    • Constructor Summary

      Constructors 
      Constructor Description
      Instrumentor()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Collection<java.lang.Class<?>> annotatedWith​(java.lang.Class<? extends java.lang.annotation.Annotation> theAnnotation)
      Return all the classes which have the given annotation applied to them
      static <T> java.util.Collection<java.lang.Class<? extends T>> instancesOf​(java.lang.Class<T> theClass)
      Return all the classes loaded into the JVM which extend from the provided class
      static java.lang.instrument.Instrumentation instrumentation()
      Return the JVM instrumentation
      static boolean isInitialized()
      Return whether or not the JVM instrumentation has been initialized via the JVM agent
      static void premain​(java.lang.String theAgentArgs, java.lang.instrument.Instrumentation theJVMInst)
      Premain method for use with -javaagent.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Instrumentor

        public Instrumentor()
    • Method Detail

      • instrumentation

        public static java.lang.instrument.Instrumentation instrumentation()
        Return the JVM instrumentation
        Returns:
        the instrumentation or null if this was not used as the java agent
      • premain

        public static void premain​(java.lang.String theAgentArgs,
                                   java.lang.instrument.Instrumentation theJVMInst)
        Premain method for use with -javaagent.
        Parameters:
        theAgentArgs - the cmd line args
        theJVMInst - the JVM instrumentation
      • instancesOf

        public static <T> java.util.Collection<java.lang.Class<? extends T>> instancesOf​(java.lang.Class<T> theClass)
        Return all the classes loaded into the JVM which extend from the provided class
        Type Parameters:
        T - the base class type
        Parameters:
        theClass - the class
        Returns:
        all the classes extending from the parameter. An empty collection will be returned if this java agent is not installed
      • annotatedWith

        public static java.util.Collection<java.lang.Class<?>> annotatedWith​(java.lang.Class<? extends java.lang.annotation.Annotation> theAnnotation)
        Return all the classes which have the given annotation applied to them
        Parameters:
        theAnnotation - the annotation
        Returns:
        the classes with the annotation. An empty collection will be returned if this java agent is not installed
      • isInitialized

        public static boolean isInitialized()
        Return whether or not the JVM instrumentation has been initialized via the JVM agent
        Returns:
        true if initialized, false otherwise