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
This commit is contained in:
David Jencks 2008-12-30 20:05:16 +00:00
parent 90fd917a67
commit e08cc350e0
2 changed files with 15 additions and 5 deletions

View File

@ -51,6 +51,7 @@ import javax.jms.Topic;
import javax.jms.TopicConnection; import javax.jms.TopicConnection;
import javax.jms.TopicSession; import javax.jms.TopicSession;
import javax.jms.XAConnection; import javax.jms.XAConnection;
import javax.jms.InvalidDestinationException;
import org.apache.activemq.blob.BlobTransferPolicy; import org.apache.activemq.blob.BlobTransferPolicy;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
@ -1332,11 +1333,11 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
if (isConnectionInfoSentToBroker || closed.get()) { if (isConnectionInfoSentToBroker || closed.get()) {
return; return;
} }
//TODO shouldn't this check be on userSpecifiedClientID rather than the value of clientID?
if (info.getClientId() == null || info.getClientId().trim().length() == 0) { if (info.getClientId() == null || info.getClientId().trim().length() == 0) {
info.setClientId(clientIdGenerator.generateId()); info.setClientId(clientIdGenerator.generateId());
} }
syncSendPacket(info); syncSendPacket(info.copy());
this.isConnectionInfoSentToBroker = true; this.isConnectionInfoSentToBroker = true;
// Add a temp destination advisory consumer so that // Add a temp destination advisory consumer so that
@ -2043,7 +2044,7 @@ public class ActiveMQConnection implements Connection, TopicConnection, QueueCon
* specified. * specified.
* @since 1.1 * @since 1.1
*/ */
public void unsubscribe(String name) throws JMSException { public void unsubscribe(String name) throws InvalidDestinationException, JMSException {
checkClosedOrFailed(); checkClosedOrFailed();
RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo(); RemoveSubscriptionInfo rsi = new RemoveSubscriptionInfo();
rsi.setConnectionId(getConnectionInfo().getConnectionId()); rsi.setConnectionId(getConnectionInfo().getConnectionId());

View File

@ -48,14 +48,23 @@ public class ConnectionInfo extends BaseCommand {
return DATA_STRUCTURE_TYPE; 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); super.copy(copy);
copy.connectionId = connectionId;
copy.clientId = clientId; copy.clientId = clientId;
copy.userName = userName; copy.userName = userName;
copy.password = password; copy.password = password;
copy.brokerPath = brokerPath; copy.brokerPath = brokerPath;
copy.brokerMasterConnector = brokerMasterConnector; copy.brokerMasterConnector = brokerMasterConnector;
copy.manageable = manageable; 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) { public void setBrokerMasterConnector(boolean slaveBroker) {
this.brokerMasterConnector = slaveBroker; this.brokerMasterConnector = slaveBroker;