Class ResetAbandonedTimer
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.ResetAbandonedTimer
- All Implemented Interfaces:
InvocationHandler, ResetAbandonedTimerMBean
Class that resets the abandoned timer on any activity on the Connection, on any query execution and on any read of a
ResultSet returned by a statement obtained from the pooled connection, whether the operation
completed successfully or failed. Iterating a large result set therefore keeps the connection alive through the fetch
phase, not only until the query returns. Each reset happens when an individual call completes, so a single call that
itself blocks on the database for longer than
PoolConfiguration.setRemoveAbandonedTimeout(int) still gets the connection
abandoned. The statement facade is always used, so a result set handle that outlives its borrow is sealed off before
it can go on refreshing the abandoned timer of whoever holds that physical connection next. The handles this
interceptor hands out release what they wrap - the statement layer, the physical result set - once a close has been
forwarded to it, and answer any later call from the closed contract, as the statement facade's own handles do; a
handle the application keeps beyond its close therefore stops keeping the physical objects below it reachable. This
interceptor is useful for when you have a
PoolConfiguration.setRemoveAbandonedTimeout(int) that is fairly low, and you
want to reset the abandoned time each time any operation on the connection is performed This is useful for batch
processing programs that use connections for extensive amount of times.-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractQueryReport
AbstractQueryReport.StatementProxyModifier and TypeClassDescriptionprotected classClass to measure query execute time -
Field Summary
Fields inherited from class AbstractQueryReport
thresholdFields inherited from class AbstractCreateStatementInterceptor
constructors, CREATE_STATEMENT, CREATE_STATEMENT_IDX, EXECUTE, EXECUTE_BATCH, EXECUTE_LARGE_BATCH, EXECUTE_LARGE_UPDATE, 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_TYPESModifier and TypeFieldDescriptionprotected static final Constructor<?>[]the constructors that are used to create statement proxies.protected static final Stringprotected static final intprotected static final Stringprotected static final Stringprotected static final Stringprotected static final StringStatement.executeLargeUpdate(String)and its overloads, andPreparedStatement.executeLargeUpdate()protected static final Stringprotected static final String[]Array of execute type method namesprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final Stringprotected static final intprotected static final Stringprotected static final intprotected static final intprotected static final intCount of statement types inAbstractCreateStatementInterceptor.STATEMENT_TYPESprotected static final String[]Array of statement type method namesFields inherited from class JdbcInterceptor
ABORT_VAL, CLOSE_VAL, EQUALS_VAL, GETCONNECTION_VAL, HASHCODE_VAL, ISCLOSED_VAL, ISVALID_VAL, ISWRAPPERFOR_VAL, properties, TOSTRING_VAL, UNWRAP_VALModifier and TypeFieldDescriptionstatic final StringConnection.abort(java.util.concurrent.Executor)method namestatic final StringConnection.close()method namestatic final Stringstatic final StringPooledConnection.getConnection()method namestatic final Stringstatic final StringConnection.isClosed()method namestatic final StringConnection.isValid(int)method namestatic final StringWrapper.isWrapperFor(Class)method nameprotected Map<String, PoolProperties.InterceptorProperty> Properties for this interceptor.static final StringObject.toString()method namestatic final StringWrapper.unwrap(Class)method name -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidMethod invoked when the operationConnection.close()is invoked.createStatement(Object proxy, Method method, Object[] args, Object statement, long time) Wraps the query reporting statement proxy so that the result sets handed to the application reset the abandoned timer while they are read.Gets invoked each time an operation onConnectionis invoked.protected voidprepareCall(String query, long time) Invoked when prepareCall has been called and completed.protected voidprepareStatement(String sql, long time) Invoked when prepareStatement has been called and completed.protected StringreportFailedQuery(String query, Object[] args, String name, long start, long delta, Throwable t) Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), failed.protected StringreportQuery(String query, Object[] args, String name, long start, long delta) Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and was within the timing thresholdprotected StringreportSlowQuery(String query, Object[] args, String name, long start, long delta) Invoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and was exceeded the timing thresholdvoidreset(ConnectionPool parent, PooledConnection con) no-op for this interceptor. no state is stored.booleanReset the abandoned timer for the pooled connection.Methods inherited from class AbstractQueryReport
getThreshold, setThresholdModifier and TypeMethodDescriptionlongreturns the query measure threshold.voidsetThreshold(long threshold) Sets the query measurement threshold.Methods inherited from class AbstractCreateStatementInterceptor
getConstructor, isExecute, isStatement, processModifier and TypeMethodDescriptionprotected Constructor<?> getConstructor(int idx, Class<?> clazz) Creates a constructor for a proxy class, if one doesn't already exist.protected booleanReturns true if the method that is being invoked matches one of the execute types.protected booleanisStatement(Method method, boolean process) Returns true if the method that is being invoked matches one of the statement types.protected booleanReturns true if the method that is being invoked matches one of the method names passed inMethods inherited from class JdbcInterceptor
compare, compare, disconnected, getNext, getProperties, isUseEquals, poolClosed, poolStarted, setNext, setProperties, setUseEqualsModifier and TypeMethodDescriptionbooleanCompares a method name (String) to a method (Method)JdbcInterceptor.compare(String,String)Uses reference comparison unless the useEquals property is set to truebooleanPerforms a string comparison, using references unless the useEquals property is set to true.voiddisconnected(ConnectionPool parent, PooledConnection con, boolean finalizing) Called whenConnection.close()is called on the underlying connection.getNext()Returns the next interceptor in the chainReturns the properties configured for this interceptorbooleanTrue if the compare method uses the Object.equals(Object) method, false if comparison is done on a reference level.voidpoolClosed(ConnectionPool pool) This method is invoked by a connection pool when the pool is closed.voidpoolStarted(ConnectionPool pool) This method is invoked by a connection pool when the pool is first started up, usually when the first connection is requested.voidsetNext(JdbcInterceptor next) configures the next interceptor in the chainvoidsetProperties(Map<String, PoolProperties.InterceptorProperty> properties) Called during the creation of an interceptor The properties can be set during the configuration of an interceptor Override this method to perform type casts between string values and object propertiesvoidsetUseEquals(boolean useEquals) Set to true if string comparisons (for theJdbcInterceptor.compare(String, Method)andJdbcInterceptor.compare(String, String)methods) should use the Object.equals(Object) method The default is false
-
Constructor Details
-
ResetAbandonedTimer
public ResetAbandonedTimer()Default constructor.
-
-
Method Details
-
reset
Description copied from class:AbstractCreateStatementInterceptorno-op for this interceptor. no state is stored.- Overrides:
resetin classAbstractCreateStatementInterceptor- Parameters:
parent- - the connection pool owning the connectioncon- - the pooled connection
-
resetTimer
public boolean resetTimer()Description copied from interface:ResetAbandonedTimerMBeanReset the abandoned timer for the pooled connection.- Specified by:
resetTimerin interfaceResetAbandonedTimerMBean- Returns:
- True if the timer was reset, false if no connection is associated
-
invoke
Description copied from class:JdbcInterceptorGets invoked each time an operation onConnectionis invoked.- Specified by:
invokein interfaceInvocationHandler- Overrides:
invokein classAbstractCreateStatementInterceptor- Throws:
Throwable
-
createStatement
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) Wraps the query reporting statement proxy so that the result sets handed to the application reset the abandoned timer while they are read. Statements that this interceptor does not proxy are passed through unchanged.- Overrides:
createStatementin classAbstractQueryReport- Parameters:
proxy- the actual proxy objectmethod- the method that was called. It will be one of the methods defined inAbstractCreateStatementInterceptor.STATEMENT_TYPESargs- the arguments to the methodstatement- the statement that the underlying connection createdtime- Elapsed time- Returns:
- a
Statementobject
-
prepareCall
Description copied from class:AbstractQueryReportInvoked when prepareCall has been called and completed.- Specified by:
prepareCallin classAbstractQueryReport- Parameters:
query- - the string used to prepare the statement withtime- - the time it took to invoke prepare
-
prepareStatement
Description copied from class:AbstractQueryReportInvoked when prepareStatement has been called and completed.- Specified by:
prepareStatementin classAbstractQueryReport- Parameters:
sql- - the string used to prepare the statement withtime- - the time it took to invoke prepare
-
closeInvoked
public void closeInvoked()Description copied from class:AbstractCreateStatementInterceptorMethod invoked when the operationConnection.close()is invoked.- Specified by:
closeInvokedin classAbstractCreateStatementInterceptor
-
reportFailedQuery
protected String reportFailedQuery(String query, Object[] args, String name, long start, long delta, Throwable t) Description copied from class:AbstractQueryReportInvoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), failed.- Overrides:
reportFailedQueryin classAbstractQueryReport- Parameters:
query- the query that was executed and failedargs- the arguments to the executionname- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the wall clock time the query execution starteddelta- the time the execution took before it failed, measured with the monotonic clockt- the exception that happened- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution, or
nullif the invocation carries no SQL string
-
reportQuery
Description copied from class:AbstractQueryReportInvoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and was within the timing threshold- Overrides:
reportQueryin classAbstractQueryReport- Parameters:
query- the query that was executed and failedargs- the arguments to the executionname- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the wall clock time the query execution starteddelta- the time the execution took, measured with the monotonic clock- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution, or
nullif the invocation carries no SQL string
-
reportSlowQuery
Description copied from class:AbstractQueryReportInvoked when a query execution, a call to an execute method as recognised byAbstractCreateStatementInterceptor.isExecute(Method, boolean), succeeded and was exceeded the timing threshold- Overrides:
reportSlowQueryin classAbstractQueryReport- Parameters:
query- the query that was executed and failedargs- the arguments to the executionname- the name of the method used to executeAbstractCreateStatementInterceptor.isExecute(Method, boolean)start- the wall clock time the query execution starteddelta- the time the execution took, measured with the monotonic clock- Returns:
- - the SQL that was executed or the string "batch" if it was a batch execution, or
nullif the invocation carries no SQL string
-