r248@34: chirino | 2007-02-23 14:50:13 -0500

Fix to avoid a deadlock.  Better synchonization
 


git-svn-id: https://svn.apache.org/repos/asf/activemq/branches/activemq-4.1@511092 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Hiram R. Chirino 2007-02-23 20:26:06 +00:00
parent fcb1b83c6b
commit 72b9565153
1 changed files with 63 additions and 61 deletions

View File

@ -83,7 +83,7 @@ public class RegionBroker implements Broker {
protected final DestinationStatistics destinationStatistics = new DestinationStatistics(); protected final DestinationStatistics destinationStatistics = new DestinationStatistics();
private final CopyOnWriteArrayList connections = new CopyOnWriteArrayList(); private final CopyOnWriteArrayList connections = new CopyOnWriteArrayList();
private final HashMap destinations = new HashMap(); private final Map destinations = new ConcurrentHashMap();
private final CopyOnWriteArrayList brokerInfos = new CopyOnWriteArrayList(); private final CopyOnWriteArrayList brokerInfos = new CopyOnWriteArrayList();
private final LongSequenceGenerator sequenceGenerator = new LongSequenceGenerator(); private final LongSequenceGenerator sequenceGenerator = new LongSequenceGenerator();
@ -240,16 +240,16 @@ public class RegionBroker implements Broker {
return rc; return rc;
} }
public Destination addDestination(ConnectionContext context, ActiveMQDestination destination) throws Exception { public Destination addDestination(ConnectionContext context,
ActiveMQDestination destination) throws Exception {
Destination answer; Destination answer;
synchronized(destinations) {
answer = (Destination) destinations.get(destination);
if( answer!=null )
return answer;
}
switch(destination.getDestinationType()) { answer = (Destination) destinations.get(destination);
if (answer != null)
return answer;
switch (destination.getDestinationType()) {
case ActiveMQDestination.QUEUE_TYPE: case ActiveMQDestination.QUEUE_TYPE:
answer = queueRegion.addDestination(context, destination); answer = queueRegion.addDestination(context, destination);
break; break;
@ -266,33 +266,35 @@ public class RegionBroker implements Broker {
throw createUnknownDestinationTypeException(destination); throw createUnknownDestinationTypeException(destination);
} }
synchronized(destinations) {
destinations.put(destination, answer); destinations.put(destination, answer);
return answer; return answer;
}
} }
public void removeDestination(ConnectionContext context,ActiveMQDestination destination,long timeout) throws Exception{ public void removeDestination(ConnectionContext context,
synchronized(destinations) { ActiveMQDestination destination, long timeout) throws Exception {
if( destinations.remove(destination)!=null ){
switch(destination.getDestinationType()){ if (destinations.remove(destination) != null) {
switch (destination.getDestinationType()) {
case ActiveMQDestination.QUEUE_TYPE: case ActiveMQDestination.QUEUE_TYPE:
queueRegion.removeDestination(context,destination,timeout); queueRegion.removeDestination(context, destination, timeout);
break; break;
case ActiveMQDestination.TOPIC_TYPE: case ActiveMQDestination.TOPIC_TYPE:
topicRegion.removeDestination(context,destination,timeout); topicRegion.removeDestination(context, destination, timeout);
break; break;
case ActiveMQDestination.TEMP_QUEUE_TYPE: case ActiveMQDestination.TEMP_QUEUE_TYPE:
tempQueueRegion.removeDestination(context,destination,timeout); tempQueueRegion
.removeDestination(context, destination, timeout);
break; break;
case ActiveMQDestination.TEMP_TOPIC_TYPE: case ActiveMQDestination.TEMP_TOPIC_TYPE:
tempTopicRegion.removeDestination(context,destination,timeout); tempTopicRegion
.removeDestination(context, destination, timeout);
break; break;
default: default:
throw createUnknownDestinationTypeException(destination); throw createUnknownDestinationTypeException(destination);
} }
} }
}
} }
public void addDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{ public void addDestinationInfo(ConnectionContext context,DestinationInfo info) throws Exception{
@ -307,9 +309,9 @@ public class RegionBroker implements Broker {
public ActiveMQDestination[] getDestinations() throws Exception { public ActiveMQDestination[] getDestinations() throws Exception {
ArrayList l; ArrayList l;
synchronized(destinations) {
l = new ArrayList(destinations.values()); l = new ArrayList(destinations.values());
}
ActiveMQDestination rc[] = new ActiveMQDestination[l.size()]; ActiveMQDestination rc[] = new ActiveMQDestination[l.size()];
l.toArray(rc); l.toArray(rc);
return rc; return rc;