db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r628142 - in /db/derby/code/trunk/java/engine/org/apache/derby: iapi/reference/ iapi/services/jmx/ impl/services/jmx/ impl/services/jmxnone/ impl/services/monitor/ jdbc/ mbeans/
Date Fri, 15 Feb 2008 18:37:16 GMT
Author: djd
Date: Fri Feb 15 10:37:15 2008
New Revision: 628142

URL: http://svn.apache.org/viewvc?rev=628142&view=rev
Log:
DERBY-3424 (partial) Add initial apis and bean implementations for a management
mbean to control Derby's JMX behaviour. Start and stop the management are
present as operations but currently do nothing. Also fix a bug in DERBY-1387
where shutting down Derby would fail with jmx when multiple mbeans were registered.

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java   (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Module.java
    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/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/jdbc/InternalDriver.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Module.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Module.java?rev=628142&r1=628141&r2=628142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Module.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Module.java Fri Feb 15
10:37:15 2008
@@ -31,5 +31,7 @@
 	String LockFactory = "org.apache.derby.iapi.services.locks.LockFactory";
 	String PropertyFactory = "org.apache.derby.iapi.services.property.PropertyFactory";
 	String ResourceAdapter = "org.apache.derby.iapi.jdbc.ResourceAdapter";
+    
+    String JMX = "org.apache.derby.iapi.services.jmx.ManagementService";
 
 }

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=628142&r1=628141&r2=628142&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
Fri Feb 15 10:37:15 2008
@@ -18,6 +18,8 @@
 package org.apache.derby.iapi.services.jmx;
 
 import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.Module;
+import org.apache.derby.mbeans.ManagementMBean;
 
 
 /**
@@ -32,16 +34,12 @@
 * The following code can be used to locate an instance of this service
 * if running.
 *
-* ManagementService ms = (ManagementService)Monitor.getSystemModule
-*		("org.apache.derby.iapi.services.mbeans.ManagementService");
+* ManagementService ms = (ManagementService)
+*        Monitor.getSystemModule(Module.JMX);
 *
 */
