[jboss-cvs] JBoss Messaging SVN: r5349 - in trunk: src/main/org/jboss/messaging/jms/server/management/impl and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 13 11:55:59 EST 2008


Author: jmesnil
Date: 2008-11-13 11:55:59 -0500 (Thu, 13 Nov 2008)
New Revision: 5349

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/management/TopicControlTest.java
Modified:
   trunk/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java
   trunk/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java
Log:
JBMESSAGING-1097: Ability to quickly drop queues / durable subscriptions

- added dropAllSubscriptions() and dropDurableSubscription(clientID, subscriptionName) to TopicControlMBean
- added integration tests in TopicControlTest

Modified: trunk/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java	2008-11-13 16:49:00 UTC (rev 5348)
+++ trunk/src/main/org/jboss/messaging/jms/server/management/TopicControlMBean.java	2008-11-13 16:55:59 UTC (rev 5349)
@@ -22,6 +22,8 @@
 
 package org.jboss.messaging.jms.server.management;
 
+import static javax.management.MBeanOperationInfo.ACTION;
+
 import javax.management.openmbean.TabularData;
 
 import org.jboss.messaging.core.management.Operation;
@@ -76,4 +78,13 @@
    @Operation(desc = "List only the non durable subscriptions")
    SubscriptionInfo[] listNonDurableSubscriptionInfos();
 
+   @Operation(desc = "Drop a durable subscription", impact = ACTION)
+   void dropDurableSubscription(
+         @Parameter(name = "clientID", desc = "the client ID") String clientID,
+         @Parameter(name = "subscriptionName", desc = "the name of the durable subscription") String subscriptionName)
+         throws Exception;
+   
+
+   @Operation(desc = "Drop all subscriptions from this topic", impact = ACTION)
+   void dropAllSubscriptions() throws Exception;
 }

Modified: trunk/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java	2008-11-13 16:49:00 UTC (rev 5348)
+++ trunk/src/main/org/jboss/messaging/jms/server/management/impl/TopicControl.java	2008-11-13 16:55:59 UTC (rev 5349)
@@ -218,7 +218,37 @@
          queue.deleteAllReferences(storageManager);
       }
    }
