diff options
| author | Keith Wall <kwall@apache.org> | 2011-12-16 12:51:56 +0000 |
|---|---|---|
| committer | Keith Wall <kwall@apache.org> | 2011-12-16 12:51:56 +0000 |
| commit | 247798f6c222e09b026052ba97b2357c05b4e9d7 (patch) | |
| tree | 5a98ad46a6cd8c6c9939e83d17dfb5bb5f460146 /qpid/java | |
| parent | 45066f17e52eb44dbb9c8f0250200d4ef974b54c (diff) | |
| download | qpid-python-247798f6c222e09b026052ba97b2357c05b4e9d7.tar.gz | |
QPID-3682: Shutdown Plugin Improvements
Various improvements to shutdown plugin:
1) Give the ShutdownPlugin instance a name to allow it to be permission via ACL METHOD rules.
2) Refactored to extend DefaultManagedObject.
3) Added method/parameter annotations to improve usability from the UI.
4) Fix date format parsing pattern used by the plugin
Applied patch from Andrew MacBean <andymacbean@gmail.com> and myself.
git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk@1215112 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid/java')
8 files changed, 85 insertions, 65 deletions
diff --git a/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF b/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF index 49e90c6aad..0bd0a835e4 100644 --- a/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF +++ b/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF @@ -9,7 +9,8 @@ Bundle-Version: 1.0.0 Bundle-Activator: org.apache.qpid.shutdown.Activator Import-Package: javax.management;resolution:=optional, org.apache.log4j, - org.osgi.framework + org.osgi.framework, + org.apache.qpid.server.management Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy diff --git a/qpid/java/broker-plugins/experimental/shutdown/build.xml b/qpid/java/broker-plugins/experimental/shutdown/build.xml index ec4fce374e..cb4254806b 100644 --- a/qpid/java/broker-plugins/experimental/shutdown/build.xml +++ b/qpid/java/broker-plugins/experimental/shutdown/build.xml @@ -20,7 +20,7 @@ --> <project name="AMQ Broker Shutdown Plugin" default="build"> - <property name="module.depends" value="common broker broker-plugins"/> + <property name="module.depends" value="common broker management/common broker-plugins"/> <property name="module.test.depends" value="test broker/test management/common client systests"/> <property name="module.manifest" value="MANIFEST.MF"/> <property name="module.plugin" value="true"/> diff --git a/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java b/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java index ad5e7707b6..2b7fa33784 100644 --- a/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java +++ b/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java @@ -19,11 +19,6 @@ */ package org.apache.qpid.shutdown; -import java.lang.management.ManagementFactory; - -import javax.management.InstanceNotFoundException; -import javax.management.MBeanServer; -import javax.management.ObjectName; import org.apache.log4j.Logger; import org.osgi.framework.BundleActivator; @@ -33,20 +28,17 @@ public class Activator implements BundleActivator { private static final Logger _logger = Logger.getLogger(Activator.class); - private static final String SHUTDOWN_MBEAN_NAME = "org.apache.qpid:type=ShutdownMBean"; + private Shutdown _shutdown = null; /** @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */ public void start(BundleContext ctx) throws Exception { - Shutdown shutdown = new Shutdown(); + _shutdown = new Shutdown(); if (ctx != null) { - ctx.registerService(ShutdownMBean.class.getName(), shutdown, null); + ctx.registerService(ShutdownMBean.class.getName(), _shutdown, null); } - // MBean registration - MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - ObjectName name = new ObjectName(SHUTDOWN_MBEAN_NAME); - mbs.registerMBean(shutdown, name); + _shutdown.register(); _logger.info("Shutdown plugin MBean registered"); } @@ -54,16 +46,10 @@ public class Activator implements BundleActivator /** @see org.osgi.framework.BundleActivator#stop(org.osgi.framework.BundleContext) */ public void stop(BundleContext ctx) throws Exception { - // Unregister MBean - MBeanServer mbs = ManagementFactory.getPlatformMBeanServer(); - ObjectName name = new ObjectName(SHUTDOWN_MBEAN_NAME); - try - { - mbs.unregisterMBean(name); - } - catch (InstanceNotFoundException e) + if (_shutdown != null) { - //ignore + _shutdown.unregister(); + _shutdown = null; } _logger.info("Shutdown plugin MBean unregistered"); diff --git a/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java b/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java index 9a6f85fe9c..cef4a42b64 100644 --- a/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java +++ b/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java @@ -27,21 +27,30 @@ import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.TimeUnit; +import javax.management.NotCompliantMBeanException; + import org.apache.log4j.Logger; +import org.apache.qpid.server.management.DefaultManagedObject; /** * Implementation of the JMX broker shutdown plugin. */ -public class Shutdown implements ShutdownMBean +public class Shutdown extends DefaultManagedObject implements ShutdownMBean { + private static final Logger _logger = Logger.getLogger(Shutdown.class); - private static final String FORMAT = "yyyyy/MM/dd hh:mm:ss"; + private static final String FORMAT = "yyyy/MM/dd HH:mm:ss"; private static final int THREAD_COUNT = 1; private static final ScheduledExecutorService EXECUTOR = new ScheduledThreadPoolExecutor(THREAD_COUNT); private final Runnable _shutdown = new SystemExiter(); + public Shutdown() throws NotCompliantMBeanException + { + super(ShutdownMBean.class, ShutdownMBean.TYPE); + } + /** @see ShutdownMBean#shutdown() */ public void shutdown() { @@ -50,14 +59,22 @@ public class Shutdown implements ShutdownMBean } /** @see ShutdownMBean#shutdown(long) */ - public void shutdown(long delay) + public void shutdown(final long delay) { - _logger.info("Scheduled broker shutdown after " + delay + "ms"); - shutdownBroker(delay); + if (delay < 0) + { + _logger.info("Shutting down at user's request"); + shutdownBroker(0); + } + else + { + _logger.info("Scheduled broker shutdown after " + delay + "ms"); + shutdownBroker(delay); + } } /** @see ShutdownMBean#shutdownAt(String) */ - public void shutdownAt(String when) + public void shutdownAt(final String when) { Date date; DateFormat df = new SimpleDateFormat(FORMAT); @@ -101,4 +118,13 @@ public class Shutdown implements ShutdownMBean System.exit(0); } } + + /** + * @see org.apache.qpid.server.management.ManagedObject#getObjectInstanceName() + */ + @Override + public String getObjectInstanceName() + { + return "Shutdown"; + } } diff --git a/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java b/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java index 6294f869e9..48d2eab8df 100644 --- a/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java +++ b/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java @@ -19,6 +19,9 @@ */ package org.apache.qpid.shutdown; +import org.apache.qpid.management.common.mbeans.annotations.MBeanOperation; +import org.apache.qpid.management.common.mbeans.annotations.MBeanOperationParameter; + /** * Shutdown plugin JMX MBean interface. * @@ -26,9 +29,12 @@ package org.apache.qpid.shutdown; */ public interface ShutdownMBean { + static final String TYPE = "Shutdown"; + /** * Broker will be shut down immediately. */ + @MBeanOperation(name="shutdown", description="Shut down immediately") public void shutdown(); /** @@ -36,12 +42,14 @@ public interface ShutdownMBean * * @param delay the number of ms to wait */ - public void shutdown(long delay); + @MBeanOperation(name="shutdown", description="Shutdown after the specified delay (ms)") + public void shutdown(@MBeanOperationParameter(name="when", description="delay (ms)")long delay); /** * Broker will be shutdown at the specified date and time. * * @param when the date and time to shutdown */ - public void shutdownAt(String when); + @MBeanOperation(name="shutdownAt", description="Shutdown at the specified date and time (yyyy/MM/dd HH:mm:ss)") + public void shutdownAt(@MBeanOperationParameter(name="when", description="shutdown date/time (yyyy/MM/dd HH:mm:ss)")String when); } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java index c4ffcd26bf..6c9d6e39de 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/AMQManagedObject.java @@ -52,8 +52,6 @@ public abstract class AMQManagedObject extends DefaultManagedObject */ protected long _notificationSequenceNumber = 0; - protected MBeanInfo _mbeanInfo; - protected LogActor _logActor; protected AMQManagedObject(Class<?> managementInterface, String typeName) @@ -63,27 +61,8 @@ public abstract class AMQManagedObject extends DefaultManagedObject // CurrentActor will be defined as these objects are created during // broker startup. _logActor = new ManagementActor(CurrentActor.get().getRootMessageLogger()); - buildMBeanInfo(); - } - - @Override - public MBeanInfo getMBeanInfo() - { - return _mbeanInfo; - } - - private void buildMBeanInfo() throws NotCompliantMBeanException - { - _mbeanInfo = new MBeanInfo(this.getClass().getName(), - MBeanIntrospector.getMBeanDescription(this.getClass()), - MBeanIntrospector.getMBeanAttributesInfo(getManagementInterface()), - MBeanIntrospector.getMBeanConstructorsInfo(this.getClass()), - MBeanIntrospector.getMBeanOperationsInfo(getManagementInterface()), - this.getNotificationInfo()); } - - // notification broadcaster implementation public void addNotificationListener(NotificationListener listener, @@ -99,8 +78,5 @@ public abstract class AMQManagedObject extends DefaultManagedObject _broadcaster.removeNotificationListener(listener); } - public MBeanNotificationInfo[] getNotificationInfo() - { - return null; - } + } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java index e44b8c41cb..0c3a5fc571 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/management/DefaultManagedObject.java @@ -21,6 +21,8 @@ package org.apache.qpid.server.management; import javax.management.JMException; +import javax.management.MBeanInfo; +import javax.management.MBeanNotificationInfo; import javax.management.MalformedObjectNameException; import javax.management.NotCompliantMBeanException; import javax.management.ObjectName; @@ -28,7 +30,6 @@ import javax.management.StandardMBean; import org.apache.log4j.Logger; import org.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.registry.IApplicationRegistry; /** * Provides implementation of the boilerplate ManagedObject interface. Most managed objects should find it useful @@ -37,11 +38,13 @@ import org.apache.qpid.server.registry.IApplicationRegistry; */ public abstract class DefaultManagedObject extends StandardMBean implements ManagedObject { - private static final Logger LOGGER = Logger.getLogger(ApplicationRegistry.class); + private static final Logger LOGGER = Logger.getLogger(DefaultManagedObject.class); - private Class<?> _managementInterface; + private final Class<?> _managementInterface; - private String _typeName; + private final String _typeName; + + private final MBeanInfo _mbeanInfo; private ManagedObjectRegistry _registry; @@ -51,6 +54,13 @@ public abstract class DefaultManagedObject extends StandardMBean implements Mana super(managementInterface); _managementInterface = managementInterface; _typeName = typeName; + _mbeanInfo = buildMBeanInfo(); + } + + @Override + public MBeanInfo getMBeanInfo() + { + return _mbeanInfo; } public String getType() @@ -98,7 +108,6 @@ public abstract class DefaultManagedObject extends StandardMBean implements Mana return getObjectInstanceName() + "[" + getType() + "]"; } - /** * Created the ObjectName as per the JMX Specs * @return ObjectName @@ -161,4 +170,18 @@ public abstract class DefaultManagedObject extends StandardMBean implements Mana return ""; } + private MBeanInfo buildMBeanInfo() throws NotCompliantMBeanException + { + return new MBeanInfo(this.getClass().getName(), + MBeanIntrospector.getMBeanDescription(this.getClass()), + MBeanIntrospector.getMBeanAttributesInfo(getManagementInterface()), + MBeanIntrospector.getMBeanConstructorsInfo(this.getClass()), + MBeanIntrospector.getMBeanOperationsInfo(getManagementInterface()), + this.getNotificationInfo()); + } + + public MBeanNotificationInfo[] getNotificationInfo() + { + return null; + } } diff --git a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java index c07074f69c..7eb1b54693 100644 --- a/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java +++ b/qpid/java/broker/src/main/java/org/apache/qpid/server/registry/ApplicationRegistry.java @@ -250,14 +250,14 @@ public abstract class ApplicationRegistry implements IApplicationRegistry try { + initialiseManagedObjectRegistry(); + configure(); _qmfService = new QMFService(getConfigStore(), this); CurrentActor.get().message(BrokerMessages.STARTUP(QpidProperties.getReleaseVersion(), QpidProperties.getBuildVersion())); - initialiseManagedObjectRegistry(); - _virtualHostRegistry = new VirtualHostRegistry(this); _securityManager = new SecurityManager(_configuration, _pluginManager); @@ -471,12 +471,12 @@ public abstract class ApplicationRegistry implements IApplicationRegistry close(_authenticationManager); - close(_managedObjectRegistry); - close(_qmfService); close(_pluginManager); + close(_managedObjectRegistry); + CurrentActor.get().message(BrokerMessages.STOPPED()); } |
