mirror of https://github.com/apache/activemq.git
fixed edge cases in DestinationMap
git-svn-id: https://svn.apache.org/repos/asf/incubator/activemq/trunk@365882 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6cbd6d2e8d
commit
664b534be5
|
@ -27,10 +27,24 @@ import org.springframework.beans.factory.InitializingBean;
|
||||||
*
|
*
|
||||||
* @version $Revision: 1.1 $
|
* @version $Revision: 1.1 $
|
||||||
*/
|
*/
|
||||||
public abstract class DestinationMapEntry implements InitializingBean {
|
public abstract class DestinationMapEntry implements InitializingBean, Comparable {
|
||||||
|
|
||||||
private ActiveMQDestination destination;
|
private ActiveMQDestination destination;
|
||||||
|
|
||||||
|
|
||||||
|
public int compareTo(Object that) {
|
||||||
|
if (that instanceof DestinationMapEntry) {
|
||||||
|
DestinationMapEntry thatEntry = (DestinationMapEntry) that;
|
||||||
|
return ActiveMQDestination.compare(destination, thatEntry.destination);
|
||||||
|
}
|
||||||
|
else if (that == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return getClass().getName().compareTo(that.getClass().getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A helper method to set the destination from a configuration file
|
* A helper method to set the destination from a configuration file
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -25,7 +25,7 @@ import java.util.Set;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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 {
|
||||||
|
@ -38,14 +38,13 @@ public class DestinationMapNode {
|
||||||
protected static final String ANY_CHILD = DestinationMap.ANY_CHILD;
|
protected static final String ANY_CHILD = DestinationMap.ANY_CHILD;
|
||||||
protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
|
protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
|
||||||
|
|
||||||
|
|
||||||
public DestinationMapNode(DestinationMapNode parent) {
|
public DestinationMapNode(DestinationMapNode parent) {
|
||||||
this.parent = parent;
|
this.parent = parent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the child node for the given named path or null if it does not exist
|
* Returns the child node for the given named path or null if it does not
|
||||||
|
* exist
|
||||||
*/
|
*/
|
||||||
public DestinationMapNode getChild(String path) {
|
public DestinationMapNode getChild(String path) {
|
||||||
return (DestinationMapNode) childNodes.get(path);
|
return (DestinationMapNode) childNodes.get(path);
|
||||||
|
@ -54,10 +53,10 @@ public class DestinationMapNode {
|
||||||
public int getChildCount() {
|
public int getChildCount() {
|
||||||
return childNodes.size();
|
return childNodes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the child node for the given named path, lazily creating one if it does
|
* Returns the child node for the given named path, lazily creating one if
|
||||||
* not yet exist
|
* it does not yet exist
|
||||||
*/
|
*/
|
||||||
public DestinationMapNode getChildOrCreate(String path) {
|
public DestinationMapNode getChildOrCreate(String path) {
|
||||||
DestinationMapNode answer = (DestinationMapNode) childNodes.get(path);
|
DestinationMapNode answer = (DestinationMapNode) childNodes.get(path);
|
||||||
|
@ -169,10 +168,12 @@ public class DestinationMapNode {
|
||||||
|
|
||||||
public void appendMatchingValues(Set answer, String[] paths, int startIndex) {
|
public void appendMatchingValues(Set answer, String[] paths, int startIndex) {
|
||||||
DestinationMapNode node = this;
|
DestinationMapNode node = this;
|
||||||
|
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];
|
||||||
if (path.equals(ANY_DESCENDENT)) {
|
if (path.equals(ANY_DESCENDENT)) {
|
||||||
answer.addAll(node.getDesendentValues());
|
answer.addAll(node.getDesendentValues());
|
||||||
|
couldMatchAny = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -186,10 +187,16 @@ public class DestinationMapNode {
|
||||||
}
|
}
|
||||||
if (node != null) {
|
if (node != null) {
|
||||||
answer.addAll(node.getValues());
|
answer.addAll(node.getValues());
|
||||||
|
if (couldMatchAny) {
|
||||||
|
// lets allow FOO.BAR to match the FOO.BAR.> entry in the map
|
||||||
|
DestinationMapNode child = node.getChild(ANY_DESCENDENT);
|
||||||
|
if (child != null) {
|
||||||
|
answer.addAll(child.getValues());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public String getPath() {
|
public String getPath() {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
@ -200,7 +207,6 @@ public class DestinationMapNode {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void removeChild(DestinationMapNode node) {
|
protected void removeChild(DestinationMapNode node) {
|
||||||
childNodes.remove(node.getPath());
|
childNodes.remove(node.getPath());
|
||||||
pruneIfEmpty();
|
pruneIfEmpty();
|
||||||
|
|
|
@ -165,20 +165,34 @@ public class DestinationMapTest extends TestCase {
|
||||||
put("TEST.XYZ.D4", v4);
|
put("TEST.XYZ.D4", v4);
|
||||||
put("TEST.BAR.D3", v5);
|
put("TEST.BAR.D3", v5);
|
||||||
put("TEST.*.D2", v6);
|
put("TEST.*.D2", v6);
|
||||||
|
|
||||||
|
|
||||||
assertMapValue("TEST.*.D3", v2, v3, v5);
|
assertMapValue("TEST.*.D3", v2, v3, v5);
|
||||||
assertMapValue("TEST.*.D4", v2, v4);
|
assertMapValue("TEST.*.D4", v2, v4);
|
||||||
|
|
||||||
assertMapValue("TEST.*", v1, v2);
|
assertMapValue("TEST.*", v1, v2);
|
||||||
assertMapValue("TEST.*.*", v2, v3, v4, v5, v6);
|
assertMapValue("TEST.*.*", v2, v3, v4, v5, v6);
|
||||||
assertMapValue("*.*.D3", v2, v3, v5);
|
assertMapValue("*.*.D3", v2, v3, v5);
|
||||||
assertMapValue("TEST.BAR.*", v2, v5, v6);
|
assertMapValue("TEST.BAR.*", v2, v5, v6);
|
||||||
|
|
||||||
assertMapValue("TEST.BAR.D2", v2, v6);
|
assertMapValue("TEST.BAR.D2", v2, v6);
|
||||||
assertMapValue("TEST.*.D2", v2, v6);
|
assertMapValue("TEST.*.D2", v2, v6);
|
||||||
assertMapValue("TEST.BAR.*", v2, v5, v6);
|
assertMapValue("TEST.BAR.*", v2, v5, v6);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testAnyPathWildcardInMap() throws Exception {
|
||||||
|
put("TEST.FOO.>", v1);
|
||||||
|
|
||||||
|
|
||||||
|
assertMapValue("TEST.FOO.BAR.WHANOT.A.B.C", v1);
|
||||||
|
assertMapValue("TEST.FOO.BAR.WHANOT", v1);
|
||||||
|
assertMapValue("TEST.FOO.BAR", v1);
|
||||||
|
|
||||||
|
assertMapValue("TEST.*.*", v1);
|
||||||
|
assertMapValue("TEST.BAR", null);
|
||||||
|
|
||||||
|
assertMapValue("TEST.FOO", v1);
|
||||||
|
}
|
||||||
|
|
||||||
public void testSimpleAddRemove() throws Exception {
|
public void testSimpleAddRemove() throws Exception {
|
||||||
put("TEST.D1", v2);
|
put("TEST.D1", v2);
|
||||||
|
|
Loading…
Reference in New Issue