Author: kfujino Date: Thu Feb 1 08:49:14 2018 New Revision: 1822861 URL: http://svn.apache.org/viewvc?rev=1822861&view=rev Log: Add MBean for ResetAbandonedTimer.
Added: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimerMBean.java (with props) Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Modified: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java?rev=1822861&r1=1822860&r2=1822861&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java (original) +++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimer.java Thu Feb 1 08:49:14 2018 @@ -19,9 +19,11 @@ package org.apache.tomcat.jdbc.pool.inte import java.lang.reflect.Method; -import org.apache.tomcat.jdbc.pool.JdbcInterceptor; +import javax.management.ObjectName; + +import org.apache.tomcat.jdbc.pool.ConnectionPool; import org.apache.tomcat.jdbc.pool.PooledConnection; -import org.apache.tomcat.jdbc.pool.ProxyConnection; +import org.apache.tomcat.jdbc.pool.jmx.JmxUtil; /** * Class that resets the abandoned timer on any activity on the @@ -31,30 +33,43 @@ import org.apache.tomcat.jdbc.pool.Proxy * This is useful for batch processing programs that use connections for extensive amount of times. * */ -public class ResetAbandonedTimer extends AbstractQueryReport { +public class ResetAbandonedTimer extends AbstractQueryReport implements ResetAbandonedTimerMBean { + + private PooledConnection pcon; + + private ObjectName oname = null; public ResetAbandonedTimer() { } + @Override + public void reset(ConnectionPool parent, PooledConnection con) { + super.reset(parent, con); + if (con == null) { + this.pcon = null; + if (oname != null) { + JmxUtil.unregisterJmx(oname); + oname = null; + } + } else { + this.pcon = con; + if (oname == null) { + String keyprop = ",JdbcInterceptor=" + getClass().getSimpleName(); + oname = JmxUtil.registerJmx(pcon.getObjectName(), keyprop, this); + } + } + } + + @Override public boolean resetTimer() { boolean result = false; - JdbcInterceptor interceptor = this.getNext(); - while (interceptor!=null && result==false) { - if (interceptor instanceof ProxyConnection) { - PooledConnection con = ((ProxyConnection)interceptor).getConnection(); - if (con!=null) { - con.setTimestamp(System.currentTimeMillis()); - result = true; - } else { - break; - } - } - interceptor = interceptor.getNext(); + if (pcon != null) { + pcon.setTimestamp(System.currentTimeMillis()); + result = true; } return result; } - @Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { Object result = super.invoke(proxy, method, args); Added: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimerMBean.java URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimerMBean.java?rev=1822861&view=auto ============================================================================== --- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimerMBean.java (added) +++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimerMBean.java Thu Feb 1 08:49:14 2018 @@ -0,0 +1,22 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.tomcat.jdbc.pool.interceptor; + +public interface ResetAbandonedTimerMBean { + public boolean resetTimer(); +} Propchange: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/interceptor/ResetAbandonedTimerMBean.java ------------------------------------------------------------------------------ svn:eol-style = native Modified: tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml?rev=1822861&r1=1822860&r2=1822861&view=diff ============================================================================== --- tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml (original) +++ tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Thu Feb 1 08:49:14 2018 @@ -110,6 +110,9 @@ Expose the cache size for each connection via JMX in <code>StatementCache</code>. (kfujino) </add> + <add> + Add MBean for <code>ResetAbandonedTimer</code>. (kfujino) + </add> </changelog> </subsection> </section> --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org