Fix for AMQ-1341 - Improve the InvalidClientIDException message so that we know where the previous connection was established from.

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@559111 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2007-07-24 17:08:31 +00:00
parent 5a3a45f0c0
commit 97a591f08f
1 changed files with 9 additions and 14 deletions

View File

@ -24,23 +24,20 @@ import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
import javax.jms.InvalidClientIDException; import javax.jms.InvalidClientIDException;
import javax.jms.JMSException; import javax.jms.JMSException;
import org.apache.activemq.ActiveMQMessageAudit;
import org.apache.activemq.broker.Broker; import org.apache.activemq.broker.Broker;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.Connection; import org.apache.activemq.broker.Connection;
import org.apache.activemq.broker.ConnectionContext; import org.apache.activemq.broker.ConnectionContext;
import org.apache.activemq.broker.ConsumerBrokerExchange; import org.apache.activemq.broker.ConsumerBrokerExchange;
import org.apache.activemq.broker.DestinationAlreadyExistsException;
import org.apache.activemq.broker.ProducerBrokerExchange; import org.apache.activemq.broker.ProducerBrokerExchange;
import org.apache.activemq.broker.TransactionBroker;
import org.apache.activemq.broker.region.policy.DeadLetterStrategy; import org.apache.activemq.broker.region.policy.DeadLetterStrategy;
import org.apache.activemq.broker.region.policy.PendingDurableSubscriberMessageStoragePolicy;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.broker.region.policy.VMPendingDurableSubscriberMessageStoragePolicy;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.BrokerId; import org.apache.activemq.command.BrokerId;
import org.apache.activemq.command.BrokerInfo; import org.apache.activemq.command.BrokerInfo;
@ -70,9 +67,6 @@ import org.apache.activemq.util.ServiceStopper;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
/** /**
* Routes Broker operations to the correct messaging regions for processing. * Routes Broker operations to the correct messaging regions for processing.
@ -100,7 +94,7 @@ public class RegionBroker implements Broker {
private final LongSequenceGenerator sequenceGenerator = new LongSequenceGenerator(); private final LongSequenceGenerator sequenceGenerator = new LongSequenceGenerator();
private BrokerId brokerId; private BrokerId brokerId;
private String brokerName; private String brokerName;
private Map clientIdSet = new HashMap(); // we will synchronize access private Map<String, ConnectionContext> clientIdSet = new HashMap<String, ConnectionContext>(); // we will synchronize access
private final DestinationInterceptor destinationInterceptor; private final DestinationInterceptor destinationInterceptor;
private ConnectionContext adminConnectionContext; private ConnectionContext adminConnectionContext;
protected DestinationFactory destinationFactory; protected DestinationFactory destinationFactory;
@ -213,11 +207,12 @@ public class RegionBroker implements Broker {
throw new InvalidClientIDException("No clientID specified for connection request"); throw new InvalidClientIDException("No clientID specified for connection request");
} }
synchronized (clientIdSet ) { synchronized (clientIdSet ) {
if (clientIdSet.containsKey(clientId)) { ConnectionContext oldContext = clientIdSet.get(clientId);
throw new InvalidClientIDException("Broker: " + getBrokerName() + " - Client: " + clientId + " already connected"); if (oldContext!=null) {
throw new InvalidClientIDException("Broker: " + getBrokerName() + " - Client: " + clientId + " already connected from "+oldContext.getConnection().getRemoteAddress());
} }
else { else {
clientIdSet.put(clientId, info); clientIdSet.put(clientId, context);
} }
} }
@ -230,10 +225,10 @@ public class RegionBroker implements Broker {
throw new InvalidClientIDException("No clientID specified for connection disconnect request"); throw new InvalidClientIDException("No clientID specified for connection disconnect request");
} }
synchronized (clientIdSet) { synchronized (clientIdSet) {
ConnectionInfo oldValue = (ConnectionInfo) clientIdSet.get(clientId); ConnectionContext oldValue = clientIdSet.get(clientId);
// we may be removing the duplicate connection, not the first connection to be created // we may be removing the duplicate connection, not the first connection to be created
// so lets check that their connection IDs are the same // so lets check that their connection IDs are the same
if (oldValue != null) { if (oldValue == context ) {
if (isEqual(oldValue.getConnectionId(), info.getConnectionId())) { if (isEqual(oldValue.getConnectionId(), info.getConnectionId())) {
clientIdSet.remove(clientId); clientIdSet.remove(clientId);
} }