-public interface ManagementService {
-	
-    /* Class name of this interface */
-    public static final String MODULE = 
-            "org.apache.derby.iapi.services.jmx.ManagementService";
-    
+public interface ManagementService extends ManagementMBean {
+   
     /**
      * The domain for all of derby's mbeans: org.apache.derby
      */

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=628142&r1=628141&r2=628142&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
Fri Feb 15 10:37:15 2008
@@ -22,6 +22,7 @@
 import java.security.PrivilegedAction;
 import java.security.PrivilegedActionException;
 import java.security.PrivilegedExceptionAction;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Properties;
 import java.util.Set;
@@ -39,6 +40,8 @@
 import org.apache.derby.iapi.services.monitor.ModuleControl;
 import org.apache.derby.iapi.services.monitor.Monitor;
 import org.apache.derby.iapi.services.property.PropertyUtil;
+import org.apache.derby.mbeans.Management;
+import org.apache.derby.mbeans.ManagementMBean;
 import org.apache.derby.mbeans.VersionMBean;
 
 /** 
@@ -53,7 +56,7 @@
      * Platfrom MBean server, from ManagementFactory.getPlatformMBeanServer().
      */
     private MBeanServer mbeanServer;
-    
+   
     /**
      * The set of mbeans registered by this service.
      */
@@ -82,9 +85,14 @@
     public synchronized void stop() {
         if (mbeanServer == null)
             return;
-        
-        for (ObjectName mbeanName : registeredMbeans)
+
+        // Need a copy of registeredMbeans since unregisterMBean will remove
+        // items from registeredMbeans and thus invalidate any iterator
+        // on it directly.
+        for (ObjectName mbeanName : new HashSet<ObjectName>(registeredMbeans))
             unregisterMBean(mbeanName);
+        
+        mbeanServer = null;
     }
 
     /**
@@ -110,6 +118,10 @@
                     VersionMBean.class,
                     "type=Version,jar=derby.jar");
             
+            registerMBean(this,
+                    ManagementMBean.class,
+                    "type=Management");
+            
         } catch (SecurityException se) {
             // TODO: just ignoring inability to create the mbean server.
             // or should an error or warning be raised?
@@ -209,5 +221,17 @@
             //if (!(jme instanceof InstanceNotFoundException))
                 // throw StandardException.plainWrapException(jme);
         }
+    }
+
+    public synchronized boolean isManagementActive() {
+        return mbeanServer != null;
+    }
+
+    public synchronized void startManagement() {
+        // TODO:
+    }
+
+    public synchronized void stopManagement() {
+        // TODO:
     }
 }

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=628142&r1=628141&r2=628142&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
Fri Feb 15 10:37:15 2008
@@ -34,4 +34,11 @@
     }
     public void unregisterMBean(Object mbeanIdentifier) {
     }
+    public boolean isManagementActive() {
+        return false;
+    }
+    public void startManagement() {
+    }
+    public void stopManagement() {
+    }
 }

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java?rev=628142&r1=628141&r2=628142&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
(original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
Fri Feb 15 10:37:15 2008
@@ -44,6 +44,7 @@
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.services.uuid.UUIDFactory;
 import org.apache.derby.iapi.services.timer.TimerFactory;
+import org.apache.derby.iapi.reference.Module;
 import org.apache.derby.iapi.reference.Property;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.reference.Attribute;
@@ -374,7 +375,7 @@
 
             timerFactory = (TimerFactory)Monitor.startSystemModule("org.apache.derby.iapi.services.timer.TimerFactory");
             
-            Monitor.startSystemModule(ManagementService.MODULE);
+            Monitor.startSystemModule(Module.JMX);
 
 		} catch (StandardException se) {
 

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=628142&r1=628141&r2=628142&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 Fri Feb 15 10:37:15
2008
@@ -23,6 +23,7 @@
 package org.apache.derby.jdbc;
 
 import org.apache.derby.iapi.reference.Attribute;
+import org.apache.derby.iapi.reference.Module;
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.reference.MessageId;
 import org.apache.derby.iapi.services.io.FormatableProperties;
@@ -92,7 +93,7 @@
 		active = true;
         
         mbean = ((ManagementService)
-           Monitor.getSystemModule(ManagementService.MODULE)).registerMBean(
+           Monitor.getSystemModule(Module.JMX)).registerMBean(
                    new JDBC(this),
                    JDBCMBean.class,
                    "type=JDBC");
@@ -106,7 +107,7 @@
 		}
         
         ((ManagementService)
-                Monitor.getSystemModule(ManagementService.MODULE)).unregisterMBean(
+                Monitor.getSystemModule(Module.JMX)).unregisterMBean(
                         mbean);
 
 		active = false;

Added: 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=628142&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Management.java Fri Feb 15 10:37:15
2008
@@ -0,0 +1,68 @@
+/*
+
+   Derby - Class org.apache.derby.mbeans.Management
+
+   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;
+
+import org.apache.derby.iapi.reference.Module;
+import org.apache.derby.iapi.services.monitor.Monitor;
+
+/** 
+ * Management and information for the embedded JDBC driver.
+*/
+public class Management implements ManagementMBean {
+    
+    private ManagementMBean getManagementService() {
+        return (ManagementMBean)
+             Monitor.getSystemModule(Module.JMX);
+    }
+    
+    /**
+     * Start Derby's MBeans.
+     * @see ManagementMBean#startManagement()
+     */
+    public void startManagement() {
+        
+        ManagementMBean mgmtService = getManagementService();
+        if (mgmtService != null)
+            mgmtService.startManagement();   
+    }
+    
+    /**
+     * Stop Derby's MBeans.
+     * @see ManagementMBean#stopManagement()
+     */
+    public void stopManagement() {
+        ManagementMBean mgmtService = getManagementService();
+        if (mgmtService != null)
+            mgmtService.stopManagement();
+    }
+
+    /**
+     * Return state of Derby's JMX management.
+     * @see ManagementMBean#isManagementActive()
+     */
+    public boolean isManagementActive() {
+        ManagementMBean mgmtService = getManagementService();
+        if (mgmtService == null)
+             return false;
+        return mgmtService.isManagementActive();
+    }
+}

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

Added: 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=628142&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/ManagementMBean.java Fri Feb 15
10:37:15 2008
@@ -0,0 +1,49 @@
+/*
+
+   Derby - Class org.apache.derby.mbeans.ManagementMBean
+
+   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;
+
+/**
+ * JMX MBean inteface to control visibility of Derby's MBeans.
+ */
+public interface ManagementMBean {
+    
+    /**
+     * Is Derby's JMX management active. If active then Derby
+     * has registered MBeans relevant to its current state.
+     * @return true Derby has registered beans, false Derby has not
+     * registered any beans.
+     */
+    public boolean isManagementActive();
+    
+    /**
+     * Inform Derby to start its JMX management by registering
+     * MBeans relevant to its current state. If Derby is not
+     * booted then no action is taken.
+     */
+    public void startManagement();
+    
+    /**
+     * Inform Derby to stop its JMX management by unregistering
+     * its MBeans. If Derby is not booted then no action is taken.
+     */
+    public void stopManagement();
+}

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



Mime
View raw message