https://issues.apache.org/activemq/browse/AMQ-1255


git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@647872 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Davies 2008-04-14 16:02:12 +00:00
parent bff39c565b
commit 931ed7673d
3 changed files with 68 additions and 45 deletions

View File

@ -203,6 +203,7 @@ public class AdvisoryBroker extends BrokerFilter {
} }
try { try {
next.removeDestination(context, AdvisorySupport.getProducerAdvisoryTopic(info.getDestination()), -1); next.removeDestination(context, AdvisorySupport.getProducerAdvisoryTopic(info.getDestination()), -1);
} catch (Exception expectedIfDestinationDidNotExistYet) { } catch (Exception expectedIfDestinationDidNotExistYet) {
} }
} }
@ -221,10 +222,13 @@ public class AdvisoryBroker extends BrokerFilter {
next.removeConsumer(context, info); next.removeConsumer(context, info);
// Don't advise advisory topics. // Don't advise advisory topics.
if (!AdvisorySupport.isAdvisoryTopic(info.getDestination())) { ActiveMQDestination dest = info.getDestination();
ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(info.getDestination()); if (!AdvisorySupport.isAdvisoryTopic(dest)) {
ActiveMQTopic topic = AdvisorySupport.getConsumerAdvisoryTopic(dest);
consumers.remove(info.getConsumerId()); consumers.remove(info.getConsumerId());
fireConsumerAdvisory(context,info.getDestination(), topic, info.createRemoveCommand()); if (!dest.isTemporary() || destinations.contains(dest)) {
fireConsumerAdvisory(context,dest, topic, info.createRemoveCommand());
}
} }
} }
@ -232,10 +236,13 @@ public class AdvisoryBroker extends BrokerFilter {
next.removeProducer(context, info); next.removeProducer(context, info);
// Don't advise advisory topics. // Don't advise advisory topics.
if (info.getDestination() != null && !AdvisorySupport.isAdvisoryTopic(info.getDestination())) { ActiveMQDestination dest = info.getDestination();
ActiveMQTopic topic = AdvisorySupport.getProducerAdvisoryTopic(info.getDestination()); if (info.getDestination() != null && !AdvisorySupport.isAdvisoryTopic(dest)) {
ActiveMQTopic topic = AdvisorySupport.getProducerAdvisoryTopic(dest);
producers.remove(info.getProducerId()); producers.remove(info.getProducerId());
fireProducerAdvisory(context, info.getDestination(),topic, info.createRemoveCommand()); if (!dest.isTemporary() || destinations.contains(dest)) {
fireProducerAdvisory(context, dest,topic, info.createRemoveCommand());
}
} }
} }

View File

