activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r365883 - in /incubator/activemq/trunk/activemq-core/src: main/java/org/apache/activemq/broker/region/policy/ main/java/org/apache/activemq/command/ test/java/org/apache/activemq/command/
Date Wed, 04 Jan 2006 10:31:24 GMT
Author: jstrachan
Date: Wed Jan  4 02:31:15 2006
New Revision: 365883

URL: http://svn.apache.org/viewcvs?rev=365883&view=rev
Log:
make destinations sortable

Modified:
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
    incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
    incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java?rev=365883&r1=365882&r2=365883&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/broker/region/policy/PolicyEntry.java
Wed Jan  4 02:31:15 2006
@@ -18,7 +18,6 @@
 
 import org.apache.activemq.broker.region.Queue;
 import org.apache.activemq.broker.region.Topic;
-import org.apache.activemq.command.RedeliveryPolicy;
 import org.apache.activemq.filter.DestinationMapEntry;
 
 /**
@@ -33,9 +32,8 @@
 
     private DispatchPolicy dispatchPolicy;
     private SubscriptionRecoveryPolicy subscriptionRecoveryPolicy;
-    private RedeliveryPolicy redeliveryPolicy;
     private boolean sendAdvisoryIfNoConsumers;
-    private DeadLetterStrategy deadLetterStrategy = new SharedDeadLetterStrategy();
+    private DeadLetterStrategy deadLetterStrategy;
 
     public void configure(Queue queue) {
         if (dispatchPolicy != null) {
@@ -67,14 +65,6 @@
 
     public void setDispatchPolicy(DispatchPolicy policy) {
         this.dispatchPolicy = policy;
-    }
-
-    public RedeliveryPolicy getRedeliveryPolicy() {
-        return redeliveryPolicy;
-    }
-
-    public void setRedeliveryPolicy(RedeliveryPolicy redeliveryPolicy) {
-        this.redeliveryPolicy = redeliveryPolicy;
     }
 
     public SubscriptionRecoveryPolicy getSubscriptionRecoveryPolicy() {

Modified: incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java?rev=365883&r1=365882&r2=365883&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQDestination.java
Wed Jan  4 02:31:15 2006
@@ -39,7 +39,7 @@
  * @openwire:marshaller
  * @version $Revision: 1.10 $
  */
