db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r627877 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/services/jmx/ impl/services/jmx/ impl/services/jmxnone/ jdbc/ mbeans/
Date Thu, 14 Feb 2008 21:31:27 GMT
Author: djd
Date: Thu Feb 14 13:31:25 2008
New Revision: 627877

URL: http://svn.apache.org/viewvc?rev=627877&view=rev
Log:
DERBY-1387 Expose an api in ManagementService to register and unregister Mbeans. Use this
for a simple JDBCMBean that reports some information about the JDBC driver.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/JDBC.java   (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
    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/jdbc/InternalDriver.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java?rev=627877&r1=627876&r2=627877&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
Thu Feb 14 13:31:25 2008
@@ -17,6 +17,8 @@
 
 package org.apache.derby.iapi.services.jmx;
 
+import org.apache.derby.iapi.error.StandardException;
+
 
 /**
 * This interface represents a Management Service. An implementation of this 
@@ -39,4 +41,37 @@
     /* Class name of this interface */
     public static final String MODULE = 
             "org.apache.derby.iapi.services.jmx.ManagementService";
+    
+    /**
+     * The domain for all of derby's mbeans: org.apache.derby
+     */
+    public static final String DERBY_JMX_DOMAIN = "org.apache.derby";
+    
+    /**
+     * Registers an MBean with the MBean server.
+     * The object name instance 
+     * represented by the given String will be created by this method.
+     * The mbean will be unregistered automatically when Derby shutsdown.
+     * 
+     * @param bean The MBean to wrap with a StandardMBean and register
+     * @param beanInterface The management interface for the MBean.
+     * @param nameAttributes The String representation of the MBean's attrributes,
+     * they will be added into the ObjectName with Derby's domain. Attribute
+     * type should be first with a short name for the bean, typically the
+     * class name without the package.
+     * 
+     * @return An idenitifier that can later be used to unregister the mbean.
+     */
+    public Object registerMBean(Object bean,
+            Class beanInterface,
+            String nameAttributes)
+            throws StandardException;
+    
+    /**
+     * Unregister a mbean previously registered with registerMBean.
+     * 
+     * @param mbeanIdentifier An identifier returned by registerMBean.
+     * @throws StandardException Error unregistering bean.
+     */
+    public void unregisterMBean(Object mbeanIdentifier);
 }

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=627877&r1=627876&r2=627877&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 14 13:31:25 2008
@@ -26,6 +26,7 @@
 import java.util.Properties;
 import java.util.Set;
 
+import javax.management.InstanceNotFoundException;
 import javax.management.JMException;
 import javax.management.MBeanServer;
 import javax.management.ObjectName;
@@ -83,11 +84,7 @@
             return;
         
         for (ObjectName mbeanName : registeredMbeans)
-            try {
-                unregisterMBean(mbeanName);
-            } catch (StandardException e) {
-                // TODO: what to do here?
-            }
+            unregisterMBean(mbeanName);
     }
 
     /**
@@ -111,7 +108,7 @@
 
             registerMBean(new Version(Monitor.getMonitor().getEngineVersion()),
                     VersionMBean.class,
-                    "org.apache.derby:type=Version,jar=derby.jar");
+                    "type=Version,jar=derby.jar");
             
         } catch (SecurityException se) {
             // TODO: just ignoring inability to create the mbean server.
@@ -130,19 +127,21 @@
      * 
      * @param bean The MBean to wrap with a StandardMBean and register
      * @param beanInterface The management interface for the MBean.
-     * @param name The String representation of the MBean's object name.
+     * @param nameAttributes The String representation of the MBean's attrributes,
+     * they will be added into the ObjectName with Derby's domain
      * 
      */
-    private synchronized void registerMBean(final Object bean,
+    public synchronized Object registerMBean(final Object bean,
             final Class beanInterface,
-            final String name)
+            final String nameAttributes)
             throws StandardException {
 
         if (mbeanServer == null)
-            return;
+            return null;
 
         try {
-            final ObjectName beanName = new ObjectName(name);
+            final ObjectName beanName = new ObjectName(
+                    DERBY_JMX_DOMAIN + ":" + nameAttributes);
             final StandardMBean standardMBean =
                 new StandardMBean(bean, beanInterface);
             try {
@@ -158,6 +157,7 @@
                         });
                 
                 registeredMbeans.add(beanName);
+                return beanName;
 
             } catch (PrivilegedActionException pae) {
                 throw (JMException) pae.getException();
@@ -168,12 +168,21 @@
     }
     
     /**
+     * Unregister an mbean using an object previous returned
+     * from registerMBean.
+     */
+    public void unregisterMBean(Object mbeanIdentifier)
+    {
+        if (mbeanIdentifier == null)
+            return;
+        unregisterMBean((ObjectName) mbeanIdentifier);
+    }
+    
+    /**
      * Unregisters an mbean that was registered  by this service.
      * @param mbeanName Bean to unregister.
-     * @throws StandardException
      */
     private synchronized void unregisterMBean(final ObjectName mbeanName)
