Class ClasspathAgent

java.lang.Object
clazzfish.agent.ClasspathAgent
All Implemented Interfaces:
ClasspathAgentMBean, Serializable

public class ClasspathAgent extends Object implements ClasspathAgentMBean
This is a simple Java agent to be able to watch the classpath. We need it because some classloaders (e.g. the classloader of the IBM JDK) does not provide the information which classes are loaded.

Originally this class was part of patterntesting-agent.

Since:
0.8
Author:
oboehm
See Also:
  • Field Details

    • MBEAN_NAME

      public static final String MBEAN_NAME
      The Constant MBEAN_NAME for the registered name in JMX.
      See Also:
  • Method Details

    • getInstance

      public static ClasspathAgent getInstance()
      Gets the single instance of ClasspathAgent.
      Returns:
      single instance of ClasspathAgent
    • agentmain

      public static void agentmain(String agentArgs, Instrumentation inst)
      This method will be called if the class is loaded dynmically by ClasspathAgentLoader.
      Parameters:
      agentArgs - the agent args
      inst - the inst
    • premain

      public static void premain(String agentArgs, Instrumentation inst)
      I guess this method will be called from the VM.
      Parameters:
      agentArgs - the agent args
      inst - the inst
    • getInstrumentation

      public static Instrumentation getInstrumentation()
      Gets the instrumentation.
      Returns:
      the instrumentation
    • getArgs

      public String getArgs()
      Get the arguments from the call as agent.
      Specified by:
      getArgs in interface ClasspathAgentMBean
      Returns:
      the args
    • getLoadedClasses

      public Class<?>[] getLoadedClasses()
      Gets the loaded classes.
      Specified by:
      getLoadedClasses in interface ClasspathAgentMBean
      Returns:
      the loaded classes
    • getLoadedClasses

      public Class<?>[] getLoadedClasses(ClassLoader classloader)
      Gets the loaded classes.
      Specified by:
      getLoadedClasses in interface ClasspathAgentMBean
      Parameters:
      classloader - the classloader
      Returns:
      the loaded classes
      See Also:
    • getLoadedClassnames

      public String[] getLoadedClassnames()
      Returns the classes which were loaded by the classloader. The loaded packages are returned as string array so that it can be displayed by the 'jconsole'.

      Note: Because we had in the past some doublets in the resulting array we use now a SortedSet for sorting.

      Specified by:
      getLoadedClassnames in interface ClasspathAgentMBean
      Returns:
      the classnames as string array
    • isActive

      public boolean isActive()
      Checks if is active. This is true if this class here was started as Java agent.
      Specified by:
      isActive in interface ClasspathAgentMBean
      Returns:
      true, if started as Java agent
    • logLoadedClasses

      public void logLoadedClasses()
      Prints the loaded classes to the log output.
      Specified by:
      logLoadedClasses in interface ClasspathAgentMBean
      See Also:
    • dumpLoadedClasses

      public File dumpLoadedClasses() throws IOException
      This operation dumps the loaded classes to a temporary file with the prefix "dumpLoadedClasses" and the extension ".txt".

      To be able to see the name of the temporary file in the 'jconsole' it is returned as value.

      Specified by:
      dumpLoadedClasses in interface ClasspathAgentMBean
      Returns:
      the temporary file
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also:
    • dumpLoadedClasses

      public void dumpLoadedClasses(String filename) throws IOException
      This operation dumps the loaded classes to the given file.
      Specified by:
      dumpLoadedClasses in interface ClasspathAgentMBean
      Parameters:
      filename - the file where the classes are dumped to.
      Throws:
      IOException - Signals that an I/O exception has occurred.
      See Also:
    • dumpLoadedClasses

      public void dumpLoadedClasses(File dumpFile) throws IOException
      This operation dumps the loaded classes to the given file.
      Parameters:
      dumpFile - the file where the classes are dumped to.
      Throws:
      IOException - Signals that an I/O exception has occurred.