Jonas B. Lim 2007-07-24 12:32:09 +00:00
parent 9b5acf4fa1
commit e3a13763e6
3 changed files with 91 additions and 60 deletions

View File

@ -165,14 +165,17 @@ public class AdvisoryBroker extends BrokerFilter {
info.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE); info.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE);
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination); ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destination);
fireAdvisory(context, topic, info); fireAdvisory(context, topic, info);
try {
next.removeDestination(context, AdvisorySupport.getConsumerAdvisoryTopic(info.getDestination()), -1); if (!AdvisorySupport.isAdvisoryTopic(destination)) {
} catch (Exception expectedIfDestinationDidNotExistYet) { try {
} context.getBroker().removeDestination(context, AdvisorySupport.getConsumerAdvisoryTopic(info.getDestination()), -1);
try { } catch (Exception expectedIfDestinationDidNotExistYet) {
next.removeDestination(context, AdvisorySupport.getProducerAdvisoryTopic(info.getDestination()), -1); }
} catch (Exception expectedIfDestinationDidNotExistYet) { try {
} context.getBroker().removeDestination(context, AdvisorySupport.getProducerAdvisoryTopic(info.getDestination()), -1);
} catch (Exception expectedIfDestinationDidNotExistYet) {
}
}
} }
} }
@ -186,14 +189,17 @@ public class AdvisoryBroker extends BrokerFilter {
info.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE); info.setOperationType(DestinationInfo.REMOVE_OPERATION_TYPE);
ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destInfo.getDestination()); ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(destInfo.getDestination());
fireAdvisory(context, topic, info); fireAdvisory(context, topic, info);
try {
next.removeDestination(context, AdvisorySupport.getConsumerAdvisoryTopic(info.getDestination()), -1); if (!AdvisorySupport.isAdvisoryTopic(destInfo.getDestination())) {
} catch (Exception expectedIfDestinationDidNotExistYet) { try {
} context.getBroker().removeDestination(context, AdvisorySupport.getConsumerAdvisoryTopic(info.getDestination()), -1);
try { } catch (Exception expectedIfDestinationDidNotExistYet) {
next.removeDestination(context, AdvisorySupport.getProducerAdvisoryTopic(info.getDestination()), -1); }
} catch (Exception expectedIfDestinationDidNotExistYet) { try {
} context.getBroker().removeDestination(context, AdvisorySupport.getProducerAdvisoryTopic(info.getDestination()), -1);
} catch (Exception expectedIfDestinationDidNotExistYet) {
}
}
} }
} }

View File

