added a helper method so a BrokerFilter can lookup all the active destinations for a specific wildcard which can be useful for implementing things like AMQ-452 to support virtual destinations

git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@419629 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
James Strachan 2006-07-06 17:50:56 +00:00
parent a5971e69ab
commit 06a5829c14
7 changed files with 60 additions and 8 deletions

View File

@ -16,8 +16,6 @@
*/ */
package org.apache.activemq.broker; package org.apache.activemq.broker;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.region.Destination; import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Subscription; import org.apache.activemq.broker.region.Subscription;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
@ -35,6 +33,9 @@ import org.apache.activemq.command.RemoveSubscriptionInfo;
import org.apache.activemq.command.SessionInfo; import org.apache.activemq.command.SessionInfo;
import org.apache.activemq.command.TransactionId; import org.apache.activemq.command.TransactionId;
import java.util.Map;
import java.util.Set;
/** /**
* Allows you to intercept broker operation so that features such as security can be * Allows you to intercept broker operation so that features such as security can be
* implemented as a pluggable filter. * implemented as a pluggable filter.
@ -49,7 +50,6 @@ public class BrokerFilter implements Broker {
this.next=next; this.next=next;
} }
public Broker getAdaptor(Class type){ public Broker getAdaptor(Class type){
if (type.isInstance(this)){ if (type.isInstance(this)){
return this; return this;
@ -61,6 +61,10 @@ public class BrokerFilter implements Broker {
return next.getDestinationMap(); return next.getDestinationMap();
} }
public Set getDestinations(ActiveMQDestination destination) {
return next.getDestinations(destination);
}
public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception { public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
next.acknowledge(context, ack); next.acknowledge(context, ack);
} }

View File

@ -16,9 +16,6 @@
*/ */
package org.apache.activemq.broker; package org.apache.activemq.broker;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.region.Destination; import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Subscription; import org.apache.activemq.broker.region.Subscription;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
@ -36,6 +33,10 @@ import org.apache.activemq.command.RemoveSubscriptionInfo;
import org.apache.activemq.command.SessionInfo; import org.apache.activemq.command.SessionInfo;
import org.apache.activemq.command.TransactionId; import org.apache.activemq.command.TransactionId;
import java.util.Collections;
import java.util.Map;
import java.util.Set;
/** /**
* Dumb implementation - used to be overriden by listeners * Dumb implementation - used to be overriden by listeners
* *
@ -62,6 +63,10 @@ public class EmptyBroker implements Broker{
return Collections.EMPTY_MAP; return Collections.EMPTY_MAP;
} }
public Set getDestinations(ActiveMQDestination destination) {
return Collections.EMPTY_SET;
}
public void addConnection(ConnectionContext context,ConnectionInfo info) throws Exception{ public void addConnection(ConnectionContext context,ConnectionInfo info) throws Exception{
} }

View File

@ -54,6 +54,10 @@ public class ErrorBroker implements Broker {
return Collections.EMPTY_MAP; return Collections.EMPTY_MAP;
} }
public Set getDestinations(ActiveMQDestination destination) {
return Collections.EMPTY_SET;
}
public Broker getAdaptor(Class type){ public Broker getAdaptor(Class type){
if (type.isInstance(this)){ if (type.isInstance(this)){
return this; return this;

View File

@ -16,8 +16,6 @@
*/ */
package org.apache.activemq.broker; package org.apache.activemq.broker;
import java.util.Map;
import java.util.Set;
import org.apache.activemq.broker.region.Destination; import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Subscription; import org.apache.activemq.broker.region.Subscription;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
@ -35,6 +33,9 @@ import org.apache.activemq.command.RemoveSubscriptionInfo;
import org.apache.activemq.command.SessionInfo; import org.apache.activemq.command.SessionInfo;
import org.apache.activemq.command.TransactionId; import org.apache.activemq.command.TransactionId;
import java.util.Map;
import java.util.Set;
/** /**
* Like a BrokerFilter but it allows you to switch the getNext().broker. This has more * Like a BrokerFilter but it allows you to switch the getNext().broker. This has more
* overhead than a BrokerFilter since access to the getNext().broker has to synchronized * overhead than a BrokerFilter since access to the getNext().broker has to synchronized
@ -74,6 +75,10 @@ public class MutableBrokerFilter implements Broker {
return getNext().getDestinationMap(); return getNext().getDestinationMap();
} }
public Set getDestinations(ActiveMQDestination destination) {
return getNext().getDestinations(destination);
}
public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception { public void acknowledge(ConnectionContext context, MessageAck ack) throws Exception {
getNext().acknowledge(context, ack); getNext().acknowledge(context, ack);
} }

View File

@ -134,6 +134,17 @@ abstract public class AbstractRegion implements Region {
} }
} }
/**
* Provide an exact or wildcard lookup of destinations in the region
*
* @return a set of matching destination objects.
*/
public Set getDestinations(ActiveMQDestination destination) {
synchronized(destinationsMutex){
return destinationMap.get(destination);
}
}
public Map getDestinationMap() { public Map getDestinationMap() {
synchronized(destinationsMutex){ synchronized(destinationsMutex){
return new HashMap(destinations); return new HashMap(destinations);

View File

@ -26,6 +26,7 @@ import org.apache.activemq.command.MessageDispatchNotification;
import org.apache.activemq.command.RemoveSubscriptionInfo; import org.apache.activemq.command.RemoveSubscriptionInfo;
import java.util.Map; import java.util.Map;
import java.util.Set;
/** /**
* A Region is used to implement the different QOS options available to * A Region is used to implement the different QOS options available to
@ -115,4 +116,11 @@ public interface Region extends Service {
public void gc(); public void gc();
/**
* Provide an exact or wildcard lookup of destinations in the region
*
* @return a set of matching destination objects.
*/
public Set getDestinations(ActiveMQDestination destination);
} }

View File

@ -103,6 +103,21 @@ public class RegionBroker implements Broker {
return answer; return answer;
} }
public Set getDestinations(ActiveMQDestination destination) {
switch(destination.getDestinationType()) {
case ActiveMQDestination.QUEUE_TYPE:
return queueRegion.getDestinations(destination);
case ActiveMQDestination.TOPIC_TYPE:
return topicRegion.getDestinations(destination);
case ActiveMQDestination.TEMP_QUEUE_TYPE:
return tempQueueRegion.getDestinations(destination);
case ActiveMQDestination.TEMP_TOPIC_TYPE:
return tempTopicRegion.getDestinations(destination);
default:
return Collections.EMPTY_SET;
}
}
public Broker getAdaptor(Class type){ public Broker getAdaptor(Class type){
if (type.isInstance(this)){ if (type.isInstance(this)){
return this; return this;