db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r632059 - in /db/derby/code/trunk/java: engine/org/apache/derby/impl/services/jmx/ engine/org/apache/derby/impl/services/jmxnone/ engine/org/apache/derby/mbeans/ testing/org/apache/derbyTesting/functionTests/tests/management/
Date Thu, 28 Feb 2008 17:10:58 GMT
Author: djd
Date: Thu Feb 28 09:10:55 2008
New Revision: 632059

URL: http://svn.apache.org/viewvc?rev=632059&view=rev
Log:
DERBY-3466 Add a system identifier to the ObjectName of MBeans registered by Derby to allow
disambiguating Derby's MBeans when multiple systems are loaded through different class loaders.

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/package.html
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
    db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
Thu Feb 28 09:10:55 2008
@@ -18,6 +18,7 @@
 package org.apache.derby.impl.services.jmx;
 
 import java.lang.management.ManagementFactory;
+import java.security.AccessControlException;
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
@@ -42,6 +43,7 @@
 import org.apache.derby.iapi.services.property.PropertyUtil;
 import org.apache.derby.mbeans.ManagementMBean;
 import org.apache.derby.mbeans.VersionMBean;
+import org.apache.derby.security.SystemPermission;
 
 /** 
  * This class implements the ManagementService interface and provides a simple
@@ -79,6 +81,14 @@
     private ObjectName myManagementBean;
     
     private MBeanServer myManagementServer;
+    
+    /**
+     * Runtime value to disambiguate
+     * multiple Derby systems in the same virtual machine but
+     * different class loaders. Set as the system attribute in
+     * the ObjectName for all MBeans registered.
+     */
+    private String systemIdentifier;
 
     public JMXManagementService() {
 
@@ -98,6 +108,9 @@
         
         registeredMbeans = new HashMap<ObjectName,StandardMBean>();
         
+        systemIdentifier =
+            Monitor.getMonitor().getUUIDFactory().createUUID().toString();
+        
         findServer();
              
         myManagementBean = (ObjectName) registerMBean(this,
@@ -186,7 +199,8 @@
 
         try {
             final ObjectName beanName = new ObjectName(
-                    DERBY_JMX_DOMAIN + ":" + keyProperties);
+                    DERBY_JMX_DOMAIN + ":" + keyProperties
+                    + ",system=" + systemIdentifier);
             
             final StandardMBean standardMBean =
                 new StandardMBean(bean, beanInterface) {
@@ -307,6 +321,8 @@
         if (registeredMbeans == null)
             return;
         
+        checkJMXControl();
+        
         // Already active?
         if (isManagementActive())
             return;
@@ -339,6 +355,8 @@
         if (registeredMbeans == null)
             return;
         
+        checkJMXControl();
+        
         if (isManagementActive()) {
             for (ObjectName mbeanName : registeredMbeans.keySet())
             {
@@ -351,5 +369,22 @@
             }
             mbeanServer = null;
         }
+    }
+
+    private void checkJMXControl() {
+        /* FUTURE DERBY-3462
+        try {
+            AccessController.checkPermission(new SystemPermission("jmxControl"));
+        } catch (AccessControlException e) {
+            // Need to throw a simplified version as AccessControlException
+            // will have a reference to Derby's SystemPermission which most likely
+            // will not be available on the client.
+            throw new SecurityException(e.getMessage());
+        }
+        */
+    }
+
+    public String getSystemIdentifier() {
+        return systemIdentifier;
     }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
Thu Feb 28 09:10:55 2008
@@ -41,4 +41,7 @@
     }
     public void stopManagement() {
     }
+    public String getSystemIdentifier() {
+        return null;
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java Thu Feb 28 09:10:55
2008
@@ -26,7 +26,8 @@
  * <P>
  * Key properties for registered MBean:
  * <UL>
- * <LI> type=JDBC
+ * <LI> <code>type=JDBC</code>
+ * <LI> <code>system=</code><em>runtime system identifier</em>
(see overview)
  * </UL>
 */
 public interface JDBCMBean {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java Thu Feb 28 09:10:55
2008
@@ -73,4 +73,15 @@
              return false;
         return mgmtService.isManagementActive();
     }
+
+    /**
+     * Return the system identifier that this MBean is managing.
+     * @see ManagementMBean#getSystemIdentifier()
+     */
+    public String getSystemIdentifier() {
+        ManagementMBean mgmtService = getManagementService();
+        if (mgmtService == null)
+             return null;
+        return mgmtService.getSystemIdentifier();
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java Thu Feb 28
09:10:55 2008
@@ -33,10 +33,12 @@
  * <P>
  * Key properties for registered MBean when registered by Derby:
  * <UL>
- * <LI> type=Management
+ * <LI> <code>type=Management</code>
+ * <LI> <code>system=</code><em>runtime system identifier</em>
(see overview)
  * </UL>
  * 
  * @see Management
+ * @see ManagementMBean#getSystemIdentifier()
  */
 public interface ManagementMBean {
     
@@ -47,6 +49,15 @@
      * registered any beans.
      */
     public boolean isManagementActive();
+    
+    /**
+     * Get the system identifier that this MBean is managing.
+     * The system identifier is a runtime value to disambiguate
+     * multiple Derby systems in the same virtual machine but
+     * different class loaders.
+     * @return Runtime identifier for the system, null if Derby is not running.
+     */
+    public String getSystemIdentifier();
     
     /**
      * Inform Derby to start its JMX management by registering

Modified: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java Thu Feb 28 09:10:55
2008
@@ -32,8 +32,9 @@
  * <P>
  * Key properties for registered MBean:
  * <UL>
- * <LI> type=Version
- * <LI> jar={derby.jar|derbynet.jar}
+ * <LI> <code>type=Version</code>
+ * <LI> <code>jar={derby.jar|derbynet.jar}</code>
+ * <LI> <code>system=</code><em>runtime system identifier</em>
(see overview)
  * </UL>
 */
 public interface VersionMBean {

Modified: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/package.html
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/mbeans/package.html?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/package.html (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/package.html Thu Feb 28 09:10:55
2008
@@ -21,8 +21,20 @@
 a number of MBeans to monitor and manage Derby.
 <P>
 Derby registers its JMX MBeans in the <code>org.apache.derby</code> domain and
-always includes a value for <code>type</code> in the MBean's ObjectName's key
+always includes values for <code>type</code> and <code>system</code>
in the MBean's ObjectName's key
 properties. Other key properties are described in the interface class for the MBean.
+<UL>
+<LI> <code>type</code> Set to the class name of the MBean's interface class
without
+the package and without <code>MBean</code>. E.g. for <code>org.apache.derby.mbeans.VersionMBean</code>
+the key property <code>type</code> will be set to <code>Version</code>.
The javadoc for each MBean
+also indicates what <code>type</code> will be set to.
+<LI> <code>system</code> Set to a runtime identifier that allows Derby
and applications
+to disambiguate multiple Derby systems in the same virtual machine but different class loaders.
+Currently a new value is created each time Derby is booted. An application may discover the
+value of the identifier by registering the MBean <code>org.apache.derby.mbeans.Management</code>
+and accessing the <code>SystemIdentifier</code>. This application created <code>ManagementMBean</code>
+must be running in the same class loader as Derby.
+</UL>
 <P>
 Derby registers the class name for any MBean to be the interface class for the MBean
 (i.e. <code>org.apache.derby.mbeans.*MBean</code>) to hide the implementation
class

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/JMXTest.java
Thu Feb 28 09:10:55 2008
@@ -21,11 +21,15 @@
 
 package org.apache.derbyTesting.functionTests.tests.management;
 
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.sql.SQLException;
 import java.util.Set;
 
 import javax.management.MBeanInfo;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
+import javax.sql.DataSource;
 
 import junit.framework.Test;
 
@@ -71,6 +75,15 @@
             // Is the class name in the public api
             assertTrue(mbeanClassName.startsWith("org.apache.derby.mbeans."));
             
+            // See if it was the application created ManagementMBean
+            // This will have the implementation class registered
+            // as the class name since it is not registered by Derby.
+            if ("Management".equals(type)
+                    && "org.apache.derby.mbeans.Management".equals(mbeanClassName))
+            {
+                continue;
+            }
+                    
             // and is a Derby specific MBean.
             assertTrue(mbeanClassName.endsWith("MBean"));
             

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/MBeanTest.java
Thu Feb 28 09:10:55 2008
@@ -23,6 +23,7 @@
 
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.Hashtable;
 import java.util.Set;
 
 import javax.management.MBeanServerConnection;
@@ -225,6 +226,24 @@
         }
         
         return mgmtObjName;
+    }
+    
+    /**
+     * Get the ObjectName for an MBean registered by Derby for a set of
+     * key properties. The ObjectName has the org.apache.derby and
+     * the key property <code>system</code> will be set to the system identifier
+     * for the Derby system under test (if Derby is running).
+     * @param keyProperties Set of key properties, may be modified by this call.
+     * @return ObjectName to access MBean.
+     */
+    protected ObjectName getDerbyMBeanName(Hashtable<String,String> keyProperties)
+        throws Exception
+    {
+        String systemIdentifier = (String)
+                  getAttribute(getApplicationManagementMBean(), "SystemIdentifier");
+        if (systemIdentifier != null)
+            keyProperties.put("system", systemIdentifier);
+        return new ObjectName("org.apache.derby", keyProperties);
     }
     
     /**

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/ManagementMBeanTest.java
Thu Feb 28 09:10:55 2008
@@ -79,9 +79,11 @@
         invokeOperation(mbean, "stopManagement");
         assertBooleanAttribute(false, mbean, "ManagementActive");
         
-        // leaving only management MBeans.
+        // leaving only management MBeans, the one registered
+        // by this test and the one registered by Derby
+        // (which has the system key property).
         Set<ObjectName> managementOnly = getDerbyDomainMBeans();
-        assertEquals(1, managementOnly.size());
+        assertEquals(2, managementOnly.size());
         for (ObjectName name : managementOnly)
         {
             assertEquals("Management", name.getKeyProperty("type"));

Modified: db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java?rev=632059&r1=632058&r2=632059&view=diff
==============================================================================
--- db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java
(original)
+++ db/derby/code/trunk/java/testing/org/apache/derbyTesting/functionTests/tests/management/VersionMBeanTest.java
Thu Feb 28 09:10:55 2008
@@ -74,13 +74,13 @@
      * @throws MalformedObjectNameException if the object name is not valid
      */
     private ObjectName getDerbyJarObjectName() 
-            throws MalformedObjectNameException {
+            throws Exception {
         
         // get a reference to the VersionMBean instance for derby.jar
         Hashtable<String, String> keyProps = new Hashtable<String, String>();
         keyProps.put("type", "Version");
         keyProps.put("jar", "derby.jar");
-        return new ObjectName("org.apache.derby", keyProps);
+        return getDerbyMBeanName(keyProps);
     }
     
     //



Mime
View raw message