You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@activemq.apache.org by cl...@apache.org on 2016/11/07 16:37:10 UTC

[50/50] [abbrv] activemq-artemis git commit: Fix AutoCreateTopics

Fix AutoCreateTopics


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/661ea2c4
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/661ea2c4
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/661ea2c4

Branch: refs/heads/ARTEMIS-780
Commit: 661ea2c4e695442d6229478824f381dcaed17a3f
Parents: ae40a3d
Author: Martyn Taylor <mt...@redhat.com>
Authored: Mon Nov 7 16:00:58 2016 +0000
Committer: Clebert Suconic <cl...@apache.org>
Committed: Mon Nov 7 11:29:54 2016 -0500

----------------------------------------------------------------------
 .../artemis/jms/client/ActiveMQSession.java     | 32 ++++++++++++++------
 .../artemis/core/server/ActiveMQServer.java     |  2 ++
 .../core/server/impl/ActiveMQServerImpl.java    | 27 +++++++++++------
 3 files changed, 42 insertions(+), 19 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/661ea2c4/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
----------------------------------------------------------------------
diff --git a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
index d40ca21..d554cf8 100644
--- a/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
+++ b/artemis-jms-client/src/main/java/org/apache/activemq/artemis/jms/client/ActiveMQSession.java
@@ -299,19 +299,31 @@ public class ActiveMQSession implements QueueSession, TopicSession {
          if (jbd != null) {
             ClientSession.AddressQuery response = session.addressQuery(jbd.getSimpleAddress());
 
-            if (!response.isExists() && response.isAutoCreateJmsQueues()) {
-               if (jbd.isQueue()) {
-                  session.createAddress(jbd.getSimpleAddress(), false);
-                  session.createQueue(jbd.getSimpleAddress(), jbd.getSimpleAddress(), null, true);
-               } else {
-                  session.createAddress(jbd.getSimpleAddress(), true);
+            if (jbd.isQueue()) {
+               if (!response.isExists()) {
+                  if (response.isAutoCreateJmsQueues()) {
+                     session.createAddress(jbd.getSimpleAddress(), false);
+                  } else {
+                     throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
+                  }
                }
 
-            } else if (!response.isExists() && !response.isAutoCreateJmsQueues()) {
-               throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
+               if (response.getQueueNames().isEmpty()) {
+                  if (response.isAutoCreateJmsQueues()) {
+                     session.createQueue(jbd.getSimpleAddress(), jbd.getSimpleAddress(), null, true);
+                  } else {
+                     throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
+                  }
+               }
+            } else {
+               if (!response.isExists()) {
+                  if (response.isAutoCreateJmsTopics()) {
+                     session.createAddress(jbd.getSimpleAddress(), true);
+                  } else {
+                     throw new InvalidDestinationException("Destination " + jbd.getName() + " does not exist");
+                  }
+               }
             }
-
-            connection.addKnownDestination(jbd.getSimpleAddress());
          }
 
          ClientProducer producer = session.createProducer(jbd == null ? null : jbd.getSimpleAddress());

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/661ea2c4/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
index bb819ae..09f679b 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/ActiveMQServer.java
@@ -465,6 +465,8 @@ public interface ActiveMQServer extends ActiveMQComponent {
 
    void removeClientConnection(String clientId);
 
+   AddressInfo putAddressInfoIfAbsent(AddressInfo addressInfo) throws Exception;
+
    AddressInfo createOrUpdateAddressInfo(AddressInfo addressInfo) throws Exception;
 
    AddressInfo removeAddressInfo(SimpleString address) throws Exception;

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/661ea2c4/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
index 58d8ff2..df00cc1 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ActiveMQServerImpl.java
@@ -653,7 +653,11 @@ public class ActiveMQServerImpl implements ActiveMQServer {
          }
       }
 
-      return new BindingQueryResult(!names.isEmpty(), names, autoCreateJmsQueues, autoCreateJmsTopics);
+      if (autoCreateJmsTopics) {
+         putAddressInfoIfAbsent(new AddressInfo(address));
+      }
+
+      return new BindingQueryResult(getAddressInfo(address) != null, names, autoCreateJmsQueues, autoCreateJmsTopics);
    }
 
    @Override
@@ -2153,14 +2157,7 @@ public class ActiveMQServerImpl implements ActiveMQServer {
 
    private void deployQueuesFromListCoreQueueConfiguration(List<CoreQueueConfiguration> queues) throws Exception {
       for (CoreQueueConfiguration config : queues) {
-         deployQueue(SimpleString.toSimpleString(config.getAddress()),
-                     SimpleString.toSimpleString(config.getName()),
-                     SimpleString.toSimpleString(config.getFilterString()),
-                     config.isDurable(),
-                     false,
-                     false,
-                     config.getMaxConsumers(),
-                     config.getDeleteOnNoConsumers());
+         deployQueue(SimpleString.toSimpleString(config.getAddress()), SimpleString.toSimpleString(config.getName()), SimpleString.toSimpleString(config.getFilterString()), config.isDurable(), false, false, config.getMaxConsumers(), config.getDeleteOnNoConsumers());
       }
    }
 
@@ -2264,6 +2261,18 @@ public class ActiveMQServerImpl implements ActiveMQServer {
    }
 
    @Override
+   public AddressInfo putAddressInfoIfAbsent(AddressInfo addressInfo) throws Exception {
+      AddressInfo result = postOffice.addAddressInfo(addressInfo);
+
+      // TODO: is this the right way to do this?
+      long txID = storageManager.generateID();
+      storageManager.addAddressBinding(txID, addressInfo);
+      storageManager.commitBindings(txID);
+
+      return result;
+   }
+
+   @Override
    public AddressInfo createOrUpdateAddressInfo(AddressInfo addressInfo) throws Exception {
       AddressInfo result = postOffice.addOrUpdateAddressInfo(addressInfo);