QPID-8141: [JMS AMQP 0-x] Return resolved destination from Session#createQueue/Sessio...
authorAlex Rudyy <orudyy@apache.org>
Tue, 1 May 2018 10:55:10 +0000 (11:55 +0100)
committerAlex Rudyy <orudyy@apache.org>
Tue, 1 May 2018 11:05:06 +0000 (12:05 +0100)
client/src/main/java/org/apache/qpid/client/AMQSession.java

index cba764e..8d10dd9 100644 (file)
@@ -676,32 +676,39 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
 
     boolean isResolved(final AMQDestination dest)
     {
-        if (!_resolvedDestinations.contains(dest))
-        {
-            return false;
-        }
+        return _resolvedDestinations.contains(dest);
+    }
 
-        if (dest.getAddressType() == AMQDestination.QUEUE_TYPE)
+    private <T extends AMQDestination> T getResolvedOfSameClassOrRemoveResolved(final T destination, Class<T> destinationClass)
+    {
+        if (isResolved(destination))
         {
-            // verify legacy fields are set
-            return dest.getQueueName() != null
-                   && dest.getQueueName().equals(dest.getAddressName())
-                   && dest.getExchangeName() != null
-                   && dest.getExchangeClass() != null
-                   && dest.getRoutingKey() != null;
+            AMQDestination resolved = getResolved(destination);
+            if (resolved != null && destinationClass.isInstance(resolved))
+            {
+                return (T) resolved;
+            }
+            else
+            {
+                setUnresolved(destination);
+            }
         }
-        else if (dest.getAddressType() == AMQDestination.TOPIC_TYPE)
+        return destination;
+    }
+
+    private AMQDestination getResolved(AMQDestination destination)
+    {
+        for(AMQDestination resolved : _resolvedDestinations)
         {
-            // verify legacy fields are set
-            return dest.getExchangeName() != null
-                   && dest.getExchangeName().equals(dest.getAddressName())
-                   && dest.getExchangeClass() != null
-                   && (dest.getSubject() == null
-                        || (dest.getSubject() != null && dest.getSubject().equals(dest.getRoutingKey())));
+            if (resolved.equals(destination))
+            {
+                return resolved;
+            }
         }
-        return false;
+        return null;
     }
 
+
     public abstract int resolveAddressType(AMQDestination dest) throws QpidException;
 
     protected abstract void acknowledgeImpl() throws JMSException;
@@ -1336,14 +1343,13 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
                 }
                 else
                 {
-                    AMQQueue queue = new AMQQueue(queueName);
-                    return queue;
+                    return getResolvedOfSameClassOrRemoveResolved(new AMQQueue(queueName), AMQQueue.class);
 
                 }
             }
             else
             {
-                return new AMQQueue(queueName);
+                return getResolvedOfSameClassOrRemoveResolved(new AMQQueue(queueName), AMQQueue.class);
             }
         }
         catch (URISyntaxException urlse)
@@ -1641,12 +1647,13 @@ public abstract class AMQSession<C extends BasicMessageConsumer, P extends Basic
                 }
                 else
                 {
-                    return new AMQTopic("ADDR:" + getDefaultTopicExchangeName() + "/" + topicName);
+                    AMQTopic topic = new AMQTopic("ADDR:" + getDefaultTopicExchangeName() + "/" + topicName);
+                    return getResolvedOfSameClassOrRemoveResolved(topic, AMQTopic.class);
                 }
             }
             else
             {
-                return new AMQTopic(topicName);
+                return getResolvedOfSameClassOrRemoveResolved(new AMQTopic(topicName), AMQTopic.class);
             }
 
         }