Author: dejanb
Date: Thu Aug 20 10:13:38 2009
New Revision: 806105
URL: http://svn.apache.org/viewvc?rev=806105&view=rev
Log:
fix for https://issues.apache.org/activemq/browse/AMQ-2360 - destination
filters and destination types
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java?rev=806105&r1=806104&r2=806105&view=diff
==============================================================================
---
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java
(original)
+++
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/DestinationFilter.java
Thu Aug 20 10:13:38 2009
@@ -60,12 +60,12 @@
if (idx >= 0) {
String lastPath = paths[idx];
if (lastPath.equals(ANY_DESCENDENT)) {
- return new PrefixDestinationFilter(paths);
+ return new PrefixDestinationFilter(paths,
destination.getDestinationType());
} else {
while (idx >= 0) {
lastPath = paths[idx--];
if (lastPath.equals(ANY_CHILD)) {
- return new WildcardDestinationFilter(paths);
+ return new WildcardDestinationFilter(paths,
destination.getDestinationType());
}
}
}
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java?rev=806105&r1=806104&r2=806105&view=diff
==============================================================================
---
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
(original)
+++
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/PrefixDestinationFilter.java
Thu Aug 20 10:13:38 2009
@@ -28,17 +28,20 @@
public class PrefixDestinationFilter extends DestinationFilter {
private String[] prefixes;
+ private byte destinationType;
/**
* An array of paths, the last path is '>'
*
* @param prefixes
*/
- public PrefixDestinationFilter(String[] prefixes) {
+ public PrefixDestinationFilter(String[] prefixes, byte destinationType) {
this.prefixes = prefixes;
+ this.destinationType = destinationType;
}
public boolean matches(ActiveMQDestination destination) {
+ if (destination.getDestinationType() != destinationType) return false;
String[] path =
DestinationPath.getDestinationPaths(destination.getPhysicalName());
int length = prefixes.length;
if (path.length >= length) {
Modified:
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java?rev=806105&r1=806104&r2=806105&view=diff
==============================================================================
---
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java
(original)
+++
activemq/trunk/activemq-core/src/main/java/org/apache/activemq/filter/WildcardDestinationFilter.java
Thu Aug 20 10:13:38 2009
@@ -28,13 +28,14 @@
public class WildcardDestinationFilter extends DestinationFilter {
private String[] prefixes;
+ private byte destinationType;
/**
* An array of paths containing * characters
*
* @param prefixes
*/
- public WildcardDestinationFilter(String[] prefixes) {
+ public WildcardDestinationFilter(String[] prefixes, byte destinationType) {
this.prefixes = new String[prefixes.length];
for (int i = 0; i < prefixes.length; i++) {
String prefix = prefixes[i];
@@ -42,9 +43,11 @@
this.prefixes[i] = prefix;
}
}
+ this.destinationType = destinationType;
}
public boolean matches(ActiveMQDestination destination) {
+ if (destination.getDestinationType() != destinationType) return false;
String[] path = DestinationPath.getDestinationPaths(destination);
int length = prefixes.length;
if (path.length == length) {
Added:
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
URL:
http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java?rev=806105&view=auto
==============================================================================
---
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
(added)
+++
activemq/trunk/activemq-core/src/test/java/org/apache/activemq/filter/DestinationFilterTest.java
Thu Aug 20 10:13:38 2009
@@ -0,0 +1,44 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.filter;
+
+import org.apache.activemq.command.ActiveMQQueue;
+import org.apache.activemq.command.ActiveMQTopic;
+
+import junit.framework.TestCase;
+
+public class DestinationFilterTest extends TestCase {
+
+ public void testPrefixFilter() throws Exception {
+ DestinationFilter filter = DestinationFilter.parseFilter(new
ActiveMQQueue(">"));
+ assertTrue("Filter not parsed well: " + filter.getClass(),
filter instanceof PrefixDestinationFilter);
+ System.out.println(filter);
+ assertFalse("Filter matched wrong destination type",
filter.matches(new ActiveMQTopic(">")));
+ }
+
+ public void testWildcardFilter() throws Exception {
+ DestinationFilter filter = DestinationFilter.parseFilter(new
ActiveMQQueue("A.*"));
+ assertTrue("Filter not parsed well: " + filter.getClass(),
filter instanceof WildcardDestinationFilter);
+ assertFalse("Filter matched wrong destination type",
filter.matches(new ActiveMQTopic("A.B")));
+ }
+
+ public void testCompositeFilter() throws Exception {
+ DestinationFilter filter = DestinationFilter.parseFilter(new
ActiveMQQueue("A.B,B.C"));
+ assertTrue("Filter not parsed well: " + filter.getClass(),
filter instanceof CompositeDestinationFilter);
+ assertFalse("Filter matched wrong destination type",
filter.matches(new ActiveMQTopic("A.B")));
+ }
+}