You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by ma...@apache.org on 2013/12/10 21:07:14 UTC

svn commit: r1549952 - in /commons/proper/pool/trunk/src: changes/changes.xml main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java

Author: markt
Date: Tue Dec 10 20:07:13 2013
New Revision: 1549952

URL: http://svn.apache.org/r1549952
Log:
Provide more control over the names under which Pools are registered in JMX so components using the pools can register the pools they use under a related name.

Modified:
    commons/proper/pool/trunk/src/changes/changes.xml
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
    commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java

Modified: commons/proper/pool/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/changes/changes.xml?rev=1549952&r1=1549951&r2=1549952&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/changes/changes.xml (original)
+++ commons/proper/pool/trunk/src/changes/changes.xml Tue Dec 10 20:07:13 2013
@@ -43,8 +43,9 @@ The <action> type attribute can be add,u
     <title>Apache Commons Pool Changes</title>
   </properties>
   <body>
-  <release version="2.0.1" date="TBD" description=
-      "This is a patch release, including bugfixes and test case improvements.">
+  <release version="2.1" date="TBD" description=
+      "This is a maintenance release that includes a small number of new
+       features as well as including bugfixes and test case improvements.">
     <action issue="POOL-240" dev="psteitz" type="fix" due-to="Dan McNulty">
       Ensured that blocked threads waiting on a depleted pool get served when
       objects are destroyed due to validation or passivation failures in
@@ -53,6 +54,11 @@ The <action> type attribute can be add,u
     <action issue="POOL-241" dev="markt" type="add" due-to="Bruno P. Kinoshita">
       Expand the coverage of the unit tests.
     </action>
+    <action dev="markt" type="add">
+      Provide more control over the names under which Pools are registered in
+      JMX so components using the pools can register the pools they use under a
+      related name.
+    </action>
   </release>
   <release version="2.0" date="2013-11-11" description=
 "This is a major new release that provides significant performance improvements

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java?rev=1549952&r1=1549951&r2=1549952&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java (original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseGenericObjectPool.java Tue Dec 10 20:07:13 2013
@@ -121,13 +121,14 @@ public abstract class BaseGenericObjectP
      * monitoring.
      *
      * @param config        Pool configuration
-     * @param jmxNameBase   Base JMX name for the new pool
+     * @param jmxNameBase   The default base JMX name for the new pool unless
+     *                      overridden by the config
      * @param jmxNamePrefix Prefix to be used for JMX name for the new pool
      */
     public BaseGenericObjectPool(BaseObjectPoolConfig config,
             String jmxNameBase, String jmxNamePrefix) {
         if (config.getJmxEnabled()) {
-            this.oname = jmxRegister(jmxNameBase, jmxNamePrefix);
+            this.oname = jmxRegister(config, jmxNameBase, jmxNamePrefix);
         } else {
             this.oname = null;
         }
@@ -869,32 +870,44 @@ public abstract class BaseGenericObjectP
      * registered. Swallows MBeanRegistrationException, NotCompliantMBeanException
      * returning null.
      *
-     * @param jmxNameBase base JMX name for this pool
+     * @param config Pool configuration
+     * @param jmxNameBase default base JMX name for this pool
      * @param jmxNamePrefix name prefix
      * @return registered ObjectName, null if registration fails
      */
-    private ObjectName jmxRegister(String jmxNameBase, String jmxNamePrefix) {
+    private ObjectName jmxRegister(BaseObjectPoolConfig config,
+            String jmxNameBase, String jmxNamePrefix) {
         ObjectName objectName = null;
         MBeanServer mbs = ManagementFactory.getPlatformMBeanServer();
         int i = 1;
         boolean registered = false;
+        String base = config.getJmxNameBase();
+        if (base == null) {
+            base = jmxNameBase;
+        }
         while (!registered) {
             try {
-                ObjectName objName =
-                    new ObjectName(jmxNameBase + jmxNamePrefix + i);
+                ObjectName objName;
+                // Skip the numeric suffix for the first pool in case there is
+                // only one so the names are cleaner.
+                if (i == 1) {
+                    objName = new ObjectName(base + jmxNamePrefix);
+                } else {
+                    objName = new ObjectName(base + jmxNamePrefix + i);
+                }
                 mbs.registerMBean(this, objName);
                 objectName = objName;
                 registered = true;
             } catch (MalformedObjectNameException e) {
                 if (BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX.equals(
-                        jmxNamePrefix)) {
+                        jmxNamePrefix) && jmxNameBase.equals(base)) {
                     // Shouldn't happen. Skip registration if it does.
                     registered = true;
                 } else {
-                    // Must be an invalid name prefix. Use the default
-                    // instead.
+                    // Must be an invalid name. Use the defaults instead.
                     jmxNamePrefix =
                             BaseObjectPoolConfig.DEFAULT_JMX_NAME_PREFIX;
+                    base = jmxNameBase;
                 }
             } catch (InstanceAlreadyExistsException e) {
                 // Increment the index and try again

Modified: commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java
URL: http://svn.apache.org/viewvc/commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java?rev=1549952&r1=1549951&r2=1549952&view=diff
==============================================================================
--- commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java (original)
+++ commons/proper/pool/trunk/src/main/java/org/apache/commons/pool2/impl/BaseObjectPoolConfig.java Tue Dec 10 20:07:13 2013
@@ -120,6 +120,15 @@ public abstract class BaseObjectPoolConf
     public static final String DEFAULT_JMX_NAME_PREFIX = "pool";
 
     /**
+     * The default value for the base name to use to name JMX enabled pools
+     * created with a configuration instance. The default is <code>null</code>
+     * which means the pool will provide the base name to use.
+     * @see GenericObjectPool#getJmxName()
+     * @see GenericKeyedObjectPool#getJmxName()
+     */
+    public static final String DEFAULT_JMX_NAME_BASE = null;
+
+    /**
      * The default value for the {@code evictionPolicyClassName} configuration
      * attribute.
      * @see GenericObjectPool#getEvictionPolicyClassName()
@@ -159,6 +168,8 @@ public abstract class BaseObjectPoolConf
 
     private String jmxNamePrefix = DEFAULT_JMX_NAME_PREFIX;
 
+    private String jmxNameBase = DEFAULT_JMX_NAME_PREFIX;
+
 
     /**
      * Get the value for the {@code lifo} configuration attribute for pools
@@ -497,6 +508,32 @@ public abstract class BaseObjectPoolConf
     }
 
     /**
+     * Gets the value of the JMX name base that will be used as part of the
+     * name assigned to JMX enabled pools created with this configuration
+     * instance. A value of <code>null</code> means that the pool will define
+     * the JMX name base.
+     *
+     * @return  The current setting of {@code jmxNameBase} for this
+     *          configuration instance
+     */
+    public String getJmxNameBase() {
+        return jmxNameBase;
+    }
+
+    /**
+     * Sets the value of the JMX name base that will be used as part of the
+     * name assigned to JMX enabled pools created with this configuration
+     * instance. A value of <code>null</code> means that the pool will define
+     * the JMX name base.
+     *
+     * @param jmxNameBase The new setting of {@code jmxNameBase}
+     *        for this configuration instance
+     */
+    public void setJmxNameBase(String jmxNameBase) {
+        this.jmxNameBase = jmxNameBase;
+    }
+
+    /**
      * Gets the value of the JMX name prefix that will be used as part of the
      * name assigned to JMX enabled pools created with this configuration
      * instance.