-        throws StandardException
     {
         if (!registeredMbeans.remove(mbeanName))
             return;
@@ -194,7 +203,11 @@
                     });
 
         } catch (PrivilegedActionException pae) {
-            throw StandardException.plainWrapException(pae.getException());
+            // TODO - this is called on shutdown where
+            // we don't really care about errors.
+            // JMException jme = (JMException) pae.getException();
+            //if (!(jme instanceof InstanceNotFoundException))
+                // throw StandardException.plainWrapException(jme);
         }
     }
 }

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=627877&r1=627876&r2=627877&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 14 13:31:25 2008
@@ -23,7 +23,15 @@
  * Dummy management service for environments that do not support
  * JMX, such as JDK 1.4 and J2ME.
 */
-public class NoManagementService implements ManagementService {
+public final class NoManagementService implements ManagementService {
     public NoManagementService() {
+    }
+    public Object registerMBean(final Object bean,
+            final Class beanInterface,
+            final String nameAttributes)
+    {
+        return null;
+    }
+    public void unregisterMBean(Object mbeanIdentifier) {
     }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java?rev=627877&r1=627876&r2=627877&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java Thu Feb 14 13:31:25
2008
@@ -36,6 +36,7 @@
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.i18n.MessageService;
+import org.apache.derby.iapi.services.jmx.ManagementService;
 
 import org.apache.derby.iapi.sql.ResultSet;
 
@@ -43,6 +44,7 @@
 import org.apache.derby.iapi.sql.ResultColumnDescriptor;
 
 import org.apache.derby.impl.jdbc.*;
+import org.apache.derby.mbeans.JDBCMBean;
 
 import java.sql.Connection;
 import java.sql.DatabaseMetaData;
@@ -60,6 +62,8 @@
     
 	private static final Object syncMe = new Object();
 	private static InternalDriver activeDriver;
+    
+    private Object mbean;
 
 	protected boolean active;
 	private ContextService contextServiceFactory;
@@ -86,6 +90,12 @@
 		}
 
 		active = true;
+        
+        mbean = ((ManagementService)
+           Monitor.getSystemModule(ManagementService.MODULE)).registerMBean(
+                   new JDBC(this),
+                   JDBCMBean.class,
+                   "type=JDBC");
 	}
 
 	public void stop() {
@@ -94,6 +104,10 @@
 		{
 			InternalDriver.activeDriver = null;
 		}
+        
+        ((ManagementService)
+                Monitor.getSystemModule(ManagementService.MODULE)).unregisterMBean(
+                        mbean);
 
 		active = false;
 

Added: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/JDBC.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/jdbc/JDBC.java?rev=627877&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/jdbc/JDBC.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/jdbc/JDBC.java Thu Feb 14 13:31:25 2008
@@ -0,0 +1,62 @@
+/*
+
+   Derby - Class org.apache.derby.jdbc.JDBC
+
+   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.derby.jdbc;
+
+import org.apache.derby.iapi.services.info.JVMInfo;
+import org.apache.derby.mbeans.JDBCMBean;
+
+/**
+ * Simple JBDC mbean that pulls information
+ * about the JDBC driver.
+ * 
+ */
+final class JDBC implements JDBCMBean
+{ 
+    private final InternalDriver driver;
+    JDBC(InternalDriver driver)
+    {
+        this.driver = driver;
+    }
+
+    public String getDriverLevel() {
+        return JVMInfo.derbyVMLevel();
+    }
+
+    public int getMajorVersion() {
+         return driver.getMajorVersion();
+    }
+
+    public int getMinorVersion() {
+        return driver.getMinorVersion();
+    }
+    
+    public boolean isCompliantDriver()
+    {
+        return driver.jdbcCompliant();
+    }
+    
+    public boolean acceptsURL(String url)
+    {
+        return driver.acceptsURL(url);
+    }
+}
+

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/jdbc/JDBC.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=627877&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java Thu Feb 14 13:31:25
2008
@@ -0,0 +1,63 @@
+/*
+
+   Derby - Class org.apache.derby.mbeans.JDBCMBean
+
+   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.derby.mbeans;
+
+/** 
+ * Management and information for the embedded JDBC driver.
+*/
+public interface JDBCMBean {
+    
+    /**
+     * Get the JDBC driver's implementation level
+     */
+    public String getDriverLevel();
+
+    /**
+     * Return the JDBC driver's major version.
+     * @return major version
+     * @see java.sql.Driver#getMajorVersion()
+     */
+    public int getMajorVersion();
+    
+    /**
+     * Return the JDBC driver's minor version.
+     * @return minor version
+     * @see java.sql.Driver#getMinorVersion()
+     */
+    public int getMinorVersion();
+    
+    /**
+     * Is the JDBC driver compliant.
+     * @return compliance state
+     * @see java.sql.Driver#jdbcCompliant()
+     */
+    public boolean isCompliantDriver();
+    
+    /**
+     * Does the driver accept the passed in JDBC URL
+     * @param url JDBC URL to check.
+     * @return True if it supports it, false otherwise.
+     * @see java.sql.Driver#acceptsURL(String)
+     */
+    public boolean acceptsURL(String url);
+
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/JDBCMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message