db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d..@apache.org
Subject svn commit: r627062 - in /db/derby/code/trunk/java/engine/org/apache/derby: ./ iapi/reference/ iapi/services/jmx/ impl/services/ impl/services/jmx/ impl/services/jmxnone/ impl/services/monitor/ mbeans/
Date Tue, 12 Feb 2008 19:50:45 GMT
Author: djd
Date: Tue Feb 12 11:50:42 2008
New Revision: 627062

URL: http://svn.apache.org/viewvc?rev=627062&view=rev
Log:
DERBY-1387 (partial) Initial JMX support including obtaining the platform mbean server and
registering a single Version mbean for the embedded engine. JMX functionality enabled by derby.system.jmx,
need follow on work for derby's builtin policy files.
Based upon contributions by Ole Gunnar Borstad, Bernt M. Johnsen, John H. Embretsen and Dan
Debrunner. (all have icla's on file).

Added:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
  (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Version.java   (with props)
    db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java   (with props)
Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml
    db/derby/code/trunk/java/engine/org/apache/derby/impl/services/monitor/BaseMonitor.java
    db/derby/code/trunk/java/engine/org/apache/derby/modules.properties

Modified: db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java?rev=627062&r1=627061&r2=627062&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/reference/Property.java Tue Feb
12 11:50:42 2008
@@ -885,6 +885,12 @@
 	// Define a static string for collation derivation NONE
 	public static final String COLLATION_NONE =
 		"NONE";
+        
+    /**
+     * derby.system.jmx
+     * enable or disable JMX
+     */    
+    public final static String JMX = "derby.system.jmx";
 
     /**
      * db2j.storage.dataNotSyncedAtCheckPoint

Added: 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=627062&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
Tue Feb 12 11:50:42 2008
@@ -0,0 +1,42 @@
+/*
+   Derby Classname org.apache.derby.iapi.services.jmx.ManagementService
+  
+   Licensed 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.iapi.services.jmx;
+
+
+/**
+* This interface represents a Management Service. An implementation of this 
+* service is started by the Derby monitor if the system property derby.system.jmx has
+* been set. The following services are provided:
+* 
+*	<li> Create and start an instance of MBean server to register MBeans.
+*       <li> Create managed beans (MBeans) to instrument derby resources for
+*            management and monitoring.
+* 
+* 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");
+*
+*/
+public interface ManagementService {
+	
+    /* Class name of this interface */
+    public static final String MODULE = 
+            "org.apache.derby.iapi.services.jmx.ManagementService";
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/iapi/services/jmx/ManagementService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml?rev=627062&r1=627061&r2=627062&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/build.xml Tue Feb 12 11:50:42
2008
@@ -58,6 +58,7 @@
       <exclude name="${derby.dir}/impl/services/cache/CacheEntry.java"/>
       <exclude name="${derby.dir}/impl/services/cache/*Policy.java"/>
       <exclude name="${derby.dir}/impl/services/cache/BackgroundCleaner.java"/>
+      <exclude name="${derby.dir}/impl/services/jmx/**"/>
     </javac>
  </target>
  
@@ -84,6 +85,7 @@
      <include name="${derby.dir}/impl/services/cache/CacheEntry.java"/>
      <include name="${derby.dir}/impl/services/cache/*Policy.java"/>
      <include name="${derby.dir}/impl/services/cache/BackgroundCleaner.java"/>
+   	 <include name="${derby.dir}/impl/services/jmx/**"/>
    </javac>
  </target>
 

Added: 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=627062&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
Tue Feb 12 11:50:42 2008
@@ -0,0 +1,187 @@
+/*
+ Derby Classname org.apache.derby.impl.services.jmx.JMXManagementService
+ 
+ Licensed 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.impl.services.jmx;
+
+import java.lang.management.ManagementFactory;
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+import java.security.PrivilegedActionException;
+import java.security.PrivilegedExceptionAction;
+import java.util.HashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import javax.management.JMException;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.derby.iapi.error.StandardException;
+import org.apache.derby.iapi.reference.Property;
+import org.apache.derby.iapi.services.jmx.ManagementService;
+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.Version;
+
+/** 
+ * This class implements the ManagementService interface and provides a simple
+ * management and monitoring service.
+ *
+ * @see org.apache.derby.iapi.services.jmx.ManagementService
+ */
+public class JMXManagementService implements ManagementService, ModuleControl {
+
+    /**
+     * Platfrom MBean server, from ManagementFactory.getPlatformMBeanServer().
+     */
+    private MBeanServer mbeanServer;
+    
+    /**
+     * The set of mbeans registered by this service.
+     */
+    private Set<ObjectName> registeredMbeans;
+
+    public JMXManagementService() {
+
+    }
+
+    /**
+     * Start the management service if derby.system.jmx is true.
+     * <P>
+     * Starting the service means:
+     * <UL>
+     * <LI> getting the platform MBeanServer which may require starting it
+     * <LI> registering a Version mbean representing the system
+     * </UL>
+     */
+    public void boot(boolean create, Properties properties)
+            throws StandardException {
+
+        if (PropertyUtil.getSystemBoolean(Property.JMX))
+            initialize();
+    }
+
+    public synchronized void stop() {
+        if (mbeanServer == null)
+            return;
+        
+        for (ObjectName mbeanName : registeredMbeans)
+            try {
+                unregisterMBean(mbeanName);
+            } catch (StandardException e) {
+                // TODO: what to do here?
+            }
+    }
+
+    /**
+     * Initialize the management service by obtaining the platform
+     * MBeanServer and registering system beans. Separate from
+     * boot() to allow future changes where the jmx management
+     * can be enabled on the fly.
+     * 
+     * @throws StandardException
+     */
+    private synchronized void initialize() throws StandardException {
+        
+        registeredMbeans = new HashSet<ObjectName>();
+        try {
+            mbeanServer = AccessController
+                    .doPrivileged(new PrivilegedAction<MBeanServer>() {
+                        public MBeanServer run() {
+                            return ManagementFactory.getPlatformMBeanServer();
+                        }
+                    });
+
+            registerMBean(new Version(Monitor.getMonitor().getEngineVersion()),
+                    "org.apache.derby:type=Version,jar=derby.jar");
+            
+        } catch (SecurityException se) {
+            // TODO: just ignoring inability to create the mbean server.
+            // or should an error or warning be raised?
+        }
+    }
+
+    /**
+     * Registers an MBean with the MBean server. The object name instance 
+     * represented by the given String will be created by this method.
+     * 
+     * @param bean The MBean to register
+     * @param name The String representation of the MBean's object name.
+     * 
+     */
+    private synchronized void registerMBean(final Object bean, final String name)
+            throws StandardException {
+
+        if (mbeanServer == null)
+            return;
+
+        try {
+            final ObjectName beanName = new ObjectName(name);
+            try {
+
+                AccessController
+                        .doPrivileged(new PrivilegedExceptionAction<Object>() {
+
+                            public Object run() throws JMException {
+                                mbeanServer.registerMBean(bean, beanName);
+                                return null;
+                            }
+
+                        });
+                
+                registeredMbeans.add(beanName);
+
+            } catch (PrivilegedActionException pae) {
+                throw (JMException) pae.getException();
+            }
+        } catch (JMException jme) {
+            throw StandardException.plainWrapException(jme);
+        }
+    }
+    
+    /**
+     * 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;
+
+        if (!mbeanServer.isRegistered(mbeanName))
+            return;
+
+        try {
+
+            AccessController
+                    .doPrivileged(new PrivilegedExceptionAction<Object>() {
+
+                        public Object run() throws JMException {
+                            mbeanServer.unregisterMBean(mbeanName);
+                            return null;
+                        }
+
+                    });
+
+        } catch (PrivilegedActionException pae) {
+            throw StandardException.plainWrapException(pae.getException());
+        }
+    }
+}

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmx/JMXManagementService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: 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=627062&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
(added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
Tue Feb 12 11:50:42 2008
@@ -0,0 +1,29 @@
+/*
+    Derby Classname org.apache.derby.impl.services.jmxnone.NoManagementService
+  
+   Licensed 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.impl.services.jmxnone;
+
+import org.apache.derby.iapi.services.jmx.ManagementService;
+
+/** 
+ * Dummy management service for environments that do not support
+ * JMX, such as JDK 1.4 and J2ME.
+*/
+public class NoManagementService implements ManagementService {
+    public NoManagementService() {
+    }
+}
\ No newline at end of file

Propchange: db/derby/code/trunk/java/engine/org/apache/derby/impl/services/jmxnone/NoManagementService.java
------------------------------------------------------------------------------
    svn:eol-style = native

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=627062&r1=627061&r2=627062&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
Tue Feb 12 11:50:42 2008
@@ -62,6 +62,7 @@
 import org.apache.derby.iapi.services.info.JVMInfo;
 import org.apache.derby.iapi.services.i18n.BundleFinder;
 import org.apache.derby.iapi.services.i18n.MessageService;
+import org.apache.derby.iapi.services.jmx.ManagementService;
 
 import org.apache.derby.impl.services.monitor.StorageFactoryService;
 
@@ -372,6 +373,9 @@
 			uuidFactory = (UUIDFactory) Monitor.startSystemModule("org.apache.derby.iapi.services.uuid.UUIDFactory");
 
             timerFactory = (TimerFactory)Monitor.startSystemModule("org.apache.derby.iapi.services.timer.TimerFactory");
+            
+            Monitor.startSystemModule(ManagementService.MODULE);
+
 		} catch (StandardException se) {
 
 			// if we can't create an error log or a context then there's no point going on
@@ -391,6 +395,8 @@
 			dumpProperties("-- System Properties --", systemProperties);
 			dumpProperties("-- Application Properties --", applicationProperties);
 		}
+        
+        
 
 		// bootup all the service providers
 		determineSupportedServiceProviders();

Added: db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Version.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Version.java?rev=627062&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Version.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/Version.java Tue Feb 12 11:50:42
2008
@@ -0,0 +1,83 @@
+/*
+
+   Derby - Class org.apache.derby.mbeans.Version
+
+   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.services.info.ProductVersionHolder;
+
+/**
+ * This implementation of VersionMBean instruments a
+ * ProductVersionHolder object. The MBean interface is implemented with 
+ * callbacks to the wrapped object which gives detailed version information.
+ *
+ * @see org.apache.derby.iapi.services.info.ProductVersionHolder
+ */
+public class Version implements VersionMBean {
+    
+    private final ProductVersionHolder engineVersionRef;
+    
+    public Version(ProductVersionHolder pvh) {
+        engineVersionRef = pvh;
+    }
+    
+    // ------------------------- MBEAN ATTRIBUTES  ----------------------------
+    
+    public String getProductName(){
+        return engineVersionRef.getProductName();
+    }
+    
+     public String getProductTechnologyName(){
+        return engineVersionRef.getProductTechnologyName();
+    }
+    
+    public String getProductVendorName(){
+        return engineVersionRef.getProductVendorName();
+    }
+    
+    public int getMajorVersion(){
+        return engineVersionRef.getMajorVersion();
+    }
+    
+    public int getMinorVersion(){
+        return engineVersionRef.getMinorVersion();
+    }
+    
+    public int getMaintVersion(){
+        return engineVersionRef.getMaintVersion();
+    }
+    
+    public String getBuildNumber(){
+        return engineVersionRef.getBuildNumber();
+    }
+    
+    public int getBuildNumberAsInt(){
+        return engineVersionRef.getBuildNumberAsInt();
+    }
+    
+    public boolean getIsBeta(){
+        return engineVersionRef.isBeta();
+    }
+    
+    public boolean isAlpha(){
+        return engineVersionRef.isAlpha();
+    }
+  
+}

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

Added: 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=627062&view=auto
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java (added)
+++ db/derby/code/trunk/java/engine/org/apache/derby/mbeans/VersionMBean.java Tue Feb 12 11:50:42
2008
@@ -0,0 +1,50 @@
+/*
+
+   Derby - Class org.apache.derby.mbeans.VersionMBean
+
+   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;
+
+/** 
+* This interface defines a Standard MBean for exposing the version information
+* of the running Derby engine.
+* 
+* Refer to the getters of the interface for defined attributes. All attributes
+* are read-only.
+*
+* The MBean does not define any operations.
+*/
+public interface VersionMBean {
+    // attributes
+    
+    public String getProductName();
+    public String getProductTechnologyName();
+    public String getProductVendorName();
+    
+    public int getMajorVersion();
+    public int getMinorVersion();
+    public int getMaintVersion();
+    
+    public String getBuildNumber();
+    public int getBuildNumberAsInt();
+    
+    public boolean getIsBeta();
+    public boolean isAlpha();
+    
+}

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

Modified: db/derby/code/trunk/java/engine/org/apache/derby/modules.properties
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/modules.properties?rev=627062&r1=627061&r2=627062&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/modules.properties (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/modules.properties Tue Feb 12 11:50:42
2008
@@ -336,6 +336,14 @@
 derby.env.classes.dvfJ2=java.math.BigDecimal,java.sql.Driver
 cloudscape.config.dvfJ2=derby
 
+derby.module.mgmt.jmx=org.apache.derby.impl.services.jmx.JMXManagementService
+derby.env.mgmt.jmx=6
+cloudscape.config.mgmt.jmx=derby
+
+derby.module.mgmt.null=org.apache.derby.impl.services.jmxnone.NoManagementService
+derby.env.mgmt.jmx=2
+cloudscape.config.mgmt.null=derby
+
 # J2ME optional elements, the J2ME_optional_ lead in
 # is removed if the optional target is built.
 



Mime
View raw message