You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by ch...@apache.org on 2009/06/19 15:26:53 UTC
svn commit: r786503 - in /activemq/sandbox/activemq-flow:
activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/
activemq-broker/src/test/java/org/apache/activemq/apollo/broker/wildcard/
activemq-util/src/main/java/org/apache/activem...
Author: chirino
Date: Fri Jun 19 13:26:52 2009
New Revision: 786503
URL: http://svn.apache.org/viewvc?rev=786503&view=rev
Log:
Updated the DestinationMap to use AsciiBuffer throughout instead of String. Should avoid some conversions in the broker.
Modified:
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/AnyChildDestinationNode.java
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationFilter.java
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMap.java
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapNode.java
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationNode.java
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationPath.java
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/PrefixDestinationFilter.java
activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/WildcardDestinationFilter.java
activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapTest.java
activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/AsciiBuffer.java
activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/Buffer.java
activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/UTF8Buffer.java
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/AnyChildDestinationNode.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/AnyChildDestinationNode.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/AnyChildDestinationNode.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/AnyChildDestinationNode.java Fri Jun 19 13:26:52 2009
@@ -20,6 +20,8 @@
import java.util.Collection;
import java.util.Set;
+import org.apache.activemq.protobuf.AsciiBuffer;
+
/**
* An implementation of {@link DestinationNode} which navigates all the children of the given node
* ignoring the name of the current path (so for navigating using * in a wildcard).
@@ -33,14 +35,14 @@
this.node = node;
}
- public void appendMatchingValues(Set<Value> answer, String[] paths, int startIndex) {
+ public void appendMatchingValues(Set<Value> answer, ArrayList<AsciiBuffer> paths, int startIndex) {
for (DestinationNode<Value> child : getChildNodes()) {
child.appendMatchingValues(answer, paths, startIndex);
}
}
- public void appendMatchingWildcards(Set<Value> answer, String[] paths, int startIndex) {
+ public void appendMatchingWildcards(Set<Value> answer, ArrayList<AsciiBuffer> paths, int startIndex) {
for (DestinationNode<Value> child : getChildNodes()) {
child.appendMatchingWildcards(answer, paths, startIndex);
}
@@ -53,7 +55,7 @@
}
}
- public DestinationNode<Value> getChild(String path) {
+ public DestinationNode<Value> getChild(AsciiBuffer path) {
final Collection<DestinationNode<Value>> list = new ArrayList<DestinationNode<Value>>();
for (DestinationNode<Value> child : getChildNodes()) {
DestinationNode<Value> answer = child.getChild(path);
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationFilter.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationFilter.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationFilter.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationFilter.java Fri Jun 19 13:26:52 2009
@@ -17,12 +17,14 @@
package org.apache.activemq.apollo.broker.wildcard;
+import java.util.ArrayList;
import java.util.Collection;
import org.apache.activemq.apollo.broker.Destination;
import org.apache.activemq.filter.BooleanExpression;
import org.apache.activemq.filter.FilterException;
import org.apache.activemq.filter.MessageEvaluationContext;
+import org.apache.activemq.protobuf.AsciiBuffer;
/**
@@ -32,8 +34,8 @@
*/
public abstract class DestinationFilter implements BooleanExpression {
- public static final String ANY_DESCENDENT = ">";
- public static final String ANY_CHILD = "*";
+ public static final AsciiBuffer ANY_DESCENDENT = new AsciiBuffer(">");
+ public static final AsciiBuffer ANY_CHILD = new AsciiBuffer("*");
public boolean matches(MessageEvaluationContext message) throws FilterException {
Destination destination = message.getDestination();
@@ -50,15 +52,15 @@
if (destinations!=null) {
return new CompositeDestinationFilter(destination);
}
- String[] paths = DestinationPath.getDestinationPaths(destination);
- int idx = paths.length - 1;
+ ArrayList<AsciiBuffer> paths = DestinationPath.parse(destination);
+ int idx = paths.size() - 1;
if (idx >= 0) {
- String lastPath = paths[idx];
+ AsciiBuffer lastPath = paths.get(idx);
if (lastPath.equals(ANY_DESCENDENT)) {
return new PrefixDestinationFilter(paths);
} else {
while (idx >= 0) {
- lastPath = paths[idx--];
+ lastPath = paths.get(idx--);
if (lastPath.equals(ANY_CHILD)) {
return new WildcardDestinationFilter(paths);
}
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMap.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMap.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMap.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMap.java Fri Jun 19 13:26:52 2009
@@ -16,6 +16,7 @@
*/
package org.apache.activemq.apollo.broker.wildcard;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
@@ -24,6 +25,7 @@
import java.util.TreeSet;
import org.apache.activemq.apollo.broker.Destination;
+import org.apache.activemq.protobuf.AsciiBuffer;
/**
* A Map-like data structure allowing values to be indexed by
@@ -39,10 +41,10 @@
* @version $Revision: 1.3 $
*/
public class DestinationMap<Value> {
- protected static final String ANY_DESCENDENT = DestinationFilter.ANY_DESCENDENT;
- protected static final String ANY_CHILD = DestinationFilter.ANY_CHILD;
+ protected static final AsciiBuffer ANY_DESCENDENT = DestinationFilter.ANY_DESCENDENT;
+ protected static final AsciiBuffer ANY_CHILD = DestinationFilter.ANY_CHILD;
- private DestinationMapNode<Value> root = new DestinationMapNode<Value>(null);
+ private final DestinationMapNode<Value> root = new DestinationMapNode<Value>(null);
/**
* Looks up the value(s) matching the given Destination key. For simple
@@ -74,8 +76,8 @@
}
return;
}
- String[] paths = DestinationPath.getDestinationPaths(key);
- getRootNode(key).add(paths, 0, value);
+ ArrayList<AsciiBuffer> paths = DestinationPath.parse(key);
+ root.add(paths, 0, value);
}
/**
@@ -89,8 +91,8 @@
}
return;
}
- String[] paths = DestinationPath.getDestinationPaths(key);
- getRootNode(key).remove(paths, 0, value);
+ ArrayList<AsciiBuffer> paths = DestinationPath.parse(key);
+ root.remove(paths, 0, value);
}
@@ -113,9 +115,9 @@
}
protected Set<Value> findWildcardMatches(Destination key) {
- String[] paths = DestinationPath.getDestinationPaths(key);
+ ArrayList<AsciiBuffer> paths = DestinationPath.parse(key);
HashSet<Value> answer = new HashSet<Value>();
- getRootNode(key).appendMatchingValues(answer, paths, 0);
+ root.appendMatchingValues(answer, paths, 0);
return answer;
}
@@ -132,8 +134,8 @@
}
return rc;
}
- String[] paths = DestinationPath.getDestinationPaths(key);
- getRootNode(key).removeAll(rc, paths, 0);
+ ArrayList<AsciiBuffer> paths = DestinationPath.parse(key);
+ root.removeAll(rc, paths, 0);
return rc;
}
@@ -153,11 +155,4 @@
SortedSet<Value> sortedSet = new TreeSet<Value>(set);
return sortedSet.last();
}
-
- /**
- * Returns the root node for the given destination type
- */
- protected DestinationMapNode<Value> getRootNode(Destination key) {
- return root;
- }
}
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapNode.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapNode.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapNode.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapNode.java Fri Jun 19 13:26:52 2009
@@ -24,20 +24,22 @@
import java.util.Map;
import java.util.Set;
+import org.apache.activemq.protobuf.AsciiBuffer;
+
/**
* An implementation class used to implement {@link DestinationMap}
*
* @version $Revision: 1.2 $
*/
public class DestinationMapNode<Value> implements DestinationNode<Value> {
- protected static final String ANY_CHILD = DestinationMap.ANY_CHILD;
- protected static final String ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
+ protected static final AsciiBuffer ANY_CHILD = DestinationMap.ANY_CHILD;
+ protected static final AsciiBuffer ANY_DESCENDENT = DestinationMap.ANY_DESCENDENT;
// we synchornize at the DestinationMap level
private DestinationMapNode<Value> parent;
private List<Value> values = new ArrayList<Value>();
- private Map<String, DestinationNode<Value>> childNodes = new HashMap<String, DestinationNode<Value>>();
- private String path = "Root";
+ private Map<AsciiBuffer, DestinationNode<Value>> childNodes = new HashMap<AsciiBuffer, DestinationNode<Value>>();
+ private AsciiBuffer path = new AsciiBuffer("Root");
// private DestinationMapNode anyChild;
private int pathLength;
@@ -54,7 +56,7 @@
* Returns the child node for the given named path or null if it does not
* exist
*/
- public DestinationMapNode<Value> getChild(String path) {
+ public DestinationMapNode<Value> getChild(AsciiBuffer path) {
return (DestinationMapNode<Value>)childNodes.get(path);
}
@@ -73,12 +75,12 @@
* Returns the child node for the given named path, lazily creating one if
* it does not yet exist
*/
- public DestinationMapNode<Value> getChildOrCreate(String path) {
- DestinationMapNode<Value> answer = (DestinationMapNode<Value>)childNodes.get(path);
+ public DestinationMapNode<Value> getChildOrCreate(AsciiBuffer asciiBuffer) {
+ DestinationMapNode<Value> answer = (DestinationMapNode<Value>)childNodes.get(asciiBuffer);
if (answer == null) {
answer = createChildNode();
- answer.path = path;
- childNodes.put(path, answer);
+ answer.path = asciiBuffer;
+ childNodes.put(asciiBuffer, answer);
}
return answer;
}
@@ -132,41 +134,41 @@
return answer;
}
- public void add(String[] paths, int idx, Value value) {
- if (idx >= paths.length) {
+ public void add(ArrayList<AsciiBuffer> paths, int idx, Value value) {
+ if (idx >= paths.size()) {
values.add(value);
} else {
- // if (idx == paths.length - 1) {
+ // if (idx == paths.size() - 1) {
// getAnyChildNode().getValues().add(value);
// }
// else {
// getAnyChildNode().add(paths, idx + 1, value);
// }
- getChildOrCreate(paths[idx]).add(paths, idx + 1, value);
+ getChildOrCreate(paths.get(idx)).add(paths, idx + 1, value);
}
}
- public void remove(String[] paths, int idx, Value value) {
- if (idx >= paths.length) {
+ public void remove(ArrayList<AsciiBuffer> paths, int idx, Value value) {
+ if (idx >= paths.size()) {
values.remove(value);
pruneIfEmpty();
} else {
- // if (idx == paths.length - 1) {
+ // if (idx == paths.size() - 1) {
// getAnyChildNode().getValues().remove(value);
// }
// else {
// getAnyChildNode().remove(paths, idx + 1, value);
// }
- getChildOrCreate(paths[idx]).remove(paths, ++idx, value);
+ getChildOrCreate(paths.get(idx)).remove(paths, ++idx, value);
}
}
- public void removeAll(Set<Value> answer, String[] paths, int startIndex) {
+ public void removeAll(Set<Value> answer, ArrayList<AsciiBuffer> paths, int startIndex) {
DestinationNode<Value> node = this;
- int size = paths.length;
+ int size = paths.size();
for (int i = startIndex; i < size && node != null; i++) {
- String path = paths[i];
+ AsciiBuffer path = paths.get(i);
if (path.equals(ANY_DESCENDENT)) {
answer.addAll(node.removeDesendentValues());
break;
@@ -211,7 +213,7 @@
/**
* Matches any entries in the map containing wildcards
*/
- public void appendMatchingWildcards(Set<Value> answer, String[] paths, int idx) {
+ public void appendMatchingWildcards(Set<Value> answer, ArrayList<AsciiBuffer> paths, int idx) {
if (idx - 1 > pathLength) {
return;
}
@@ -225,12 +227,12 @@
}
}
- public void appendMatchingValues(Set<Value> answer, String[] paths, int startIndex) {
+ public void appendMatchingValues(Set<Value> answer, ArrayList<AsciiBuffer> paths, int startIndex) {
DestinationNode<Value> node = this;
boolean couldMatchAny = true;
- int size = paths.length;
+ int size = paths.size();
for (int i = startIndex; i < size && node != null; i++) {
- String path = paths[i];
+ AsciiBuffer path = paths.get(i);
if (path.equals(ANY_DESCENDENT)) {
answer.addAll(node.getDesendentValues());
couldMatchAny = false;
@@ -257,7 +259,7 @@
}
}
- public String getPath() {
+ public AsciiBuffer getPath() {
return path;
}
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationNode.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationNode.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationNode.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationNode.java Fri Jun 19 13:26:52 2009
@@ -16,24 +16,27 @@
*/
package org.apache.activemq.apollo.broker.wildcard;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Set;
+import org.apache.activemq.protobuf.AsciiBuffer;
+
/**
* Represents a node in the {@link DestinationMap} tree
*
* @version $Revision: 563921 $
*/
public interface DestinationNode<Value> {
- void appendMatchingValues(Set<Value> answer, String[] paths, int startIndex);
+ void appendMatchingValues(Set<Value> answer, ArrayList<AsciiBuffer> paths, int startIndex);
- void appendMatchingWildcards(Set<Value> answer, String[] paths, int startIndex);
+ void appendMatchingWildcards(Set<Value> answer, ArrayList<AsciiBuffer> paths, int startIndex);
void appendDescendantValues(Set<Value> answer);
Collection<Value> getDesendentValues();
- DestinationNode<Value> getChild(String path);
+ DestinationNode<Value> getChild(AsciiBuffer path);
Collection<Value> getValues();
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationPath.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationPath.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationPath.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/DestinationPath.java Fri Jun 19 13:26:52 2009
@@ -18,9 +18,9 @@
package org.apache.activemq.apollo.broker.wildcard;
import java.util.ArrayList;
-import java.util.List;
import org.apache.activemq.apollo.broker.Destination;
+import org.apache.activemq.protobuf.AsciiBuffer;
/**
* Helper class for decomposing a Destination into a number of paths
@@ -28,32 +28,32 @@
* @version $Revision: 1.3 $
*/
public final class DestinationPath {
- protected static final char SEPARATOR = '.';
+ protected static final byte SEPARATOR = '.';
private DestinationPath() {
}
- public static String[] getDestinationPaths(String subject) {
- List<String> list = new ArrayList<String>();
+ public static ArrayList<AsciiBuffer> parse(AsciiBuffer domain, AsciiBuffer subject) {
+ ArrayList<AsciiBuffer> list = new ArrayList<AsciiBuffer>(10);
+ list.add(domain);
int previous = 0;
- int lastIndex = subject.length() - 1;
+ int lastIndex = subject.getLength() - 1;
while (true) {
int idx = subject.indexOf(SEPARATOR, previous);
if (idx < 0) {
- list.add(subject.substring(previous, lastIndex + 1));
+ AsciiBuffer buffer = subject.slice(previous, lastIndex + 1);
+ list.add(buffer);
break;
}
- list.add(subject.substring(previous, idx));
+ AsciiBuffer buffer = subject.slice(previous, idx);
+ list.add(buffer);
previous = idx + 1;
}
- String[] answer = new String[list.size()];
- list.toArray(answer);
- return answer;
+ return list;
}
- public static String[] getDestinationPaths(Destination destination) {
- // TODO: avoid converting to string..
- return getDestinationPaths(destination.getName().toString());
+ public static ArrayList<AsciiBuffer> parse(Destination destination) {
+ return parse(destination.getDomain(), destination.getName());
}
/**
@@ -62,13 +62,13 @@
* @param paths
* @return
*/
- public static String toString(String[] paths) {
+ public static String toString(ArrayList<AsciiBuffer> paths) {
StringBuffer buffer = new StringBuffer();
- for (int i = 0; i < paths.length; i++) {
+ for (int i = 0; i < paths.size(); i++) {
if (i > 0) {
buffer.append(SEPARATOR);
}
- String path = paths[i];
+ AsciiBuffer path = paths.get(i);
if (path == null) {
buffer.append("*");
} else {
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/PrefixDestinationFilter.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/PrefixDestinationFilter.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/PrefixDestinationFilter.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/PrefixDestinationFilter.java Fri Jun 19 13:26:52 2009
@@ -17,7 +17,10 @@
package org.apache.activemq.apollo.broker.wildcard;
+import java.util.ArrayList;
+
import org.apache.activemq.apollo.broker.Destination;
+import org.apache.activemq.protobuf.AsciiBuffer;
/**
@@ -27,24 +30,24 @@
*/
public class PrefixDestinationFilter extends DestinationFilter {
- private String[] prefixes;
+ private ArrayList<AsciiBuffer> prefixes;
/**
* An array of paths, the last path is '>'
*
- * @param prefixes
+ * @param paths
*/
- public PrefixDestinationFilter(String[] prefixes) {
- this.prefixes = prefixes;
+ public PrefixDestinationFilter(ArrayList<AsciiBuffer> paths) {
+ this.prefixes = paths;
}
public boolean matches(Destination destination) {
- String[] path = DestinationPath.getDestinationPaths(destination);
- int length = prefixes.length;
- if (path.length >= length) {
+ ArrayList<AsciiBuffer> path = DestinationPath.parse(destination);
+ int length = prefixes.size();
+ if (path.size() >= length) {
int size = length - 1;
for (int i = 0; i < size; i++) {
- if (!prefixes[i].equals(path[i])) {
+ if (!prefixes.get(i).equals(path.get(i))) {
return false;
}
}
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/WildcardDestinationFilter.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/WildcardDestinationFilter.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/WildcardDestinationFilter.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/main/java/org/apache/activemq/apollo/broker/wildcard/WildcardDestinationFilter.java Fri Jun 19 13:26:52 2009
@@ -17,7 +17,10 @@
package org.apache.activemq.apollo.broker.wildcard;
+import java.util.ArrayList;
+
import org.apache.activemq.apollo.broker.Destination;
+import org.apache.activemq.protobuf.AsciiBuffer;
@@ -28,30 +31,30 @@
*/
public class WildcardDestinationFilter extends DestinationFilter {
- private String[] prefixes;
+ private AsciiBuffer[] prefixes;
/**
* An array of paths containing * characters
*
- * @param prefixes
+ * @param paths
*/
- public WildcardDestinationFilter(String[] prefixes) {
- this.prefixes = new String[prefixes.length];
- for (int i = 0; i < prefixes.length; i++) {
- String prefix = prefixes[i];
- if (!prefix.equals("*")) {
+ public WildcardDestinationFilter(ArrayList<AsciiBuffer> paths) {
+ this.prefixes = new AsciiBuffer[paths.size()];
+ for (int i = 0; i < paths.size(); i++) {
+ AsciiBuffer prefix = paths.get(i);
+ if (!prefix.equals(DestinationFilter.ANY_CHILD)) {
this.prefixes[i] = prefix;
}
}
}
public boolean matches(Destination destination) {
- String[] path = DestinationPath.getDestinationPaths(destination);
+ ArrayList<AsciiBuffer> path = DestinationPath.parse(destination);
int length = prefixes.length;
- if (path.length == length) {
+ if (path.size() == length) {
for (int i = 0; i < length; i++) {
- String prefix = prefixes[i];
- if (prefix != null && !prefix.equals(path[i])) {
+ AsciiBuffer prefix = prefixes[i];
+ if (prefix != null && !prefix.equals(path.get(i))) {
return false;
}
}
@@ -62,7 +65,9 @@
public String getText() {
- return DestinationPath.toString(prefixes);
+ ArrayList<AsciiBuffer> t = new ArrayList<AsciiBuffer>(prefixes.length);
+ t.toArray(prefixes);
+ return DestinationPath.toString(t);
}
public String toString() {
Modified: activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapTest.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapTest.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapTest.java (original)
+++ activemq/sandbox/activemq-flow/activemq-broker/src/test/java/org/apache/activemq/apollo/broker/wildcard/DestinationMapTest.java Fri Jun 19 13:26:52 2009
@@ -27,7 +27,6 @@
import org.apache.activemq.apollo.broker.Destination;
import org.apache.activemq.apollo.broker.Router;
-import org.apache.activemq.apollo.broker.wildcard.DestinationMap;
import org.apache.activemq.protobuf.AsciiBuffer;
public class DestinationMapTest extends TestCase {
@@ -46,6 +45,17 @@
protected String v5 = "value5";
protected String v6 = "value6";
+ public void testQueueAndTopicWithSameName() throws Exception {
+ Destination q1 = new Destination.SingleDestination(Router.QUEUE_DOMAIN, new AsciiBuffer("foo"));
+ Destination t1 = new Destination.SingleDestination(Router.TOPIC_DOMAIN, new AsciiBuffer("foo"));
+
+ map.put(q1, v1);
+ map.put(t1, v2);
+
+ assertMapValue(q1, v1);
+ assertMapValue(t1, v2);
+ }
+
public void testCompositeDestinations() throws Exception {
Destination d1 = createDestination("TEST.BAR.D2");
Destination d2 = createDestination("TEST.BAR.D3");
Modified: activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/AsciiBuffer.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/AsciiBuffer.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/AsciiBuffer.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/AsciiBuffer.java Fri Jun 19 13:26:52 2009
@@ -30,6 +30,11 @@
return this;
}
+ @Override
+ protected AsciiBuffer createBuffer(byte[] data, int offset, int length) {
+ return new AsciiBuffer(data, offset, length);
+ }
+
public String toString()
{
if( value == null ) {
Modified: activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/Buffer.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/Buffer.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/Buffer.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/Buffer.java Fri Jun 19 13:26:52 2009
@@ -44,7 +44,8 @@
this(UTF8Buffer.encode(value));
}
- public final Buffer slice(int low, int high) {
+ @SuppressWarnings("unchecked")
+ public final <T extends Buffer> T slice(int low, int high) {
int sz;
if (high < 0) {
@@ -57,10 +58,14 @@
sz = 0;
}
- return new Buffer(data, offset + low, sz);
+ return (T) createBuffer(data, offset + low, sz);
}
- public final byte[] getData() {
+ protected Buffer createBuffer(byte[] data, int offset, int length) {
+ return new Buffer(data, offset, length);
+ }
+
+ public final byte[] getData() {
return data;
}
Modified: activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/UTF8Buffer.java
URL: http://svn.apache.org/viewvc/activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/UTF8Buffer.java?rev=786503&r1=786502&r2=786503&view=diff
==============================================================================
--- activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/UTF8Buffer.java (original)
+++ activemq/sandbox/activemq-flow/activemq-util/src/main/java/org/apache/activemq/protobuf/UTF8Buffer.java Fri Jun 19 13:26:52 2009
@@ -30,6 +30,11 @@
return this;
}
+ @Override
+ protected UTF8Buffer createBuffer(byte[] data, int offset, int length) {
+ return new UTF8Buffer(data, offset, length);
+ }
+
public String toString()
{
if( value==null ) {