Class ResourcepathMonitor
java.lang.Object
java.lang.Thread
clazzfish.core.util.ShutdownHook
clazzfish.monitor.AbstractMonitor
clazzfish.monitor.ResourcepathMonitor
- All Implemented Interfaces:
Shutdownable, AbstractMonitorMBean, ResourcepathMonitorMBean, Runnable
Analogous to ClasspathMonitor this class allows you to ask for resources in
the classpath. Originally this class was part of the PatternTesting project.
- Author:
- oliver
-
Nested Class Summary
Nested classes/interfaces inherited from class Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidThis operation dumps the different MBean attributes to the given directory.getDoublet(String name, int nr) Gets the doublet.String[]Looks for each found doublet resource in which classpath it was found.protected URI[]Gets the URIs of the doublet resourcepath.String[]Gets the doublets.getFirstDoublet(String name) Returns the first doublet of the given classname or resource.String[]Gets the classpath which contains incompatible resources.protected URI[]Gets the classpath which contains incompatible resources.String[]Incompatible resources are doublets with different content.static ResourcepathMonitorYes, it is a Singleton because it offers only some services.intgetNoResources(String name) Gets the number of resources.String[]Scans the classpath for all resources.getResourcesFor(String name) Gets the resources for a given name.booleanIs the given classname or resource a doublet, e.g. can it be found several times in the classpath?static booleanIf you want to ask JMX if bean is already registered you can use this method.voidlogMe()Logs the different array to the log output.static voidWith this method you can register theResourcepathMonitorwith the default name.static voidUnregister ResourcepathMonitor as MBean.whichResource(String name) Looks if the given resource can be found in the classpath.Methods inherited from class AbstractMonitor
copyResource, dump, dump, dumpArray, dumpArray, dumpHeadline, dumpMe, dumpMe, exportCSV, getDumpDir, isMBean, registerMeAsMBean, registerMeAsMBean, run, toString, toStringArray, unregisterMeAsMBeanModifier and TypeMethodDescriptionprotected voidcopyResource(String name, File file) Copy a resource to the given file.protected voiddump(BufferedWriter writer, String... getterMethodNames) This operation dumps the different MBean attributes.protected voidDumps different arrays to the given dumpDir directory, each array in its own file.protected static voiddumpArray(Object[] array, BufferedWriter writer, String title) Dump array.protected static voidDumps an array to the given directory.protected static voiddumpHeadline(BufferedWriter writer, String headline) Dump headline.dumpMe()This operation dumps the different MBean attributes to a temporary directory with classname as prefix.voidThis operation dumps the different MBean attributes to the given directory.If you want to configure viaConfig.DUMP_URIthe location where the monitored data should be exported you should override this method.The base directory where all is dumped can be configured (seeConfig.getDumpDir().booleanisMBean()If you want to ask JMX if bean is already registered you can ask the MBeanHelper or you can ask this method.voidWith this method you can register the monitor with the default name.voidregisterMeAsMBean(ObjectName name) With this method you can register the monitor with your own name.voidrun()This method is called when the ClasspathMonitor is registered as shutdown hook.toString()As the toString implementation the name of the registered MBean is used.protected static String[]toStringArray(URI[] uris) We remove the URI prefix from the result to be in-line with the other classpath methods.voidUnregister monitor as MBean.Methods inherited from class ShutdownHook
addMeAsShutdownHook, isShutdownHook, removeMeAsShutdownHookModifier and TypeMethodDescriptionvoidTo be able to register the class as shutdown hook via JMX we can't use a static method - this is the reason why this additional method was added.booleanHere you can ask if the class was already registered as shutdown hook.voidIf you want to unregister the instance as shutdown hook you can use this (not static) method.Methods inherited from class 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, threadId, yield
-
Constructor Details
-
ResourcepathMonitor
protected ResourcepathMonitor()We offer only some services. So there is no need to instantiate it from outside.
-
-
Method Details
-
getInstance
Yes, it is a Singleton because it offers only some services. So we don't need the object twice.- Returns:
- the only instance
-
registerAsMBean
public static void registerAsMBean()With this method you can register theResourcepathMonitorwith the default name.You can only register the
ResourcepathMonitoronce only. If you want to register it with another name you have to first unregister it. -
unregisterAsMBean
public static void unregisterAsMBean()Unregister ResourcepathMonitor as MBean. -
isRegisteredAsMBean
public static boolean isRegisteredAsMBean()If you want to ask JMX if bean is already registered you can use this method.- Returns:
- true if class is registered as MBean
-
getResources
Scans the classpath for all resources. For performance reason we return no longer a copy but the origin array. Don't do changes for the returned array!- Specified by:
getResourcesin interfaceResourcepathMonitorMBean- Returns:
- all resources as String array
-
whichResource
Looks if the given resource can be found in the classpath.- Specified by:
whichResourcein interfaceResourcepathMonitorMBean- Parameters:
name- of a resource e.g. "log4j.properties"- Returns:
- URI of the given resource (or null if resource was not found)
- See Also:
-
getResourcesFor
Gets the resources for a given name.- Parameters:
name- the name- Returns:
- the resources as URL enumeration
-
getNoResources
Gets the number of resources.- Specified by:
getNoResourcesin interfaceResourcepathMonitorMBean- Parameters:
name- the name of the resource- Returns:
- number of resources
- See Also:
-
isDoublet
@Description("is the given classname or resource found more than once in the classpath?") public boolean isDoublet(String name) Is the given classname or resource a doublet, e.g. can it be found several times in the classpath? If the classname or resource is not in the classpath a java.util.NoSuchElementException will be thrown.- Specified by:
isDoubletin interfaceResourcepathMonitorMBean- Parameters:
name- a classname or resource- Returns:
- true if more than one classname or resource was found in the classpath
- Throws:
NoSuchElementException- the no such element exceptionNoSuchElementException- if no classname or resource was found- See Also:
-
getFirstDoublet
@Description("returns the first doublet of the given classname or resource") public URI getFirstDoublet(String name) Returns the first doublet of the given classname or resource.- Specified by:
getFirstDoubletin interfaceResourcepathMonitorMBean- Parameters:
name- a classname or resource- Returns:
- the first doublet
- See Also:
-
getDoublet
Gets the doublet.- Specified by:
getDoubletin interfaceResourcepathMonitorMBean- Parameters:
name- the namenr- the nr- Returns:
- the doublet
- See Also:
-
getDoublets
Gets the doublets.Note: The Manifest file (META-INF/MANIFEST.MF) ist not counted as doublet file because it is not really a resource.
- Specified by:
getDoubletsin interfaceResourcepathMonitorMBean- Returns:
- the doublets
- See Also:
-
getDoubletResourcepath
@Description("returns the classpath where doublets were found") public String[] getDoubletResourcepath()Looks for each found doublet resource in which classpath it was found. Resources like META-INF/MANIFEST.MF are not considered as doublet - otherwise you'll find all classpathes in the array.- Specified by:
getDoubletResourcepathin interfaceResourcepathMonitorMBean- Returns:
- the classpath where doublets were found
-
getDoubletResourcepathURIs
Gets the URIs of the doublet resourcepath. Doublets in the META-INF folder are filtered out because these resources contains often some meta information of the JAR.- Returns:
- the URIs of the doublets
-
getIncompatibleResources
Incompatible resources are doublets with different content.- Specified by:
getIncompatibleResourcesin interfaceResourcepathMonitorMBean- Returns:
- doublet resources with different content
-
getIncompatibleResourcepath
Gets the classpath which contains incompatible resources. Resources in the META-INF folder are filtered out because resources in this folder contains often only some meta info of the JAR.- Specified by:
getIncompatibleResourcepathin interfaceResourcepathMonitorMBean- Returns:
- the classpathes where incompatible resources were found
-
getIncompatibleResourcepathURIs
Gets the classpath which contains incompatible resources. Resources in the META-INF folder are filtered out because resources in this folder contains often only some meta info of the JAR.- Returns:
- the resourcepath as array of URIs
-
logMe
public void logMe()Logs the different array to the log output.- Specified by:
logMein interfaceAbstractMonitorMBean- Specified by:
logMein classAbstractMonitor
-
dumpMe
This operation dumps the different MBean attributes to the given directory.- Overrides:
dumpMein classAbstractMonitor- Parameters:
dumpDir- the directory where the attributes are dumped to.- Throws:
IOException- Signals that an I/O exception has occurred.
-