Class ClasspathAgent
java.lang.Object
java.lang.Thread
clazzfish.core.util.ShutdownHook
clazzfish.agent.ClasspathAgent
- All Implemented Interfaces:
ClasspathAgentMBean,ClassLoading,Shutdownable,Serializable,Runnable
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:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe Constant MBEAN_NAME for the registered name in JMX.Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
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".String[]Gets all classes which are available thru the classpathgetArgs()Get the arguments from the call as agent.Returns the URI where a little statistic of loaded and unloaded classes are dumped to.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.String[]Gets unused classes.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.voidrun()voidsetDumpURI(URI dumpURI) It is possible to change the URI where the classes are dumped to.Methods inherited from class clazzfish.core.util.ShutdownHook
addMeAsShutdownHook, isShutdownHook, removeMeAsShutdownHookMethods inherited from class java.lang.Thread
activeCount, checkAccess, clone, currentThread, dumpStack, enumerate, getAllStackTraces, getContextClassLoader, getDefaultUncaughtExceptionHandler, getId, getName, getPriority, getStackTrace, getState, getThreadGroup, getUncaughtExceptionHandler, holdsLock, interrupt, interrupted, isAlive, isDaemon, isInterrupted, isVirtual, join, join, join, join, ofPlatform, ofVirtual, onSpinWait, setContextClassLoader, setDaemon, setDefaultUncaughtExceptionHandler, setName, setPriority, setUncaughtExceptionHandler, sleep, sleep, sleep, start, startVirtualThread, stop, threadId, toString, yieldMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface clazzfish.core.ClassLoading
getClasspathMethods inherited from interface clazzfish.agent.ClasspathAgentMBean
isDumping
-
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 interfaceClassLoading- 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 interfaceClassLoading- 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
- See Also:
-
getAllClasses
Gets all classes which are available thru the classpath- Specified by:
getAllClassesin interfaceClasspathAgentMBean- Returns:
- all classes of the classpath
- Since:
- 3.0
-
getUnusedClasses
Gets unused classes.- Specified by:
getUnusedClassesin interfaceClasspathAgentMBean- Returns:
- all unused classes of the classpath
- Since:
- 3.0
-
getDumpURI
Description copied from interface:ClasspathAgentMBeanReturns the URI where a little statistic of loaded and unloaded classes are dumped to.- Specified by:
getDumpURIin interfaceClasspathAgentMBean- Returns:
- dump URI or "dev:/null" if nothing is dumped
-
setDumpURI
Description copied from interface:ClasspathAgentMBeanIt is possible to change the URI where the classes are dumped to. If the URI cannot be handled (e.g. it is not a file URI) it will be ignored.- Specified by:
setDumpURIin interfaceClasspathAgentMBean- Parameters:
dumpURI- e.g. "file://tmp/test.csv"
-
run
-