-abstract public class ActiveMQDestination implements DataStructure, Destination, Externalizable
{
+abstract public class ActiveMQDestination implements DataStructure, Destination, Externalizable,
Comparable {
 
     private static final long serialVersionUID = -3885260014960795889L;
 
@@ -65,6 +65,72 @@
     transient protected int hashValue;
     protected Map options;
 
+    
+    // static helper methods for working with destinations
+    // -------------------------------------------------------------------------
+    static public ActiveMQDestination createDestination(String name, byte defaultType) {
+        
+        if( name.startsWith(QUEUE_QUALIFIED_PREFIX) ) {
+            return new ActiveMQQueue(name.substring(QUEUE_QUALIFIED_PREFIX.length()));
+        } else if( name.startsWith(TOPIC_QUALIFIED_PREFIX) ) {            
+            return new ActiveMQTopic(name.substring(TOPIC_QUALIFIED_PREFIX.length()));
+        } else if( name.startsWith(TEMP_QUEUE_QUALIFED_PREFIX) ) {            
+            return new ActiveMQTempQueue(name.substring(TEMP_QUEUE_QUALIFED_PREFIX.length()));
+        } else if( name.startsWith(TEMP_TOPIC_QUALIFED_PREFIX) ) {            
+            return new ActiveMQTempTopic(name.substring(TEMP_TOPIC_QUALIFED_PREFIX.length()));
+        }
+        
+        switch(defaultType) {
+        case QUEUE_TYPE:
+            return new ActiveMQQueue(name);
+        case TOPIC_TYPE:
+            return new ActiveMQTopic(name);
+        case TEMP_QUEUE_TYPE:
+            return new ActiveMQTempQueue(name);
+        case TEMP_TOPIC_TYPE:
+            return new ActiveMQTempTopic(name);
+        default:
+            throw new IllegalArgumentException("Invalid default destination type: "+defaultType);
+        }
+    }
+    
+    public static ActiveMQDestination transform(Destination dest) throws JMSException {
+        if( dest == null )
+            return null;
+        if( dest instanceof ActiveMQDestination )
+            return (ActiveMQDestination) dest;
+        if( dest instanceof TemporaryQueue )
+            return new ActiveMQTempQueue(((TemporaryQueue)dest).getQueueName());
+        if( dest instanceof TemporaryTopic )
+            return new ActiveMQTempTopic(((TemporaryTopic)dest).getTopicName());
+        if( dest instanceof Queue )
+            return new ActiveMQQueue(((Queue)dest).getQueueName());
+        if( dest instanceof Topic )
+            return new ActiveMQTopic(((Topic)dest).getTopicName());
+        throw new JMSException("Could not transform the destination into a ActiveMQ destination:
"+dest);
+    }
+
+    public static int compare(ActiveMQDestination destination, ActiveMQDestination destination2)
{
+        if (destination == destination2) {
+            return 0;
+        }
+        if (destination == null) {
+            return -1;
+        }
+        else if (destination2 == null) {
+            return 1;
+        }
+        else {
+            if (destination.isQueue() == destination2.isQueue()) {
+                return destination.getPhysicalName().compareTo(destination2.getPhysicalName());
+            }
+            else {
+                return destination.isQueue() ? -1 : 1;
+            }
+        }
+    }
+
+    
     public ActiveMQDestination() {
     }
     
@@ -76,6 +142,18 @@
         setCompositeDestinations(composites);
     }
 
+    public int compareTo(Object that) {
+        if (that instanceof ActiveMQDestination) {
+            return compare(this, (ActiveMQDestination) that);
+        }
+        if (that == null) {
+            return 1;
+        }
+        else {
+            return getClass().getName().compareTo(that.getClass().getName());
+        }
+    }
+
     public boolean isComposite() {
         return compositeDestinations!=null;
     }
@@ -166,33 +244,6 @@
     public ActiveMQDestination createDestination(String name) {
         return createDestination(name, getDestinationType());
     }
-    
-    static public ActiveMQDestination createDestination(String name, byte defaultType) {
-        
-        if( name.startsWith(QUEUE_QUALIFIED_PREFIX) ) {
-            return new ActiveMQQueue(name.substring(QUEUE_QUALIFIED_PREFIX.length()));
-        } else if( name.startsWith(TOPIC_QUALIFIED_PREFIX) ) {            
-            return new ActiveMQTopic(name.substring(TOPIC_QUALIFIED_PREFIX.length()));
-        } else if( name.startsWith(TEMP_QUEUE_QUALIFED_PREFIX) ) {            
-            return new ActiveMQTempQueue(name.substring(TEMP_QUEUE_QUALIFED_PREFIX.length()));
-        } else if( name.startsWith(TEMP_TOPIC_QUALIFED_PREFIX) ) {            
-            return new ActiveMQTempTopic(name.substring(TEMP_TOPIC_QUALIFED_PREFIX.length()));
-        }
-        
-        switch(defaultType) {
-        case QUEUE_TYPE:
-            return new ActiveMQQueue(name);
-        case TOPIC_TYPE:
-            return new ActiveMQTopic(name);
-        case TEMP_QUEUE_TYPE:
-            return new ActiveMQTempQueue(name);
-        case TEMP_TOPIC_TYPE:
-            return new ActiveMQTempTopic(name);
-        default:
-            throw new IllegalArgumentException("Invalid default destination type: "+defaultType);
-        }
-    }
-    
     public String[] getDestinationPaths() {  
         
         if( destinationPaths!=null )
@@ -242,23 +293,6 @@
         }
         return hashValue;
     }
-
-    public static ActiveMQDestination transform(Destination dest) throws JMSException {
-        if( dest == null )
-            return null;
-        if( dest instanceof ActiveMQDestination )
-            return (ActiveMQDestination) dest;
-        if( dest instanceof TemporaryQueue )
-            return new ActiveMQTempQueue(((TemporaryQueue)dest).getQueueName());
-        if( dest instanceof TemporaryTopic )
-            return new ActiveMQTempTopic(((TemporaryTopic)dest).getTopicName());
-        if( dest instanceof Queue )
-            return new ActiveMQQueue(((Queue)dest).getQueueName());
-        if( dest instanceof Topic )
-            return new ActiveMQTopic(((Topic)dest).getTopicName());
-        throw new JMSException("Could not transform the destination into a ActiveMQ destination:
"+dest);
-    }
-    
     public String toString() {
         return getQualifiedName();
     }

Modified: incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java
URL: http://svn.apache.org/viewcvs/incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java?rev=365883&r1=365882&r2=365883&view=diff
==============================================================================
--- incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java
(original)
+++ incubator/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQDestinationTest.java
Wed Jan  4 02:31:15 2006
@@ -17,7 +17,13 @@
 package org.apache.activemq.command;
 
 import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
 import java.util.Map;
+import java.util.SortedSet;
+import java.util.TreeMap;
+import java.util.TreeSet;
 
 import org.apache.activemq.command.ActiveMQDestination;
 import org.apache.activemq.command.ActiveMQQueue;
@@ -62,6 +68,15 @@
         assertNotNull(options);
         assertEquals("v1", options.get("k1"));
         assertEquals("v2", options.get("k2"));
+    }
+    
+    public void testSorting() throws Exception {
+        SortedSet set = new TreeSet();
+        ActiveMQDestination[] destinations = { new ActiveMQQueue("A"), new ActiveMQQueue("B"),
new ActiveMQTopic("A"), new ActiveMQTopic("B") };
+        List expected = Arrays.asList(destinations);
+        set.addAll(expected);
+        List actual = new ArrayList(set);
+        assertEquals("Sorted order", expected, actual);
     }
 
     public static Test suite() {



Mime
View raw message