Class AbstractMonitor
java.lang.Object
java.lang.Thread
clazzfish.monitor.util.Shutdowner
clazzfish.monitor.AbstractMonitor
- All Implemented Interfaces:
AbstractMonitorMBean,Shutdownable,Runnable
- Direct Known Subclasses:
AbstractStatistic,ClasspathMonitor,ConnectionMonitor,ResourcepathMonitor
This abstract base class has some support to for registration and
unregistration of a monitor class as shutdown hook. Originally this
class was part of the PatternTesting project.
- Author:
- oliver
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Thread
Thread.Builder, Thread.State, Thread.UncaughtExceptionHandler -
Field Summary
Fields inherited from class java.lang.Thread
MAX_PRIORITY, MIN_PRIORITY, NORM_PRIORITY -
Constructor Summary
Constructors -
Method Summary
Modifier 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.voidThis operation dumps the different MBean attributes to the given directory.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.abstract voidlogMe()Prints the different MBean attributes to the log output.voidWith this method you can register the monitor with the default name.voidregisterMeAsMBean(String name) With this method you can register the monitor with your own 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 clazzfish.monitor.util.Shutdowner
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, yieldMethods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface clazzfish.monitor.util.Shutdownable
addMeAsShutdownHook, isShutdownHook, removeMeAsShutdownHook
-
Constructor Details
-
AbstractMonitor
public AbstractMonitor()
-
-
Method Details
-
run
-
registerMeAsMBean
public void registerMeAsMBean()With this method you can register the monitor with the default name.You can only register the monitor only once. If you want to register it with another name you have to first unregister it.
-
registerMeAsMBean
With this method you can register the monitor with your own name. This is e.g. useful if you have an application server with several applications.You can only register the monitor only once. If you want to register it with another name you have to first unregister it.
- Parameters:
name- the MBean name (e.g. "my.class.Monitor")
-
registerMeAsMBean
With this method you can register the monitor with your own name. This is e.g. useful if you have an application server with several applications.You can only register the monitor only once. If you want to register it with another name you have to first unregister it.
- Parameters:
name- the name
-
unregisterMeAsMBean
public void unregisterMeAsMBean()Unregister monitor as MBean. -
isMBean
public boolean isMBean()If you want to ask JMX if bean is already registered you can ask the MBeanHelper or you can ask this method.- Returns:
- true if MBean is already registered.
-
logMe
public abstract void logMe()Prints the different MBean attributes to the log output.- Specified by:
logMein interfaceAbstractMonitorMBean
-
getDumpDir
The base directory where all is dumped can be configured (seeConfig.getDumpDir(). Each monitor class has its own dump dir below the base directory.- Specified by:
getDumpDirin interfaceAbstractMonitorMBean- Returns:
- the dump directory
- Since:
- 2.3
-
dumpMe
This operation dumps the different MBean attributes to a temporary directory with classname as prefix. The name of the created directory is returned so that you can see it in the 'jconsole' (if you have triggered it from there).- Specified by:
dumpMein interfaceAbstractMonitorMBean- Returns:
- the file
- Throws:
IOException- Signals that an I/O exception has occurred.- See Also:
-
dump
This operation dumps the different MBean attributes. Use this method if you want to have all relevant infos in one stream. This is e.g. used by thelogMe()method.- Parameters:
writer- a buffered writergetterMethodNames- the names of the getter methods which returns an array- Throws:
IOException- Signals that an I/O exception has occurred.
-
dump
Dumps different arrays to the given dumpDir directory, each array in its own file. For each array a method name must be provided as argument. Each given method must return an array as result.- Parameters:
dumpDir- the dump dirgetterMethodNames- the name of the getter methods which return an array- Throws:
IOException- Signals that an I/O exception has occurred.
-
dumpMe
This operation dumps the different MBean attributes to the given directory.- Specified by:
dumpMein interfaceAbstractMonitorMBean- Parameters:
dirname- the directory name- Throws:
IOException- Signals that an I/O exception has occurred.
-
dumpMe
This operation dumps the different MBean attributes to the given directory.- Parameters:
dumpDir- the directory where the attributes are dumped to.- Throws:
IOException- Signals that an I/O exception has occurred.
-
copyResource
Copy a resource to the given file.- Parameters:
name- the namefile- the dir- Throws:
IOException- Signals that an I/O exception has occurred.
-
dumpArray
Dumps an array to the given directory.- Parameters:
array- the arraydir- the dirtitle- the title (or name of the generated file)- Throws:
IOException- Signals that an I/O exception has occurred.
-
dumpArray
protected static void dumpArray(Object[] array, BufferedWriter writer, String title) throws IOException Dump array.- Parameters:
array- the arraywriter- the writertitle- the title- Throws:
IOException- Signals that an I/O exception has occurred.
-
dumpHeadline
Dump headline.- Parameters:
writer- the writerheadline- the headline- Throws:
IOException- Signals that an I/O exception has occurred.
-
toStringArray
-
toString
-