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 StringThe Constant MBEAN_NAME for the registered name in JMX. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidagentmain(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".voiddumpLoadedClasses(File dumpFile) This operation dumps the loaded classes to the given file.voiddumpLoadedClasses(String filename) This operation dumps the loaded classes to the given file.getArgs()Get the arguments from the call as agent.static ClasspathAgentGets the single instance of ClasspathAgent.static InstrumentationGets 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.booleanisActive()Checks if is active.voidPrints the loaded classes to the log output.static voidpremain(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:
getArgsin interfaceClasspathAgentMBean- Returns:
- the args
-
getLoadedClasses
Gets the loaded classes.- Specified by:
getLoadedClassesin interfaceClasspathAgentMBean- Returns:
- the loaded classes
-
getLoadedClasses
Gets the loaded classes.- Specified by:
getLoadedClassesin 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
SortedSetfor sorting.- Specified by:
getLoadedClassnamesin 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:
isActivein interfaceClasspathAgentMBean- Returns:
- true, if started as Java agent
-
logLoadedClasses
public void logLoadedClasses()Prints the loaded classes to the log output.- Specified by:
logLoadedClassesin 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:
dumpLoadedClassesin 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:
dumpLoadedClassesin 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.
-