From e08cc350e0dba5fa9c781869c93f183695dca10a Mon Sep 17 00:00:00 2001 From: David Jencks Date: Tue, 30 Dec 2008 20:05:16 +0000 Subject: [PATCH] AMQ-2049 Fix race condition on ConnectionInfo by copying. Minor javaodc cleanup git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@730226 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/activemq/ActiveMQConnection.java | 7 ++++--- .../org/apache/activemq/command/ConnectionInfo.java | 13 +++++++++++-- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java index 3e50a08665..54ae21966c 100755 --- a/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java +++ b/activemq-core/src/main/java/org/apache/activemq/ActiveMQConnection.java @@ -51,6 +51,7 @@ import javax.jms.Topic; import javax.jms.TopicConnection; import javax.jms.TopicSession; import javax.jms.XAConnection; +import javax.jms.InvalidDestinationException; import org.apache.activemq.blob.BlobTransferPolicy; import org.apache.activemq.command.ActiveMQDestination; @@ -1332,11 +1333,11 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon if (isConnectionInfoSentToBroker || closed.get()) { return; } - + //TODO shouldn't this check be on userSpecifiedClientID rather than the value of clientID? if (info.getClientId() == null || info.getClientId().trim().length() == 0) { info.setClientId(clientIdGenerator.generateId()); } - syncSendPacket(info); + syncSendPacket(info.copy()); this.isConnectionInfoSentToBroker = true; // Add a temp destination advisory consumer so that @@ -2043,7 +2044,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon * specified. * @since 1.1 */ - public void unsubscribe(String name) throws JMSException { + public void unsubscribe(String name) throws InvalidDestinationException, JMSException { checkClosedOrFailed(); RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo(); rsi.setConnectionId(getConnectionInfo().getConnectionId()); diff --git a/activemq-core/src/main/java/org/apache/activemq/command/ConnectionInfo.java b/activemq-core/src/main/java/org/apache/activemq/command/ConnectionInfo.java index cb2f99e1cb..2064440b33 100755 --- a/activemq-core/src/main/java/org/apache/activemq/command/ConnectionInfo.java +++ b/activemq-core/src/main/java/org/apache/activemq/command/ConnectionInfo.java @@ -48,14 +48,23 @@ public class ConnectionInfo extends BaseCommand { return DATA_STRUCTURE_TYPE; } - public void copy(ConnectionInfo copy) { + public ConnectionInfo copy() { + ConnectionInfo copy = new ConnectionInfo(); + copy(copy); + return copy; + } + + private void copy(ConnectionInfo copy) { super.copy(copy); + copy.connectionId = connectionId; copy.clientId = clientId; copy.userName = userName; copy.password = password; copy.brokerPath = brokerPath; copy.brokerMasterConnector = brokerMasterConnector; copy.manageable = manageable; + copy.clientMaster = clientMaster; + copy.transportContext = transportContext; } /** @@ -133,7 +142,7 @@ public class ConnectionInfo extends BaseCommand { } /** - * @param brokerMasterConnector The brokerMasterConnector to set. + * @param slaveBroker The brokerMasterConnector to set. */ public void setBrokerMasterConnector(boolean slaveBroker) { this.brokerMasterConnector = slaveBroker;