[jboss-cvs] JBoss Messaging SVN: r2136 - in branches/Branch_1_0_1_SP: src/main/org/jboss/jms/server/connectionmanager and 2 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Feb 2 01:43:28 EST 2007
Author: ovidiu.feodorov at jboss.com
Date: 2007-02-02 01:43:28 -0500 (Fri, 02 Feb 2007)
New Revision: 2136
Added:
branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DuplicateClientIDTest.java
Modified:
branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ConnectionManager.java
branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java
Log:
http://jira.jboss.org/jira/browse/JBMESSAGING-791
Modified: branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ConnectionManager.java
===================================================================
--- branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ConnectionManager.java 2007-02-02 06:40:57 UTC (rev 2135)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/ConnectionManager.java 2007-02-02 06:43:28 UTC (rev 2136)
@@ -23,7 +23,9 @@
import org.jboss.jms.server.endpoint.ConnectionEndpoint;
+import java.util.List;
+
/**
* @author <a href="mailto:ovidiu at jboss.org">Ovidiu Feodorov</a>
* @author <a href="mailto:tim.fox at jboss.com">Tim Fox</a>
@@ -39,8 +41,18 @@
* @return null if there is no such connection.
*/
ConnectionEndpoint unregisterConnection(String jmsClientVMId, String remotingClientSessionID);
-
+
void handleClientFailure(String remotingSessionID);
-
+
boolean containsSession(String remotingClientSessionID);
+
+ /**
+ * Returns a list of active connection endpoints currently maintained by an instance of this
+ * manager. The implementation should make a copy of the list to avoid
+ * ConcurrentModificationException. The list could be empty, but never null.
+ *
+ * @return List<ConnectionEndpoint>
+ */
+ List getActiveConnections();
+
}
Modified: branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java
===================================================================
--- branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java 2007-02-02 06:40:57 UTC (rev 2135)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/connectionmanager/SimpleConnectionManager.java 2007-02-02 06:43:28 UTC (rev 2136)
@@ -27,6 +27,8 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
+import java.util.HashSet;
import javax.jms.JMSException;
@@ -55,17 +57,22 @@
// Attributes ----------------------------------------------------
+ // Map<jmsClientVMID<String> - Map<remotingClientSessionID<String> - ConnectionEndpoint>>
protected Map jmsClients;
-
+
+ // Map<remotingClientSessionID<String> - jmsClientVMID<String>
protected Map sessions;
-
+
+ // Set<ConnectionEndpoint>
+ protected Set activeConnectionEndpoints;
+
// Constructors --------------------------------------------------
public SimpleConnectionManager()
{
jmsClients = new HashMap();
-
sessions = new HashMap();
+ activeConnectionEndpoints = new HashSet();
}
// ConnectionManager ---------------------------------------------
@@ -83,6 +90,8 @@
endpoints.put(remotingClientSessionID, endpoint);
sessions.put(remotingClientSessionID, jmsClientVMId);
+
+ activeConnectionEndpoints.add(endpoint);
log.debug("registered connection " + endpoint + " as " +
Util.guidToString(remotingClientSessionID));
@@ -95,7 +104,13 @@
if (endpoints != null)
{
ConnectionEndpoint e = (ConnectionEndpoint)endpoints.remove(remotingClientSessionID);
-
+
+ if (e != null)
+ {
+ endpoints.remove(e);
+ activeConnectionEndpoints.remove(e);
+ }
+
log.debug("unregistered connection " + e + " with remoting session ID " +
Util.guidToString(remotingClientSessionID));
@@ -166,7 +181,15 @@
}
}
}
-
+
+ public synchronized List getActiveConnections()
+ {
+ // I will make a copy to avoid ConcurrentModification
+ ArrayList list = new ArrayList();
+ list.addAll(activeConnectionEndpoints);
+ return list;
+ }
+
/*
* Used in testing only
*/
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-02-02 06:40:57 UTC (rev 2135)
+++ branches/Branch_1_0_1_SP/src/main/org/jboss/jms/server/endpoint/ServerConnectionEndpoint.java 2007-02-02 06:43:28 UTC (rev 2136)
@@ -30,6 +30,7 @@
import javax.jms.Destination;
import javax.jms.IllegalStateException;
import javax.jms.JMSException;
+import javax.jms.InvalidClientIDException;
import javax.transaction.xa.Xid;
import org.jboss.jms.client.delegate.ClientSessionDelegate;
@@ -225,19 +226,42 @@
{
throw new IllegalStateException("Connection is closed");
}
- if (trace) { log.trace("setClientID:" + clientID); }
+
if (this.clientID != null)
{
- throw new IllegalStateException("Cannot set clientID, already set as:" + this.clientID);
+ throw new IllegalStateException("Cannot set clientID, already set as " + this.clientID);
}
+
+ // 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."
+
+ ConnectionManager cm = serverPeer.getConnectionManager();
+ List conns = cm.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);
+ }
+ }
+
+ log.debug(this + "setting client ID to " + clientID);
+
this.clientID = clientID;
}
catch (Throwable t)
{
throw ExceptionUtil.handleJMSInvocation(t, this + " setClientID");
- }
+ }
}
-
+
public void start() throws JMSException
{
try
Added: 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 (rev 0)
+++ branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DuplicateClientIDTest.java 2007-02-02 06:43:28 UTC (rev 2136)
@@ -0,0 +1,158 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * 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.test.messaging.jms;
+
+import org.jboss.test.messaging.MessagingTestCase;
+import org.jboss.test.messaging.tools.ServerManagement;
+import javax.naming.InitialContext;
+import javax.jms.ConnectionFactory;
+import javax.jms.Connection;
+import javax.jms.InvalidClientIDException;
+
+/**
+ * @author <a href="mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ * @version <tt>$Revision$</tt>
+ * $Id$
+ */
+public class DuplicateClientIDTest extends MessagingTestCase
+{
+
+ // Constants ------------------------------------------------------------------------------------
+
+ // Attributes -----------------------------------------------------------------------------------
+
+ protected InitialContext ic;
+ protected ConnectionFactory cf;
+
+ // Static ---------------------------------------------------------------------------------------
+
+ // Constructors ---------------------------------------------------------------------------------
+
+ public DuplicateClientIDTest(String name)
+ {
+ super(name);
+ }
+
+ // Public ---------------------------------------------------------------------------------------
+
+ public void testDuplicate() throws Exception
+ {
+
+ Connection c1 = null;
+ Connection c2 = null;
+ try
+ {
+
+ 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();
+ }
+
+ }
+
+ public void testPreconfiguredDuplicateClientID() throws Exception
+ {
+ Connection c1 = null;
+ Connection c2 = null;
+ try
+ {
+
+ c1 = cf.createConnection("john", "needle");
+ c1.setClientID("Duplicated");
+
+ 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();
+ }
+ }
+
+ public void testNotDuplicateClientID() throws Exception
+ {
+ Connection c1 = null;
+ Connection c2 = null;
+ try
+ {
+
+ c1 = cf.createConnection();
+
+ c2 = cf.createConnection();
+ }
+ finally
+ {
+ if (c1 != null) c1.close();
+ if (c2 != null) c2.close();
+ }
+ }
+
+ // Package protected ----------------------------------------------------------------------------
+
+ // Protected ------------------------------------------------------------------------------------
+
+ protected void setUp() throws Exception
+ {
+ super.setUp();
+
+ ServerManagement.start("all");
+
+ ic = new InitialContext(ServerManagement.getJNDIEnvironment());
+
+ cf = (ConnectionFactory)ic.lookup("/ConnectionFactory");
+
+
+ }
+
+ protected void tearDown() throws Exception
+ {
+ super.tearDown();
+ }
+
+ // Private --------------------------------------------------------------------------------------
+
+ // Inner classes --------------------------------------------------------------------------------
+
+}
Property changes on: branches/Branch_1_0_1_SP/tests/src/org/jboss/test/messaging/jms/DuplicateClientIDTest.java
___________________________________________________________________
Name: svn:keywords
+ Id LastChangedDate Author Revision
More information about the jboss-cvs-commits
mailing list