+   
+   public void dropDurableSubscription(String clientID, String subscriptionName) throws Exception
+   {
+      String queueName = JBossTopic.createQueueNameForDurableSubscription(clientID, subscriptionName);
+      Binding binding = postOffice.getBinding(new SimpleString(queueName));
 
+      if (binding == null)
+      {
+         throw new IllegalArgumentException("No durable subscription for clientID=" + clientID + ", subcription=" + subscriptionName);
+      }
+
+      Queue queue = binding.getQueue();
+
+      queue.deleteAllReferences(storageManager);
+
+      postOffice.removeBinding(queue.getName());
+   }
+
+   public void dropAllSubscriptions() throws Exception
+   {
+      List<Binding> bindings = postOffice.getBindingsForAddress(managedTopic
+                                                                .getSimpleAddress());
+
+      for (Binding binding : bindings)
+      {
+         Queue queue = binding.getQueue();
+         queue.deleteAllReferences(storageManager);
+         postOffice.removeBinding(queue.getName());
+      }
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------

Added: trunk/tests/src/org/jboss/messaging/tests/integration/management/TopicControlTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/management/TopicControlTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/management/TopicControlTest.java	2008-11-13 16:55:59 UTC (rev 5349)
@@ -0,0 +1,182 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005-2008, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.messaging.tests.integration.management;
+
+import static org.jboss.messaging.tests.util.RandomUtil.randomString;
+
+import java.lang.management.ManagementFactory;
+
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.management.MBeanServerInvocationHandler;
+
+import org.jboss.messaging.jms.server.management.TopicControlMBean;
+import org.jboss.messaging.jms.server.management.impl.JMSManagementServiceImpl;
+import org.jboss.test.messaging.jms.JMSTestCase;
+
+/**
+ * A TopicControlTest
+ *
+ * @author <a href="jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * Created 13 nov. 2008 16:50:53
+ *
+ *
+ */
+public class TopicControlTest extends JMSTestCase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   private String clientID;
+
+   private String subscriptionName;
+
+   // Static --------------------------------------------------------
+
+   private static void assertDurableSubscriptions(Topic topic, int expectedCount) throws Exception
+   {
+      TopicControlMBean topicControl = (TopicControlMBean)MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(),
+                                                                                                        JMSManagementServiceImpl.getJMSTopicObjectName(topic.getTopicName()),
+                                                                                                        TopicControlMBean.class,
+                                                                                                        false);
+     assertEquals(expectedCount, topicControl.getDurableSubcriptionsCount());
+   }
+   
+   // Constructors --------------------------------------------------
+
+   public TopicControlTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+
+   public void testDropDurableSubscriptionWithExistingSubscription() throws Exception
+   {
+      createDurableSubscriber(clientID, subscriptionName);
+
+      assertDurableSubscriptions(topic1, 1);
+      
+      TopicControlMBean topicControl = (TopicControlMBean)MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(),
+                                                                                                        JMSManagementServiceImpl.getJMSTopicObjectName(topic1.getTopicName()),
+                                                                                                        TopicControlMBean.class,
+                                                                                                        false);
+      topicControl.dropDurableSubscription(clientID, subscriptionName);
+      
+      assertDurableSubscriptions(topic1, 0);
+   }
+
+   public void testDropDurableSubscriptionWithUnknownSubscription() throws Exception
+   {
+      createDurableSubscriber(clientID, subscriptionName);
+
+      assertDurableSubscriptions(topic1, 1);
+
+      TopicControlMBean topicControl = (TopicControlMBean)MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(),
+                                                                                                        JMSManagementServiceImpl.getJMSTopicObjectName(topic1.getTopicName()),
+                                                                                                        TopicControlMBean.class,
+                                                                                                        false);
+      try
+      {
+         topicControl.dropDurableSubscription(clientID, "this subscription does not exist");
+         fail("should throw an exception");
+      }
+      catch (Exception e)
+      {
+
+      }
+
+      assertDurableSubscriptions(topic1, 1);
+   }
+
+   public void testDropAllSubscriptions() throws Exception
+   {
+      createDurableSubscriber(clientID, subscriptionName);
+      createDurableSubscriber(clientID, subscriptionName + "2");
+      
+      assertDurableSubscriptions(topic1, 2);
+
+      TopicControlMBean topicControl = (TopicControlMBean)MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(),
+                                                                                                        JMSManagementServiceImpl.getJMSTopicObjectName(topic1.getTopicName()),
+                                                                                                        TopicControlMBean.class,
+                                                                                                        false);
+      
+      topicControl.dropAllSubscriptions();
+
+      assertDurableSubscriptions(topic1, 0);
+   }
+   
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      clientID = randomString();
+      subscriptionName = randomString();
+   }
+   
+   @Override
+   protected void tearDown() throws Exception
+   {
+      destroyAllSubscriptions();
+      
+      super.tearDown();
+   }
+   
+   // Private -------------------------------------------------------
+
+   private void createDurableSubscriber(String clientID, String subscriptionName) throws JMSException
+   {
+      Connection conn = cf.createConnection();
+
+      conn.setClientID(clientID);
+      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      s.createDurableSubscriber(topic1, subscriptionName);
+
+   }
+   
+   private void destroyAllSubscriptions() throws Exception
+   {
+      // we leave the server in a clean state wrt to subscriptions
+      TopicControlMBean topicControl = (TopicControlMBean)MBeanServerInvocationHandler.newProxyInstance(ManagementFactory.getPlatformMBeanServer(),
+                                                                                                        JMSManagementServiceImpl.getJMSTopicObjectName(topic1.getTopicName()),
+                                                                                                        TopicControlMBean.class,
+                                                                                                        false);
+      
+      topicControl.dropAllSubscriptions();
+   }
+
+
+   // Inner classes -------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list