@ -162,7 +162,7 @@ public class DestinationMap {
} }
/** /**
* @param dest * @param key
* @return * @return
*/ */
public Set removeAll(ActiveMQDestination key) { public Set removeAll(ActiveMQDestination key) {

View File

@ -24,31 +24,39 @@ import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.Iterator;
/** /**
* An implementation class used to implement {@link DestinationMap} * An implementation class used to implement {@link DestinationMap}
* *
* @version $Revision: 1.2 $ * @version $Revision: 1.2 $
*/ */
public class DestinationMapNode { public class DestinationMapNode implements DestinationNode {
protected static final String ANY_CHILD = DestinationMap.ANY_CHILD;
protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
// we synchornize at the DestinationMap level // we synchornize at the DestinationMap level
private DestinationMapNode parent; private DestinationMapNode parent;
private List values = new ArrayList(); private List values = new ArrayList();
private Map childNodes = new HashMap(); private Map childNodes = new HashMap();
private String path = "*"; private String path = "Root";
private DestinationMapNode anyChild; // private DestinationMapNode anyChild;
protected static final String ANY_CHILD = DestinationMap.ANY_CHILD; private int pathLength;
protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
public DestinationMapNode(DestinationMapNode parent) { public DestinationMapNode(DestinationMapNode parent) {
this.parent = parent; this.parent = parent;
if (parent == null) {
pathLength = 0;
}
else {
pathLength = parent.pathLength + 1;
}
} }
/** /**
* Returns the child node for the given named path or null if it does not * Returns the child node for the given named path or null if it does not
* exist * exist
*/ */
public DestinationMapNode getChild(String path) { public DestinationNode getChild(String path) {
return (DestinationMapNode) childNodes.get(path); return (DestinationMapNode) childNodes.get(path);
} }
@ -80,49 +88,49 @@ public class DestinationMapNode {
/** /**
* Returns the node which represents all children (i.e. the * node) * Returns the node which represents all children (i.e. the * node)
*/ */
public DestinationMapNode getAnyChildNode() { //public DestinationMapNode getAnyChildNode() {
if (anyChild == null) { // if (anyChild == null) {
anyChild = createChildNode(); // anyChild = createChildNode();
} // }
return anyChild; // return anyChild;
} //}
/** /**
* Returns a mutable List of the values available at this node in the tree * Returns a mutable List of the values available at this node in the tree
*/ */
public List getValues() { public Collection getValues() {
return values; return values;
} }
/** /**
* Returns a mutable List of the values available at this node in the tree * Returns a mutable List of the values available at this node in the tree
*/ */
public List removeValues() { public Collection removeValues() {
ArrayList v = new ArrayList(values); ArrayList v = new ArrayList(values);
parent.getAnyChildNode().getValues().removeAll(v); // parent.getAnyChildNode().getValues().removeAll(v);
values.clear(); values.clear();
pruneIfEmpty(); pruneIfEmpty();
return v; return v;
} }
public Set removeDesendentValues() { public Collection removeDesendentValues() {
Set answer = new HashSet(); Set answer = new HashSet();
removeDesendentValues(answer); removeDesendentValues(answer);
return answer; return answer;
} }
protected void removeDesendentValues(Set answer) { protected void removeDesendentValues(Set answer) {
if (anyChild != null) { // if (anyChild != null) {
anyChild.removeDesendentValues(answer); // anyChild.removeDesendentValues(answer);
} // }
answer.addAll(removeValues()); answer.addAll(removeValues());
} }
/** /**
* Returns a list of all the values from this node down the tree * Returns a list of all the values from this node down the tree
*/ */
public Set getDesendentValues() { public Collection getDesendentValues() {
Set answer = new HashSet(); Set answer = new HashSet();
appendDescendantValues(answer); appendDescendantValues(answer);
return answer; return answer;
@ -133,12 +141,12 @@ public class DestinationMapNode {
values.add(value); values.add(value);
} }
else { else {
if (idx == paths.length - 1) { // if (idx == paths.length - 1) {
getAnyChildNode().getValues().add(value); // getAnyChildNode().getValues().add(value);
} // }
else { // else {
getAnyChildNode().add(paths, idx + 1, value); // getAnyChildNode().add(paths, idx + 1, value);
} // }
getChildOrCreate(paths[idx]).add(paths, idx + 1, value); getChildOrCreate(paths[idx]).add(paths, idx + 1, value);
} }
} }
@ -149,12 +157,12 @@ public class DestinationMapNode {
pruneIfEmpty(); pruneIfEmpty();
} }
else { else {
if (idx == paths.length - 1) { // if (idx == paths.length - 1) {
getAnyChildNode().getValues().remove(value); // getAnyChildNode().getValues().remove(value);
} // }
else { // else {
getAnyChildNode().remove(paths, idx + 1, value); // getAnyChildNode().remove(paths, idx + 1, value);
} // }
getChildOrCreate(paths[idx]).remove(paths, ++idx, value); getChildOrCreate(paths[idx]).remove(paths, ++idx, value);
} }
} }
@ -175,7 +183,7 @@ public class DestinationMapNode {
// } // }
// //
DestinationMapNode node = this; DestinationNode node = this;
for (int i = startIndex, size = paths.length; i < size && node != null; i++) { for (int i = startIndex, size = paths.length; i < size && node != null; i++) {
String path = paths[i]; String path = paths[i];
@ -186,7 +194,8 @@ public class DestinationMapNode {
node.appendMatchingWildcards(answer, paths, i); node.appendMatchingWildcards(answer, paths, i);
if (path.equals(ANY_CHILD)) { if (path.equals(ANY_CHILD)) {
node = node.getAnyChildNode(); //node = node.getAnyChildNode();
node = new AnyChildDestinationNode(node);
} }
else { else {
node = node.getChild(path); node = node.getChild(path);
@ -200,11 +209,20 @@ public class DestinationMapNode {
} }
protected void appendDescendantValues(Set answer) { public void appendDescendantValues(Set answer) {
answer.addAll(values); answer.addAll(values);
if (anyChild != null) {
anyChild.appendDescendantValues(answer); // lets add all the children too
} Iterator iter = childNodes.values().iterator();
while (iter.hasNext()) {
DestinationNode child = (DestinationNode) iter.next();
child.appendDescendantValues(answer);
}
// TODO???
// if (anyChild != null) {
// anyChild.appendDescendantValues(answer);
// }
} }
/** /**
@ -214,8 +232,15 @@ public class DestinationMapNode {
return new DestinationMapNode(this); return new DestinationMapNode(this);
} }
/**
* Matches any entries in the map containing wildcards
*/
public void appendMatchingWildcards(Set answer, String[] paths, int idx) { public void appendMatchingWildcards(Set answer, String[] paths, int idx) {
DestinationMapNode wildCardNode = getChild(ANY_CHILD); if (idx - 1 > pathLength) {
return;
}
DestinationNode wildCardNode = getChild(ANY_CHILD);
if (wildCardNode != null) { if (wildCardNode != null) {
wildCardNode.appendMatchingValues(answer, paths, idx + 1); wildCardNode.appendMatchingValues(answer, paths, idx + 1);
} }
@ -226,7 +251,7 @@ public class DestinationMapNode {
} }
public void appendMatchingValues(Set answer, String[] paths, int startIndex) { public void appendMatchingValues(Set answer, String[] paths, int startIndex) {
DestinationMapNode node = this; DestinationNode node = this;
boolean couldMatchAny = true; boolean couldMatchAny = true;
for (int i = startIndex, size = paths.length; i < size && node != null; i++) { for (int i = startIndex, size = paths.length; i < size && node != null; i++) {
String path = paths[i]; String path = paths[i];
@ -238,7 +263,7 @@ public class DestinationMapNode {
node.appendMatchingWildcards(answer, paths, i); node.appendMatchingWildcards(answer, paths, i);
if (path.equals(ANY_CHILD)) { if (path.equals(ANY_CHILD)) {
node = node.getAnyChildNode(); node = new AnyChildDestinationNode(node);
} }
else { else {
node = node.getChild(path); node = node.getChild(path);
@ -248,7 +273,7 @@ public class DestinationMapNode {
answer.addAll(node.getValues()); answer.addAll(node.getValues());
if (couldMatchAny) { if (couldMatchAny) {
// lets allow FOO.BAR to match the FOO.BAR.> entry in the map // lets allow FOO.BAR to match the FOO.BAR.> entry in the map
DestinationMapNode child = node.getChild(ANY_DESCENDENT); DestinationNode child = node.getChild(ANY_DESCENDENT);
if (child != null) { if (child != null) {
answer.addAll(child.getValues()); answer.addAll(child.getValues());
} }