Class ClasspathAgent
java.lang.Object
clazzfish.agent.ClasspathAgent
- All Implemented Interfaces:
ClasspathAgentMBean
,Serializable
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 Summary
FieldsModifier and TypeFieldDescriptionstatic final String
The Constant MBEAN_NAME for the registered name in JMX. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
agentmain
(String agentArgs, Instrumentation inst) This method will be called if the class is loaded dynmically by ClasspathAgentLoader.This operation dumps the loaded classes to a temporary file with the prefix "dumpLoadedClasses" and the extension ".txt".void
dumpLoadedClasses
(File dumpFile) This operation dumps the loaded classes to the given file.void
dumpLoadedClasses
(String filename) This operation dumps the loaded classes to the given file.getArgs()
Get the arguments from the call as agent.static ClasspathAgent
Gets the single instance of ClasspathAgent.static Instrumentation
Gets the instrumentation.Class<?>[]
Gets the loaded classes.Class<?>[]
getLoadedClasses
(ClassLoader classloader) Gets the loaded classes.String[]
Returns the classes which were loaded by the classloader.boolean
isActive()
Checks if is active.void
Prints the loaded classes to the log output.static void
premain
(String agentArgs, Instrumentation inst) I guess this method will be called from the VM.
-
Field Details
-
MBEAN_NAME
The Constant MBEAN_NAME for the registered name in JMX.- See Also:
-
-
Method Details
-
getInstance
Gets the single instance of ClasspathAgent.- Returns:
- single instance of ClasspathAgent
-
agentmain
This method will be called if the class is loaded dynmically by ClasspathAgentLoader.- Parameters:
agentArgs
- the agent argsinst
- the inst
-
premain
I guess this method will be called from the VM.- Parameters:
agentArgs
- the agent argsinst
- the inst
-
getInstrumentation
Gets the instrumentation.- Returns:
- the instrumentation
-
getArgs
Get the arguments from the call as agent.- Specified by:
getArgs
in interfaceClasspathAgentMBean
- Returns:
- the args
-
getLoadedClasses
Gets the loaded classes.- Specified by:
getLoadedClasses
in interfaceClasspathAgentMBean
- Returns:
- the loaded classes
-
getLoadedClasses
Gets the loaded classes.- Specified by:
getLoadedClasses
in interfaceClasspathAgentMBean
- Parameters:
classloader
- the classloader- Returns:
- the loaded classes
- See Also:
-
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 interfaceClasspathAgentMBean
- 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 interfaceClasspathAgentMBean
- Returns:
- true, if started as Java agent
-
logLoadedClasses
public void logLoadedClasses()Prints the loaded classes to the log output.- Specified by:
logLoadedClasses
in interfaceClasspathAgentMBean
- See Also:
-
dumpLoadedClasses
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 interfaceClasspathAgentMBean
- Returns:
- the temporary file
- Throws:
IOException
- Signals that an I/O exception has occurred.- See Also:
-
dumpLoadedClasses
This operation dumps the loaded classes to the given file.- Specified by:
dumpLoadedClasses
in interfaceClasspathAgentMBean
- Parameters:
filename
- the file where the classes are dumped to.- Throws:
IOException
- Signals that an I/O exception has occurred.- See Also:
-
dumpLoadedClasses
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.
-