Class ConnectionMonitor
java.lang.Object
java.lang.Thread
clazzfish.monitor.util.Shutdowner
clazzfish.monitor.AbstractMonitor
clazzfish.jdbc.ConnectionMonitor
- All Implemented Interfaces:
ConnectionMonitorMBean,AbstractMonitorMBean,Shutdownable,Runnable
This is the monitor class for the
ProxyConnection which monitors the
different newInstance() and close() calls. So you can ask this monitor how
many connections and which connections are open.
The instance of this class is automatically registered as MBean as soon as a
ProxyConnection is used.
Originally this class was part of PatternTesting (since 2012) but was moved in 2018 to the ClazzFish project.
- Since:
- 0.9
- Author:
- oliver (ob@aosd.de)
-
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
ConstructorsModifierConstructorDescriptionprotectedNo need to instantiate it - we provide only some services. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidaddConnection(ProxyConnection proxyConnection) Adds the connection to the list of open connections.static voidAssert that all connections are closed.voidThis operation dumps the different MBean attributes to the given directory.static StackTraceElementgetCallerOf(Connection connection) Gets the caller of the given connection.Gets the callers.Gets the caller stacktraces of all connections.intGets the number of closed connections.static ConnectionMonitorYes, it is a Singleton because it offers only some services.Gets the caller which opens the last connection.Gets the stacktrace of the caller which opens the last connection.static ConnectiongetMonitoredConnection(Connection connection) If you want to monitor the connection use this method.intGets the number of open connections.intGets the total sum of open and closed connections.voidLog the caller stacktraces.voidlogMe()Logs the different array to the log output.static voidremoveConnection(ProxyConnection proxyConnection) Removes the connection from the list of open connections.voidrun()This method is called when the ConnectionMonitor is registered as shutdown hook.toString()This toString implementation supports logging and debugging by showing the number of open connections.Methods inherited from class clazzfish.monitor.AbstractMonitor
copyResource, dump, dump, dumpArray, dumpArray, dumpHeadline, dumpMe, dumpMe, getDumpDir, isMBean, registerMeAsMBean, registerMeAsMBean, registerMeAsMBean, toStringArray, unregisterMeAsMBeanMethods 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.AbstractMonitorMBean
dumpMe, dumpMe, getDumpDirMethods inherited from interface clazzfish.jdbc.ConnectionMonitorMBean
addMeAsShutdownHook, isShutdownHook, removeMeAsShutdownHook
-
Constructor Details
-
ConnectionMonitor
protected ConnectionMonitor()No need to instantiate it - we provide only some services. The constructor is protected because it is still used by the (deprecated) ConnectionMonitor in patterntesting.runtime.db.
-
-
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
-
getMonitoredConnection
If you want to monitor the connection use this method.- Parameters:
connection- the original connection- Returns:
- a proxy for the connection
-
addConnection
Adds the connection to the list of open connections.- Parameters:
proxyConnection- the proxy connection
-
removeConnection
Removes the connection from the list of open connections.- Parameters:
proxyConnection- the proxy connection
-
getCallerOf
Gets the caller of the given connection.- Parameters:
connection- the connection- Returns:
- the caller of the connection
-
getCallers
Gets the callers.- Specified by:
getCallersin interfaceConnectionMonitorMBean- Returns:
- the callers
- See Also:
-
getLastCallerStacktrace
Gets the stacktrace of the caller which opens the last connection.- Specified by:
getLastCallerStacktracein interfaceConnectionMonitorMBean- Returns:
- the all caller
-
getCallerStacktraces
Gets the caller stacktraces of all connections.- Specified by:
getCallerStacktracesin interfaceConnectionMonitorMBean- Returns:
- stacktraces of all callers
- Throws:
OpenDataException- the open data exception
-
getLastCaller
Gets the caller which opens the last connection.- Specified by:
getLastCallerin interfaceConnectionMonitorMBean- Returns:
- the all caller
-
getOpenConnections
public int getOpenConnections()Gets the number of open connections.- Specified by:
getOpenConnectionsin interfaceConnectionMonitorMBean- Returns:
- the open count
- See Also:
-
getClosedConnections
public int getClosedConnections()Gets the number of closed connections.- Specified by:
getClosedConnectionsin interfaceConnectionMonitorMBean- Returns:
- the closed connections
- Since:
- 1.4.1
-
getSumOfConnections
public int getSumOfConnections()Gets the total sum of open and closed connections.- Specified by:
getSumOfConnectionsin interfaceConnectionMonitorMBean- Returns:
- the sum of connections
- Since:
- 1.4.1
-
assertConnectionsClosed
public static void assertConnectionsClosed()Assert that all connections are closed. -
toString
This toString implementation supports logging and debugging by showing the number of open connections.- Overrides:
toStringin classAbstractMonitor- Returns:
- the string
- See Also:
-
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.
-
logMe
public void logMe()Logs the different array to the log output.- Specified by:
logMein interfaceAbstractMonitorMBean- Specified by:
logMein classAbstractMonitor
-
logCallerStacktraces
public void logCallerStacktraces()Log the caller stacktraces.- Specified by:
logCallerStacktracesin interfaceConnectionMonitorMBean- Since:
- 1.6.1
- See Also:
-
run
public void run()This method is called when the ConnectionMonitor is registered as shutdown hook.- Specified by:
runin interfaceRunnable- Overrides:
runin classAbstractMonitor- See Also:
-