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
ConstructorsModifierConstructorDescriptionprotected
No need to instantiate it - we provide only some services. -
Method Summary
Modifier and TypeMethodDescriptionstatic void
addConnection
(ProxyConnection proxyConnection) Adds the connection to the list of open connections.static void
Assert that all connections are closed.void
This operation dumps the different MBean attributes to the given directory.static StackTraceElement
getCallerOf
(Connection connection) Gets the caller of the given connection.Gets the callers.Gets the caller stacktraces of all connections.int
Gets the number of closed connections.static ConnectionMonitor
Yes, 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 Connection
getMonitoredConnection
(Connection connection) If you want to monitor the connection use this method.int
Gets the number of open connections.int
Gets the total sum of open and closed connections.void
Log the caller stacktraces.void
logMe()
Logs the different array to the log output.static void
removeConnection
(ProxyConnection proxyConnection) Removes the connection from the list of open connections.void
run()
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, unregisterMeAsMBean
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.AbstractMonitorMBean
dumpMe, dumpMe, getDumpDir
Methods 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:
getCallers
in interfaceConnectionMonitorMBean
- Returns:
- the callers
- See Also:
-
getLastCallerStacktrace
Gets the stacktrace of the caller which opens the last connection.- Specified by:
getLastCallerStacktrace
in interfaceConnectionMonitorMBean
- Returns:
- the all caller
-
getCallerStacktraces
Gets the caller stacktraces of all connections.- Specified by:
getCallerStacktraces
in interfaceConnectionMonitorMBean
- Returns:
- stacktraces of all callers
- Throws:
OpenDataException
- the open data exception
-
getLastCaller
Gets the caller which opens the last connection.- Specified by:
getLastCaller
in interfaceConnectionMonitorMBean
- Returns:
- the all caller
-
getOpenConnections
public int getOpenConnections()Gets the number of open connections.- Specified by:
getOpenConnections
in interfaceConnectionMonitorMBean
- Returns:
- the open count
- See Also:
-
getClosedConnections
public int getClosedConnections()Gets the number of closed connections.- Specified by:
getClosedConnections
in interfaceConnectionMonitorMBean
- Returns:
- the closed connections
- Since:
- 1.4.1
-
getSumOfConnections
public int getSumOfConnections()Gets the total sum of open and closed connections.- Specified by:
getSumOfConnections
in 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:
toString
in classAbstractMonitor
- Returns:
- the string
- See Also:
-
dumpMe
This operation dumps the different MBean attributes to the given directory.- Overrides:
dumpMe
in 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:
logMe
in interfaceAbstractMonitorMBean
- Specified by:
logMe
in classAbstractMonitor
-
logCallerStacktraces
public void logCallerStacktraces()Log the caller stacktraces.- Specified by:
logCallerStacktraces
in 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:
run
in interfaceRunnable
- Overrides:
run
in classAbstractMonitor
- See Also:
-