@ -16,7 +16,6 @@
*/ */
package org.apache.activemq.broker.region; package org.apache.activemq.broker.region;
import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
@ -24,9 +23,7 @@ import java.util.List;
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.ConcurrentHashMap;
import javax.jms.JMSException; import javax.jms.JMSException;
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.DestinationAlreadyExistsException;
@ -96,19 +93,22 @@ public abstract class AbstractRegion implements Region {
context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT); context.setSecurityContext(SecurityContext.BROKER_SECURITY_CONTEXT);
context.getBroker().addDestination(context, dest); context.getBroker().addDestination(context, dest);
} }
synchronized (destinationsMutex) {
for (Iterator<Destination> i = destinations.values().iterator(); i.hasNext();) { for (Iterator<Destination> i = destinations.values().iterator(); i.hasNext();) {
Destination dest = i.next(); Destination dest = i.next();
dest.start(); dest.start();
} }
} }
}
public void stop() throws Exception { public void stop() throws Exception {
started = false; started = false;
synchronized (destinationsMutex) {
for (Iterator<Destination> i = destinations.values().iterator(); i.hasNext();) { for (Iterator<Destination> i = destinations.values().iterator(); i.hasNext();) {
Destination dest = i.next(); Destination dest = i.next();
dest.stop(); dest.stop();
} }
}
destinations.clear(); destinations.clear();
} }
@ -169,10 +169,10 @@ public abstract class AbstractRegion implements Region {
} }
LOG.debug("Removing destination: " + destination); LOG.debug("Removing destination: " + destination);
synchronized (destinationsMutex) { synchronized (destinationsMutex) {
Destination dest = destinations.remove(destination); Destination dest = destinations.remove(destination);
if (dest != null) { if (dest != null) {
// timeout<0 or we timed out, we now force any remaining // timeout<0 or we timed out, we now force any remaining
// subscriptions to un-subscribe. // subscriptions to un-subscribe.
for (Iterator<Subscription> iter = subscriptions.values().iterator(); iter.hasNext();) { for (Iterator<Subscription> iter = subscriptions.values().iterator(); iter.hasNext();) {
@ -181,7 +181,6 @@ public abstract class AbstractRegion implements Region {
dest.removeSubscription(context, sub); dest.removeSubscription(context, sub);
} }
} }
destinationMap.removeAll(destination); destinationMap.removeAll(destination);
dispose(context,dest); dispose(context,dest);
@ -259,10 +258,13 @@ public abstract class AbstractRegion implements Region {
// so everything after this point would be leaked. // so everything after this point would be leaked.
// Add the subscription to all the matching queues. // Add the subscription to all the matching queues.
synchronized(destinationsMutex) {
for (Iterator iter = destinationMap.get(info.getDestination()).iterator(); iter.hasNext();) { for (Iterator iter = destinationMap.get(info.getDestination()).iterator(); iter.hasNext();) {
Destination dest = (Destination)iter.next(); Destination dest = (Destination)iter.next();
dest.addSubscription(context, sub); dest.addSubscription(context, sub);
} }
}
if (info.isBrowser()) { if (info.isBrowser()) {
((QueueBrowserSubscription)sub).destinationsAdded(); ((QueueBrowserSubscription)sub).destinationsAdded();
@ -286,7 +288,9 @@ public abstract class AbstractRegion implements Region {
*/ */
protected Set<ActiveMQDestination> getInactiveDestinations() { protected Set<ActiveMQDestination> getInactiveDestinations() {
Set<ActiveMQDestination> inactiveDests = destinationFactory.getDestinations(); Set<ActiveMQDestination> inactiveDests = destinationFactory.getDestinations();
synchronized (destinationsMutex) {
inactiveDests.removeAll(destinations.keySet()); inactiveDests.removeAll(destinations.keySet());
}
return inactiveDests; return inactiveDests;
} }
@ -298,11 +302,13 @@ public abstract class AbstractRegion implements Region {
if (sub != null) { if (sub != null) {
// remove the subscription from all the matching queues. // remove the subscription from all the matching queues.
synchronized (destinationsMutex) {
for (Iterator iter = destinationMap.get(info.getDestination()) for (Iterator iter = destinationMap.get(info.getDestination())
.iterator(); iter.hasNext();) { .iterator(); iter.hasNext();) {
Destination dest = (Destination) iter.next(); Destination dest = (Destination) iter.next();
dest.removeSubscription(context, sub); dest.removeSubscription(context, sub);
} }
}
destroySubscription(sub); destroySubscription(sub);
} }
@ -396,11 +402,13 @@ public abstract class AbstractRegion implements Region {
Subscription sub = iter.next(); Subscription sub = iter.next();
sub.gc(); sub.gc();
} }
synchronized (destinationsMutex) {
for (Iterator<Destination> iter = destinations.values().iterator(); iter.hasNext();) { for (Iterator<Destination> iter = destinations.values().iterator(); iter.hasNext();) {
Destination dest = iter.next(); Destination dest = iter.next();
dest.gc(); dest.gc();
} }
} }
}
protected abstract Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws Exception; protected abstract Subscription createSubscription(ConnectionContext context, ConsumerInfo info) throws Exception;
@ -417,11 +425,13 @@ public abstract class AbstractRegion implements Region {
} }
public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception{ public void addProducer(ConnectionContext context, ProducerInfo info) throws Exception{
synchronized (destinationsMutex) {
for (Iterator iter = destinationMap.get(info.getDestination()).iterator(); iter.hasNext();) { for (Iterator iter = destinationMap.get(info.getDestination()).iterator(); iter.hasNext();) {
Destination dest = (Destination) iter.next(); Destination dest = (Destination) iter.next();
dest.addProducer(context, info); dest.addProducer(context, info);
} }
} }
}
/** /**
* Removes a Producer. * Removes a Producer.
@ -429,11 +439,13 @@ public abstract class AbstractRegion implements Region {
* @throws Exception TODO * @throws Exception TODO
*/ */
public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception{ public void removeProducer(ConnectionContext context, ProducerInfo info) throws Exception{
synchronized (destinationsMutex) {
for (Iterator iter = destinationMap.get(info.getDestination()).iterator(); iter.hasNext();) { for (Iterator iter = destinationMap.get(info.getDestination()).iterator(); iter.hasNext();) {
Destination dest = (Destination)iter.next(); Destination dest = (Destination)iter.next();
dest.removeProducer(context, info); dest.removeProducer(context, info);
} }
} }
}
protected void dispose(ConnectionContext context,Destination dest) throws Exception { protected void dispose(ConnectionContext context,Destination dest) throws Exception {
dest.dispose(context); dest.dispose(context);

View File

@ -78,10 +78,12 @@ public class TopicRegion extends AbstractRegion {
if (hasDurableSubChanged(info, sub.getConsumerInfo())) { if (hasDurableSubChanged(info, sub.getConsumerInfo())) {
// Remove the consumer first then add it. // Remove the consumer first then add it.
durableSubscriptions.remove(key); durableSubscriptions.remove(key);
synchronized (destinationsMutex) {
for (Iterator<Destination> iter = destinations.values().iterator(); iter.hasNext();) { for (Iterator<Destination> iter = destinations.values().iterator(); iter.hasNext();) {
Topic topic = (Topic)iter.next(); Topic topic = (Topic)iter.next();
topic.deleteSubscription(context, key); topic.deleteSubscription(context, key);
} }
}
super.removeConsumer(context, sub.getConsumerInfo()); super.removeConsumer(context, sub.getConsumerInfo());
super.addConsumer(context, info); super.addConsumer(context, info);
sub = durableSubscriptions.get(key); sub = durableSubscriptions.get(key);
@ -132,10 +134,12 @@ public class TopicRegion extends AbstractRegion {
} }
durableSubscriptions.remove(key); durableSubscriptions.remove(key);
synchronized (destinationsMutex) {
for (Iterator<Destination> iter = destinations.values().iterator(); iter.hasNext();) { for (Iterator<Destination> iter = destinations.values().iterator(); iter.hasNext();) {
Topic topic = (Topic)iter.next(); Topic topic = (Topic)iter.next();
topic.deleteSubscription(context, key); topic.deleteSubscription(context, key);
} }
}
super.removeConsumer(context, sub.getConsumerInfo()); super.removeConsumer(context, sub.getConsumerInfo());
} }