Class AgentModule

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.ClassLoader classLoader  
      private java.util.Set<java.lang.String> scope  
    • Constructor Summary

      Constructors 
      Constructor Description
      AgentModule()
      Creates a new isolated module.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addToScopeWithInnerClasses​(java.lang.Class<?> c)  
      private static java.lang.Class<?> getModuleClass()  
      static boolean isSupported()
      Checks whether Java modules are supported by the current Java runtime.
      <T> java.lang.Class<T> loadClassInModule​(java.lang.Class<T> original)
      Loads a copy of the given class in the isolated classloader.
      void openPackage​(java.lang.instrument.Instrumentation instrumentation, java.lang.Class<?> classInPackage)
      Opens the package of the provided class to the module created in this AgentModule() instance.
      • Methods inherited from class java.lang.Object

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

      • scope

        private final java.util.Set<java.lang.String> scope
      • classLoader

        private final java.lang.ClassLoader classLoader
    • Constructor Detail

      • AgentModule

        public AgentModule()
                    throws java.lang.Exception
        Creates a new isolated module.
        Throws:
        java.lang.Exception - if it cannot be created
    • Method Detail

      • isSupported

        public static boolean isSupported()
        Checks whether Java modules are supported by the current Java runtime.
        Returns:
        true is modules are supported
      • openPackage

        public void openPackage​(java.lang.instrument.Instrumentation instrumentation,
                                java.lang.Class<?> classInPackage)
                         throws java.lang.Exception
        Opens the package of the provided class to the module created in this AgentModule() instance.
        Parameters:
        instrumentation - service provided to the agent by the Java runtime
        classInPackage - example class of the package to open
        Throws:
        java.lang.Exception - if package cannot be opened
      • loadClassInModule

        public <T> java.lang.Class<T> loadClassInModule​(java.lang.Class<T> original)
                                                 throws java.lang.Exception
        Loads a copy of the given class in the isolated classloader. Also any inner classes are loader from the isolated classloader.
        Type Parameters:
        T - type of the class to load
        Parameters:
        original - original class definition which is used as source
        Returns:
        class object from the isolated class loader
        Throws:
        java.lang.Exception - if the class cannot be loaded
      • addToScopeWithInnerClasses

        private void addToScopeWithInnerClasses​(java.lang.Class<?> c)
      • getModuleClass

        private static java.lang.Class<?> getModuleClass()
                                                  throws java.lang.ClassNotFoundException
        Throws:
        java.lang.ClassNotFoundException