[jboss-cvs] JBoss Messaging SVN: r2637 - in branches/Branch_1_0_1_SP: src/main/org/jboss/jms/server/endpoint and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri May 4 05:34:46 EDT 2007


Author: timfox
Date: 2007-05-04 05:34:46 -0400 (Fri, 04 May 2007)
New Revision: 2637

Modified:
   branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ServerPeer.java
   branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
   branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
   branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
   branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DuplicateClientIDTest.java
   branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java
Log:
http://jira.jboss.com/jira/browse/JBMESSAGING-954


Modified: branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ServerPeer.java
===================================================================
--- branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ServerPeer.java	2007-05-03 21:28:44 UTC (rev 2636)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ServerPeer.java	2007-05-04 09:34:46 UTC (rev 2637)
@@ -703,31 +703,7 @@
       return queuedExecutorPool;
    }
    
-   public void checkClientID(String clientID) throws Exception
-   {   
-      // verify the clientID is unique
    
-      // JMS 1.1 Specifications, Section 4.3.2:
-      // "By definition, the client state identified by a client identifier can be 'in use' by
-      // only one client at a time. A JMS provider must prevent concurrently executing clients
-      // from using it."
-         
-      if (clientID != null)
-      {      
-         List conns = connectionManager.getActiveConnections();
-      
-         for(Iterator i = conns.iterator(); i.hasNext(); )
-         {
-            ServerConnectionEndpoint sce = (ServerConnectionEndpoint)i.next();
-            if (clientID != null && clientID.equals(sce.getClientID()))
-            {
-               throw new InvalidClientIDException(
-                  "Client ID '" + clientID + "' already used by " + sce);
-            }
-         }
-      }
-   }
-   
    public int getServerIDAsInt()
    {
       return serverIdAsInt;

Modified: branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
===================================================================
--- branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2007-05-03 21:28:44 UTC (rev 2636)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java	2007-05-04 09:34:46 UTC (rev 2637)
@@ -240,8 +240,6 @@
             throw new IllegalStateException("Cannot set clientID, already set as " + this.clientID);
          }
 
-         serverPeer.checkClientID(clientID);
-
          log.debug(this + "setting client ID to " + clientID);
 
          this.clientID = clientID;

Modified: branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java
===================================================================
--- branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java	2007-05-03 21:28:44 UTC (rev 2636)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionFactoryEndpoint.java	2007-05-04 09:34:46 UTC (rev 2637)
@@ -128,11 +128,6 @@
             }
          }
 
-         if (clientIDUsed != null)
-         {
-            serverPeer.checkClientID(clientIDUsed);
-         }
-
          // create the corresponding "server-side" connection endpoint and register it with the
          // server peer's ClientManager
          ServerConnectionEndpoint endpoint =

