summaryrefslogtreecommitdiff
path: root/qpid/java/broker-plugins
diff options
context:
space:
mode:
authorKeith Wall <kwall@apache.org>2011-12-16 12:51:56 +0000
committerKeith Wall <kwall@apache.org>2011-12-16 12:51:56 +0000
commit247798f6c222e09b026052ba97b2357c05b4e9d7 (patch)
tree5a98ad46a6cd8c6c9939e83d17dfb5bb5f460146 /qpid/java/broker-plugins
parent45066f17e52eb44dbb9c8f0250200d4ef974b54c (diff)
downloadqpid-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/broker-plugins')
-rw-r--r--qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF3
-rw-r--r--qpid/java/broker-plugins/experimental/shutdown/build.xml2
-rw-r--r--qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java28
-rw-r--r--qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java38
-rw-r--r--qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java12
5 files changed, 52 insertions, 31 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);
}