Class SlowQueryReportJmx
- java.lang.Object
-
- org.apache.tomcat.jdbc.pool.JdbcInterceptor
-
- org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
-
- org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
-
- org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport
-
- org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReportJmx
-
- All Implemented Interfaces:
java.lang.reflect.InvocationHandler,javax.management.NotificationBroadcaster,javax.management.NotificationEmitter,SlowQueryReportJmxMBean
public class SlowQueryReportJmx extends SlowQueryReport implements javax.management.NotificationEmitter, SlowQueryReportJmxMBean
JMX-enabled slow query report interceptor. Publishes slow and failed query statistics to JMX and provides notifications when slow or failed queries are detected.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport
SlowQueryReport.QueryStats, SlowQueryReport.QueryStatsComparator
-
Nested classes/interfaces inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
AbstractQueryReport.StatementProxy
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringFAILED_QUERY_NOTIFICATIONNotification type for failed query events.protected static java.util.concurrent.ConcurrentHashMap<java.lang.String,SlowQueryReportJmxMBean>mbeansRegistry of JMX MBeans for each connection pool.protected javax.management.NotificationBroadcasterSupportnotifierNotification broadcaster support for JMX notifications.protected booleannotifyPoolWhether to send notifications to the pool.protected static java.util.concurrent.atomic.AtomicLongnotifySequenceAtomic sequence counter for notifications.static java.lang.StringobjectNameAttributeProperty key for overriding the JMX object name.protected ConnectionPoolpoolThe connection pool reference.protected java.lang.StringpoolNameThe name of the connection pool.static java.lang.StringSLOW_QUERY_NOTIFICATIONNotification type for slow query events.protected static javax.management.openmbean.CompositeTypeSLOW_QUERY_TYPEComposite type used for JMX query statistics data.-
Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport
logFailed, logSlow, maxQueries, perPoolStats, queries, queryStatsComparator
-
Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
threshold
-
Fields inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
constructors, CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_QUERY, EXECUTE_TYPES, EXECUTE_UPDATE, GET_GENERATED_KEYS, GET_RESULTSET, GET_STATEMENT, PREPARE_CALL, PREPARE_CALL_IDX, PREPARE_STATEMENT, PREPARE_STATEMENT_IDX, RESULTSET_IDX, STATEMENT_TYPE_COUNT, STATEMENT_TYPES
-
Fields inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor
CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VAL
-
-
Constructor Summary
Constructors Constructor Description SlowQueryReportJmx()Creates a new SlowQueryReportJmx instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)Adds a notification listener.protected voidderegisterJmx()Deregisters this interceptor from JMX.protected static javax.management.openmbean.CompositeTypegetCompositeType()Returns the composite type used for JMX query statistics.javax.management.MBeanNotificationInfo[]getNotificationInfo()Returns information about the notifications this MBean can send.javax.management.ObjectNamegetObjectName(java.lang.Class<?> clazz, java.lang.String poolName)Returns the JMX ObjectName for the given class and pool name.java.lang.StringgetPoolName()JMX operation - return the name of the pooljava.lang.String[]getPoolNames()JMX operation - return the names of all the poolsjavax.management.openmbean.CompositeData[]getSlowQueriesCD()JMX operation - returns all the queries we have collected.booleanisNotifyPool()Returns whether notifications are sent to the pool.protected voidnotifyJmx(java.lang.String query, java.lang.String type)Sends a JMX notification for the given query and notification type.voidpoolClosed(ConnectionPool pool)Called when the connection pool is closed; deregisters JMX.voidpoolStarted(ConnectionPool pool)Called when the connection pool is started.protected voidregisterJmx()Registers this interceptor with JMX.voidremoveNotificationListener(javax.management.NotificationListener listener)Removes a notification listener.voidremoveNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback)Removes a notification listener with the given filter and handback.protected java.lang.StringreportFailedQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, java.lang.Throwable t)Reports a failed query and sends a JMX notification if logging is enabled.protected java.lang.StringreportSlowQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta)Reports a slow query and sends a JMX notification if logging is enabled.voidreset(ConnectionPool parent, PooledConnection con)Resets this interceptor for a new connection, registering JMX if applicable.voidresetStats()JMX operation - remove all stats for this connection poolvoidsetNotifyPool(boolean notifyPool)Sets whether notifications are sent to the pool.voidsetProperties(java.util.Map<java.lang.String,PoolProperties.InterceptorProperty> properties)Sets the interceptor properties, including the notifyPool flag.-
Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.SlowQueryReport
closeInvoked, getPoolStats, getQueryStats, isLogFailed, isLogSlow, prepareCall, prepareStatement, removeOldest, reportQuery, setLogFailed, setLogSlow, setMaxQueries
-
Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractQueryReport
createStatement, getThreshold, setThreshold
-
Methods inherited from class org.apache.tomcat.jdbc.pool.interceptor.AbstractCreateStatementInterceptor
getConstructor, invoke, isExecute, isStatement, process
-
Methods inherited from class org.apache.tomcat.jdbc.pool.JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, setNext, setUseEquals
-
-
-
-
Field Detail
-
SLOW_QUERY_NOTIFICATION
public static final java.lang.String SLOW_QUERY_NOTIFICATION
Notification type for slow query events.- See Also:
- Constant Field Values
-
FAILED_QUERY_NOTIFICATION
public static final java.lang.String FAILED_QUERY_NOTIFICATION
Notification type for failed query events.- See Also:
- Constant Field Values
-
objectNameAttribute
public static final java.lang.String objectNameAttribute
Property key for overriding the JMX object name.- See Also:
- Constant Field Values
-
SLOW_QUERY_TYPE
protected static volatile javax.management.openmbean.CompositeType SLOW_QUERY_TYPE
Composite type used for JMX query statistics data.
-
mbeans
protected static final java.util.concurrent.ConcurrentHashMap<java.lang.String,SlowQueryReportJmxMBean> mbeans
Registry of JMX MBeans for each connection pool.
-
notifier
protected volatile javax.management.NotificationBroadcasterSupport notifier
Notification broadcaster support for JMX notifications.
-
poolName
protected java.lang.String poolName
The name of the connection pool.
-
notifySequence
protected static final java.util.concurrent.atomic.AtomicLong notifySequence
Atomic sequence counter for notifications.
-
notifyPool
protected boolean notifyPool
Whether to send notifications to the pool.
-
pool
protected ConnectionPool pool
The connection pool reference.
-
-
Method Detail
-
addNotificationListener
public void addNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback) throws java.lang.IllegalArgumentExceptionAdds a notification listener.- Specified by:
addNotificationListenerin interfacejavax.management.NotificationBroadcaster- Parameters:
listener- the listener to addfilter- the notification filterhandback- the handback object- Throws:
java.lang.IllegalArgumentException- if the listener is null
-
getNotificationInfo
public javax.management.MBeanNotificationInfo[] getNotificationInfo()
Returns information about the notifications this MBean can send.- Specified by:
getNotificationInfoin interfacejavax.management.NotificationBroadcaster- Returns:
- an array of MBeanNotificationInfo objects
-
removeNotificationListener
public void removeNotificationListener(javax.management.NotificationListener listener) throws javax.management.ListenerNotFoundExceptionRemoves a notification listener.- Specified by:
removeNotificationListenerin interfacejavax.management.NotificationBroadcaster- Parameters:
listener- the listener to remove- Throws:
javax.management.ListenerNotFoundException- if the listener was not previously added
-
removeNotificationListener
public void removeNotificationListener(javax.management.NotificationListener listener, javax.management.NotificationFilter filter, java.lang.Object handback) throws javax.management.ListenerNotFoundExceptionRemoves a notification listener with the given filter and handback.- Specified by:
removeNotificationListenerin interfacejavax.management.NotificationEmitter- Parameters:
listener- the listener to removefilter- the notification filterhandback- the handback object- Throws:
javax.management.ListenerNotFoundException- if the listener was not previously added
-
getCompositeType
protected static javax.management.openmbean.CompositeType getCompositeType()
Returns the composite type used for JMX query statistics.- Returns:
- the composite type, or
nullif initialization failed
-
reset
public void reset(ConnectionPool parent, PooledConnection con)
Resets this interceptor for a new connection, registering JMX if applicable.- Overrides:
resetin classSlowQueryReport- Parameters:
parent- the connection poolcon- the pooled connection
-
poolClosed
public void poolClosed(ConnectionPool pool)
Called when the connection pool is closed; deregisters JMX.- Overrides:
poolClosedin classSlowQueryReport- Parameters:
pool- the connection pool being closed
-
poolStarted
public void poolStarted(ConnectionPool pool)
Called when the connection pool is started.- Overrides:
poolStartedin classSlowQueryReport- Parameters:
pool- the connection pool being started
-
reportFailedQuery
protected java.lang.String reportFailedQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, java.lang.Throwable t)Reports a failed query and sends a JMX notification if logging is enabled.- Overrides:
reportFailedQueryin classSlowQueryReport- Parameters:
query- the SQL queryargs- the query argumentsname- the connection pool namestart- the start time in millisecondst- the throwable that caused the failure- Returns:
- the formatted query string
-
notifyJmx
protected void notifyJmx(java.lang.String query, java.lang.String type)Sends a JMX notification for the given query and notification type.- Parameters:
query- the SQL query stringtype- the notification type (slow or failed query)
-
reportSlowQuery
protected java.lang.String reportSlowQuery(java.lang.String query, java.lang.Object[] args, java.lang.String name, long start, long delta)Reports a slow query and sends a JMX notification if logging is enabled.- Overrides:
reportSlowQueryin classSlowQueryReport- Parameters:
query- the SQL queryargs- the query argumentsname- the connection pool namestart- the start time in millisecondsdelta- the elapsed time in milliseconds- Returns:
- the formatted query string
-
getPoolNames
public java.lang.String[] getPoolNames()
JMX operation - return the names of all the pools- Returns:
- - all the names of pools that we have stored data for
-
getPoolName
public java.lang.String getPoolName()
JMX operation - return the name of the pool- Returns:
- the name of the pool, unique within the JVM
-
isNotifyPool
public boolean isNotifyPool()
Returns whether notifications are sent to the pool.- Returns:
- true if notifications are sent to the pool
-
setNotifyPool
public void setNotifyPool(boolean notifyPool)
Sets whether notifications are sent to the pool.- Parameters:
notifyPool- true if notifications should be sent to the pool
-
resetStats
public void resetStats()
JMX operation - remove all stats for this connection pool
-
getSlowQueriesCD
public javax.management.openmbean.CompositeData[] getSlowQueriesCD() throws javax.management.openmbean.OpenDataExceptionJMX operation - returns all the queries we have collected.- Specified by:
getSlowQueriesCDin interfaceSlowQueryReportJmxMBean- Returns:
- - the slow query report as composite data.
- Throws:
javax.management.openmbean.OpenDataException- if the composite data cannot be created
-
deregisterJmx
protected void deregisterJmx()
Deregisters this interceptor from JMX.
-
getObjectName
public javax.management.ObjectName getObjectName(java.lang.Class<?> clazz, java.lang.String poolName) throws javax.management.MalformedObjectNameExceptionReturns the JMX ObjectName for the given class and pool name.- Parameters:
clazz- the interceptor classpoolName- the name of the connection pool- Returns:
- the JMX ObjectName
- Throws:
javax.management.MalformedObjectNameException- if the object name is malformed
-
registerJmx
protected void registerJmx()
Registers this interceptor with JMX.
-
setProperties
public void setProperties(java.util.Map<java.lang.String,PoolProperties.InterceptorProperty> properties)
Sets the interceptor properties, including the notifyPool flag.- Overrides:
setPropertiesin classSlowQueryReport- Parameters:
properties- the interceptor properties
-
-