Modified: branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java
===================================================================
--- branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2007-05-03 21:28:44 UTC (rev 2636)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerSessionEndpoint.java	2007-05-04 09:34:46 UTC (rev 2637)
@@ -208,6 +208,13 @@
                else
                {
                   if (trace) { log.trace("subscription " + subscriptionName + " already exists"); }
+                  
+                  //Can't create subscriber if there is already an active subscriber
+                  if (subscription.iterator().hasNext())
+                  {
+                  	throw new IllegalStateException("Cannot create a subscriber on the durable subscription since it already has subscriber(s)");
+
+                  }
    
                   // From javax.jms.Session Javadoc (and also JMS 1.1 6.11.1):
                   // A client can change an existing durable subscription by creating a durable

Modified: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DuplicateClientIDTest.java
===================================================================
--- branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DuplicateClientIDTest.java	2007-05-03 21:28:44 UTC (rev 2636)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DuplicateClientIDTest.java	2007-05-04 09:34:46 UTC (rev 2637)
@@ -22,174 +22,205 @@
 
 package org.jboss.test.messaging.jms;
 
-import org.jboss.test.messaging.MessagingTestCase;
-import org.jboss.test.messaging.tools.ServerManagement;
-import javax.naming.InitialContext;
+import javax.jms.Connection;
 import javax.jms.ConnectionFactory;
-import javax.jms.Connection;
 import javax.jms.InvalidClientIDException;
+import javax.naming.InitialContext;
 
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+
+
 /**
- * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
- * @version <tt>$Revision$</tt>
- * $Id$
- */
+* @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+* @version <tt>$Revision$</tt>
+* $Id$
+*/
 public class DuplicateClientIDTest extends MessagingTestCase
 {
 
-   // Constants ------------------------------------------------------------------------------------
+ // Constants ------------------------------------------------------------------------------------
 
-   // Attributes -----------------------------------------------------------------------------------
+ // Attributes -----------------------------------------------------------------------------------
 
-   protected InitialContext ic;
-   protected ConnectionFactory cf;
+ protected InitialContext ic;
+ protected ConnectionFactory cf;
 
-   // Static ---------------------------------------------------------------------------------------
+ // Static ---------------------------------------------------------------------------------------
 
-   // Constructors ---------------------------------------------------------------------------------
+ // Constructors ---------------------------------------------------------------------------------
 
-   public DuplicateClientIDTest(String name)
-   {
-      super(name);
-   }
+ public DuplicateClientIDTest(String name)
+ {
+    super(name);
+ }
 
-   // Public ---------------------------------------------------------------------------------------
+ // Public ---------------------------------------------------------------------------------------
 
-   public void testDuplicate() throws Exception
-   {
+ public void testDuplicate() throws Exception
+ {
 
-      Connection c1 = null;
-      Connection c2 = null;
-      try
-      {
+    Connection c1 = null;
+    Connection c2 = null;
+    try
+    {
 
-         c1 = cf.createConnection();
-         c1.setClientID("Duplicated");
+       c1 = cf.createConnection();
+       c1.setClientID("Duplicated");
 
-         try
-         {
-            c2 = cf.createConnection();
-            c2.setClientID("Duplicated");
-            fail("JBossMessaging is allowing duplicate clients!");
-         }
-         catch (InvalidClientIDException e)
-         {
-         }
-      }
-      finally
-      {
-         if (c1 != null) c1.close();
-         if (c2 != null) c2.close();
-      }
+       try
+       {
+          c2 = cf.createConnection();
+          c2.setClientID("Duplicated");
+       }
+       catch (InvalidClientIDException e)
+       {
+          // From JMS Spec session 4.3.2 you could have multiple connections with the same
+          // ID... as long as you check for multiple ClientIDs and don't duplicate messages 
+          fail("You could have multiple connections with the same clientID, " +
+             "as long they are not being in use!");
+       }
+    }
+    finally
+    {
+       if (c1 != null) c1.close();
+       if (c2 != null) c2.close();
+    }
 
-   }
+    // This clause was added for http://jira.jboss.org/jira/browse/JBMESSAGING-932
+    // If opening a new connection after closing the previous one... this should work
+    try
+    {
+       c1 = cf.createConnection();
+       c1.setClientID("Duplicated");
+    }
+    finally
+    {
+       if (c1 != null) c1.close();
+    }
 
-   public void testPreconfiguredDuplicateClientID() throws Exception
-   {
-      Connection c1 = null;
-      Connection c2 = null;
-      try
-      {
+ }
 
-         c1 = cf.createConnection("john", "needle");
-         c1.setClientID("Duplicated");
+ //http://jira.jboss.com/jira/browse/JBMESSAGING-816
+ public void testPreconfiguredDuplicateClientID() throws Exception
+ {
+    Connection c1 = null;
+    Connection c2 = null;
 
-         try
-         {
-            c2 = cf.createConnection("john", "needle");
-            c2.setClientID("Duplicated");
-            fail("JBossMessaging is allowing duplicate clients!");
-         }
-         catch (InvalidClientIDException e)
-         {
-         }
-      }
-      finally
-      {
-         if (c1 != null) c1.close();
-         if (c2 != null) c2.close();
-      }
-   }
+    try
+    {
 
-   public void testNotDuplicateClientID() throws Exception
-   {
-      Connection c1 = null;
-      Connection c2 = null;
-      try
-      {
+       c1 = cf.createConnection("dilbert", "dogbert");
+       assertNotNull(c1);
+       assertNotNull(c1.getClientID());
 
-         c1 = cf.createConnection();
+       try
+       {
+          c2 = cf.createConnection("dilbert", "dogbert");
+          assertNotNull(c2);
+          assertNotNull(c2.getClientID());
 
-         c2 = cf.createConnection();
-      }
-      finally
-      {
-         if (c1 != null) c1.close();
-         if (c2 != null) c2.close();
-      }
-   }
-   
-   public void testNotDuplicateClientID2() throws Exception
-   {
-      // Validates if there is anything dirty on the session that could damage a regular connection
-      Connection c0 = null;
-      Connection c1 = null;
-      Connection c2 = null;
-      try
-      {
-         c0 = cf.createConnection("dilbert", "dogbert");
-         
-         assertEquals("dilbert-id", c0.getClientID());
-         
-         c1 = cf.createConnection();
-         
-         assertNull(c1.getClientID());
-         
-         c2 = cf.createConnection();
-         
-         assertNull(c2.getClientID());
-      }
-      finally
-      {
-         if (c0 != null)
-         {
-            c0.close();
-         }
-         if (c1 != null)
-         {
-            c1.close();
-         }
-         if (c2 != null)
-         {
-            c2.close();
-         }
-      }
-   }
+       }
+       catch (InvalidClientIDException e)
+       {
+          // From JMS Spec session 4.3.2 you could have multiple connections with the same
+          // ID... as long as you check for multiple ClientIDs and don't duplicate messages
+          fail("You could have multiple connections with the same clientID, " +
+             "as long they are not being in use!");
+       }
+    }
+    finally
+    {
+       if (c1 != null)
+       {
+          c1.close();
+       }
+       if (c2 != null)
+       {
+          c2.close();
+       }
+    }
 
-   // Package protected ----------------------------------------------------------------------------
+    // This clause was added for http://jira.jboss.org/jira/browse/JBMESSAGING-932
+    // If opening a new connection after closing the previous one... this should work
+    try
+    {
+       c1 = cf.createConnection("dilbert", "dogbert");
+       assertNotNull(c1);
+       assertNotNull(c1.getClientID());
+    }
+    finally
+    {
+       if (c1 != null)
+       {
+          c1.close();
+       }
+    }
 
-   // Protected ------------------------------------------------------------------------------------
 
-   protected void setUp() throws Exception
-   {
-      super.setUp();
+ }
 
-      ServerManagement.start("all");
+ public void testNotDuplicateClientID() throws Exception
+ {
+    // Validates if there is anything dirty on the session that could damage a regular connection
+    Connection c0 = null;
+    Connection c1 = null;
+    Connection c2 = null;
+    try
+    {
+       c0 = cf.createConnection("dilbert", "dogbert");
+       
+       assertEquals("dilbert-id", c0.getClientID());
+       
+       c1 = cf.createConnection();
+       
+       assertNull(c1.getClientID());
+       
+       c2 = cf.createConnection();
+       
+       assertNull(c2.getClientID());
+    }
+    finally
+    {
+       if (c0 != null)
+       {
+          c0.close();
+       }
+       if (c1 != null)
+       {
+          c1.close();
+       }
+       if (c2 != null)
+       {
+          c2.close();
+       }
+    }
+ }
 
-      ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+ // Package protected ----------------------------------------------------------------------------
 
-      cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+ // Protected ------------------------------------------------------------------------------------
 
+ protected void setUp() throws Exception
+ {
+    super.setUp();
 
-   }
+    ServerManagement.start("all");
 
-   protected void tearDown() throws Exception
-   {
-      super.tearDown();
-   }
+    ic = new InitialContext(ServerManagement.getJNDIEnvironment());
 
-   // Private --------------------------------------------------------------------------------------
+    cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
 
-   // Inner classes --------------------------------------------------------------------------------
 
+ }
+
+ protected void tearDown() throws Exception
+ {
+    super.tearDown();
+ }
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+
 }

Modified: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java
===================================================================
--- branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java	2007-05-03 21:28:44 UTC (rev 2636)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DurableSubscriberTest.java	2007-05-04 09:34:46 UTC (rev 2637)
@@ -510,7 +510,36 @@
 
       conn.close();
    }
+   
+   public void testSubscribeWithActiveSubscription() throws Exception
+   {
+   	ConnectionFactory cf = (ConnectionFactory)ic.lookup("ConnectionFactory");
+      Topic topic = (Topic)ic.lookup("/topic/Topic");
 
+      Connection conn = cf.createConnection();
+      conn.setClientID("zeke");
+
+      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+      TopicSubscriber dursub1 = s.createDurableSubscriber(topic, "dursub1");
+
+      try
+      {      
+      	s.createDurableSubscriber(topic, "dursub1");
+         fail();
+      }
+      catch (IllegalStateException e)
+      {
+         //Ok - it is illegal to have more than one active subscriber on a subscrtiption at any one time
+      }
+         
+      dursub1.close();
+      
+      s.unsubscribe("dursub1");
+
+      conn.close();
+   }
+
    // Package protected ---------------------------------------------
 
    // Protected -----------------------------------------------------




More information about the jboss-cvs-commits mailing list