tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kfuj...@apache.org
Subject svn commit: r1822746 - in /tomcat/tc8.5.x/trunk: modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/JmxUtil.java webapps/docs/changelog.xml
Date Wed, 31 Jan 2018 05:37:41 GMT
Author: kfujino
Date: Wed Jan 31 05:37:40 2018
New Revision: 1822746

URL: http://svn.apache.org/viewvc?rev=1822746&view=rev
Log:
Enhance the JMX support for jdbc-pool in order to expose PooledConnection and JdbcInterceptors.

Added:
    tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/JmxUtil.java
  (with props)
Modified:
    tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.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/jmx/ConnectionPool.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java?rev=1822746&r1=1822745&r2=1822746&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
(original)
+++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/ConnectionPool.java
Wed Jan 31 05:37:40 2018
@@ -20,9 +20,12 @@ import java.util.concurrent.ConcurrentLi
 import java.util.concurrent.atomic.AtomicInteger;
 
 import javax.management.MBeanNotificationInfo;
+import javax.management.MBeanRegistration;
+import javax.management.MBeanServer;
 import javax.management.Notification;
 import javax.management.NotificationBroadcasterSupport;
 import javax.management.NotificationListener;
+import javax.management.ObjectName;
 
 import org.apache.juli.logging.Log;
 import org.apache.juli.logging.LogFactory;
@@ -31,7 +34,9 @@ import org.apache.tomcat.jdbc.pool.PoolP
 import org.apache.tomcat.jdbc.pool.PoolUtilities;
 import org.apache.tomcat.jdbc.pool.Validator;
 
-public class ConnectionPool extends NotificationBroadcasterSupport implements ConnectionPoolMBean
 {
+public class ConnectionPool extends NotificationBroadcasterSupport
+        implements ConnectionPoolMBean, MBeanRegistration {
+
     /**
      * logger
      */
@@ -52,6 +57,11 @@ public class ConnectionPool extends Noti
     protected ConcurrentLinkedQueue<NotificationListener> listeners =
             new ConcurrentLinkedQueue<>();
 
+    /**
+     * the ObjectName of this pool.
+     */
+    private ObjectName oname = null;
+
     public ConnectionPool(org.apache.tomcat.jdbc.pool.ConnectionPool pool) {
         super();
         this.pool = pool;
@@ -65,6 +75,29 @@ public class ConnectionPool extends Noti
         return pool.getPoolProperties();
     }
 
+    public ObjectName getObjectName() {
+        return oname;
+    }
+
+    @Override
+    public ObjectName preRegister(MBeanServer server, ObjectName name)
+            throws Exception {
+        this.oname = name;
+        return name;
+    }
+
+    @Override
+    public void postRegister(Boolean registrationDone) {
+    }
+
+    @Override
+    public void preDeregister() throws Exception {
+    }
+
+    @Override
+    public void postDeregister() {
+    }
+
     //=================================================================
     //       NOTIFICATION INFO
     //=================================================================
@@ -948,9 +981,4 @@ public class ConnectionPool extends Noti
         pool.purgeOnReturn();
 
     }
-
-
-
-
-
 }

Added: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/JmxUtil.java
URL: http://svn.apache.org/viewvc/tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/JmxUtil.java?rev=1822746&view=auto
==============================================================================
--- tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/JmxUtil.java
(added)
+++ tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/JmxUtil.java
Wed Jan 31 05:37:40 2018
@@ -0,0 +1,59 @@
+/*
+ * 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.jmx;
+
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.MalformedObjectNameException;
+import javax.management.ObjectName;
+
+import org.apache.juli.logging.Log;
+import org.apache.juli.logging.LogFactory;
+
+public class JmxUtil {
+    private static final Log log = LogFactory.getLog(JmxUtil.class);
+
+    public static ObjectName registerJmx(ObjectName base, String keyprop, Object obj) {
+        ObjectName oname = null;
+        try {
+            oname = getObjectName(base, keyprop);
+            if (oname != null) ManagementFactory.getPlatformMBeanServer().registerMBean(obj,
oname);
+        } catch (Exception e) {
+            log.error("Jmx registration failed.",e);
+        }
+        return oname;
+    }
+
+    public static void unregisterJmx(ObjectName oname) {
+        if (oname ==null) return;
+        try {
+            ManagementFactory.getPlatformMBeanServer().unregisterMBean(oname);
+        } catch (Exception e) {
+            log.error("Jmx unregistration failed.",e);
+        }
+    }
+
+    private static ObjectName getObjectName(ObjectName base, String keyprop)
+            throws MalformedObjectNameException {
+        if (base == null) return null;
+        StringBuilder OnameStr =  new StringBuilder(base.toString()); 
+        if (keyprop != null) OnameStr.append(keyprop);
+        ObjectName oname = new ObjectName(OnameStr.toString());
+        return oname;
+    }
+}
\ No newline at end of file

Propchange: tomcat/tc8.5.x/trunk/modules/jdbc-pool/src/main/java/org/apache/tomcat/jdbc/pool/jmx/JmxUtil.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=1822746&r1=1822745&r2=1822746&view=diff
==============================================================================
--- tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/tc8.5.x/trunk/webapps/docs/changelog.xml Wed Jan 31 05:37:40 2018
@@ -93,6 +93,15 @@
       </fix>
     </changelog>
   </subsection>
+  <subsection name="jdbc-pool">
+    <changelog>
+      <add>
+        Enhance the JMX support for jdbc-pool in order to expose
+        <code>PooledConnection</code> and <code>JdbcInterceptors</code>.
+        (kfujino)
+      </add>
+    </changelog>
+  </subsection>
 </section>
 <section name="Tomcat 8.5.27 (markt)" rtext="2018-01-22">
   <subsection name="Catalina">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Mime
View raw message