You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by gr...@apache.org on 2010/10/25 03:14:26 UTC
svn commit: r1026929 - in
/qpid/trunk/qpid/java/broker-plugins/experimental/shutdown: ./ src/
src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/
src/main/java/org/apache/qpid/ src/main/java/org/apache/qpid/shutdown/
Author: grkvlt
Date: Mon Oct 25 01:14:25 2010
New Revision: 1026929
URL: http://svn.apache.org/viewvc?rev=1026929&view=rev
Log:
QPID-2768: OSGI Shutdown module
Patch from Sorin S <ss...@gmail.com>
Added:
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF (with props)
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/build.xml (with props)
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java (with props)
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java (with props)
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java (with props)
qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/shutdown.bnd (with props)
Added: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF?rev=1026929&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF Mon Oct 25 01:14:25 2010
@@ -0,0 +1,15 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Experimental Shutdown
+Bundle-Description: Experimental Qpid Broker Shutdown Plugin
+Bundle-License: http://www.apache.org/licenses/LICENSE-2.0.txt
+Bundle-DocURL: http://qpid.apache.org/
+Bundle-SymbolicName: broker-plugins-experimental-shutdown;singleton:=true
+Bundle-Version: 1.0.0
+Bundle-Activator: org.apache.qpid.shutdown.Activator
+Import-Package: javax.management;resolution:=optional,
+ org.apache.log4j,
+ org.osgi.framework
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
+Bundle-ActivationPolicy: lazy
+
Propchange: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/MANIFEST.MF
------------------------------------------------------------------------------
svn:keywords = Id
Added: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/build.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/build.xml?rev=1026929&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/build.xml (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/build.xml Mon Oct 25 01:14:25 2010
@@ -0,0 +1,32 @@
+<!--
+ -
+ - 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.
+ -
+ -->
+<project name="AMQ Broker Shutdown Plugin" default="build">
+
+ <property name="module.depends" value="common broker 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"/>
+
+ <import file="../../../module.xml"/>
+
+ <target name="bundle" depends="bundle-tasks"/>
+
+</project>
Propchange: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/build.xml
------------------------------------------------------------------------------
svn:keywords = Id
Added: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java?rev=1026929&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java Mon Oct 25 01:14:25 2010
@@ -0,0 +1,63 @@
+/*
+ * 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.qpid.shutdown;
+
+import java.lang.management.ManagementFactory;
+
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+
+import org.apache.log4j.Logger;
+import org.osgi.framework.BundleActivator;
+import org.osgi.framework.BundleContext;
+
+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";
+
+ /** @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) */
+ public void start(BundleContext ctx) throws Exception {
+ Shutdown shutdown = new Shutdown();
+ if (ctx != 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);
+
+ _logger.info("Shutdown plugin MBean registered");
+ }
+
+ /** @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);
+ mbs.unregisterMBean(name);
+
+ _logger.info("Shutdown plugin MBean unregistered");
+ }
+}
Propchange: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Activator.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java?rev=1026929&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java Mon Oct 25 01:14:25 2010
@@ -0,0 +1,104 @@
+/*
+ * 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.qpid.shutdown;
+
+import java.text.DateFormat;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.ScheduledThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.log4j.Logger;
+
+/**
+ * Implementation of the JMX broker shutdown plugin.
+ */
+public class Shutdown 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 int THREAD_COUNT = 1;
+ private static final ScheduledExecutorService EXECUTOR = new ScheduledThreadPoolExecutor(THREAD_COUNT);
+
+ private final Runnable _shutdown = new SystemExiter();
+
+ /** @see ShutdownMBean#shutdown() */
+ public void shutdown()
+ {
+ _logger.info("Shutting down at user's request");
+ shutdownBroker(0);
+ }
+
+ /** @see ShutdownMBean#shutdown(long) */
+ public void shutdown(long delay)
+ {
+ _logger.info("Scheduled broker shutdown after " + delay + "ms");
+ shutdownBroker(delay);
+ }
+
+ /** @see ShutdownMBean#shutdownAt(String) */
+ public void shutdownAt(String when)
+ {
+ Date date;
+ DateFormat df = new SimpleDateFormat(FORMAT);
+ try
+ {
+ date = df.parse(when);
+ }
+ catch (ParseException e)
+ {
+ _logger.error("Invalid date \"" + when + "\": expecting " + FORMAT, e);
+ return;
+ }
+ _logger.info("Scheduled broker shutdown at " + when);
+ long now = System.currentTimeMillis();
+ long time = date.getTime();
+ if (time > now)
+ {
+ shutdownBroker(time - now);
+ }
+ else
+ {
+ shutdownBroker(0);
+ }
+ }
+
+ /**
+ * Submits the {@link SystemExiter} job to shutdown the broker.
+ */
+ private void shutdownBroker(long delay)
+ {
+ EXECUTOR.schedule(_shutdown, delay, TimeUnit.MILLISECONDS);
+ }
+
+ /**
+ * Shutting down the system in another thread to avoid JMX exceptions being thrown.
+ */
+ class SystemExiter implements Runnable
+ {
+ public void run()
+ {
+ System.exit(0);
+ }
+ }
+}
Propchange: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/Shutdown.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java?rev=1026929&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java Mon Oct 25 01:14:25 2010
@@ -0,0 +1,47 @@
+/*
+ * 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.qpid.shutdown;
+
+/**
+ * Shutdown plugin JMX MBean interface.
+ *
+ * Shuts the Qpid broker down via JMX.
+ */
+public interface ShutdownMBean
+{
+ /**
+ * Broker will be shut down immediately.
+ */
+ public void shutdown();
+
+ /**
+ * Broker will be shutdown after the specified delay
+ *
+ * @param delay the number of ms to wait
+ */
+ public void shutdown(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);
+}
Propchange: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/org/apache/qpid/shutdown/ShutdownMBean.java
------------------------------------------------------------------------------
svn:keywords = Id
Added: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/shutdown.bnd
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/shutdown.bnd?rev=1026929&view=auto
==============================================================================
--- qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/shutdown.bnd (added)
+++ qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/shutdown.bnd Mon Oct 25 01:14:25 2010
@@ -0,0 +1,25 @@
+#
+# 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.
+#
+
+ver: 0.7.0
+
+Bundle-SymbolicName: qpid-shutdown-plugin
+Bundle-Version: ${ver}
+Export-Package: *;version=${ver}
+Bundle-RequiredExecutionEnvironment: J2SE-1.5
Propchange: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/shutdown.bnd
------------------------------------------------------------------------------
svn:executable = *
Propchange: qpid/trunk/qpid/java/broker-plugins/experimental/shutdown/src/main/java/shutdown.bnd
------------------------------------------------------------------------------
svn:keywords = Id
---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project: http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org