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 void
copyResource
(String name, File file) Copy a resource to the given file.protected void
dump
(BufferedWriter writer, String... getterMethodNames) This operation dumps the different MBean attributes.protected void
Dumps different arrays to the given dumpDir directory, each array in its own file.protected static void
dumpArray
(Object[] array, BufferedWriter writer, String title) Dump array.protected static void
Dumps an array to the given directory.protected static void
dumpHeadline
(BufferedWriter writer, String headline) Dump headline.dumpMe()
This operation dumps the different MBean attributes to a temporary directory with classname as prefix.void
This operation dumps the different MBean attributes to the given directory.void
This operation dumps the different MBean attributes to the given directory.The base directory where all is dumped can be configured (seeConfig.getDumpDir()
.boolean
isMBean()
If you want to ask JMX if bean is already registered you can ask the MBeanHelper or you can ask this method.abstract void
logMe()
Prints the different MBean attributes to the log output.void
With this method you can register the monitor with the default name.void
registerMeAsMBean
(String name) With this method you can register the monitor with your own name.void
registerMeAsMBean
(ObjectName name) With this method you can register the monitor with your own name.void
run()
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.void
Unregister monitor as MBean.Methods inherited from class clazzfish.monitor.util.Shutdowner
addMeAsShutdownHook, isShutdownHook, removeMeAsShutdownHook
Methods 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, yield
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods 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:
logMe
in 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:
getDumpDir
in 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:
dumpMe
in 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:
dumpMe
in 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
-