jbertram commented on code in PR #4421:
URL: https://github.com/apache/activemq-artemis/pull/4421#discussion_r1161864711


##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java:
##########
@@ -1742,49 +1743,80 @@ public Transaction getCurrentTransaction() {
       return tx;
    }
 
-
    @Override
-   public boolean checkAutoCreate(SimpleString address, RoutingType 
routingType) throws Exception {
-      boolean result;
-      SimpleString unPrefixedAddress = removePrefix(address);
+   public AutoCreateResult checkAutoCreate(QueueConfiguration queueConfig) 
throws Exception {
+      AutoCreateResult result;
+      SimpleString unPrefixedAddress = removePrefix(queueConfig.getAddress());
       AddressSettings addressSettings =  
server.getAddressSettingsRepository().getMatch(unPrefixedAddress.toString());
 
-      if (routingType == RoutingType.MULTICAST) {
-         if (server.getAddressInfo(unPrefixedAddress) == null) {
-            if (addressSettings.isAutoCreateAddresses()) {
+      /*
+       *
+       */
+      if (queueConfig.getRoutingType() == null) {
+         return AutoCreateResult.EXISTED;
+      }

Review Comment:
   I added a comment.



##########
artemis-server/src/main/java/org/apache/activemq/artemis/core/server/impl/ServerSessionImpl.java:
##########
@@ -1742,49 +1743,80 @@ public Transaction getCurrentTransaction() {
       return tx;
    }
 
-
    @Override
-   public boolean checkAutoCreate(SimpleString address, RoutingType 
routingType) throws Exception {
-      boolean result;
-      SimpleString unPrefixedAddress = removePrefix(address);
+   public AutoCreateResult checkAutoCreate(QueueConfiguration queueConfig) 
throws Exception {
+      AutoCreateResult result;
+      SimpleString unPrefixedAddress = removePrefix(queueConfig.getAddress());
       AddressSettings addressSettings =  
server.getAddressSettingsRepository().getMatch(unPrefixedAddress.toString());
 
-      if (routingType == RoutingType.MULTICAST) {
-         if (server.getAddressInfo(unPrefixedAddress) == null) {
-            if (addressSettings.isAutoCreateAddresses()) {
+      /*
+       *
+       */
+      if (queueConfig.getRoutingType() == null) {
+         return AutoCreateResult.EXISTED;
+      }
+
+      // No matter what routingType is used the address must exist already or 
be automatically created
+      AddressInfo addressInfo = server.getAddressInfo(unPrefixedAddress);
+      if (addressInfo == null) {
+         // the address doesn't exist
+         if (addressSettings.isAutoCreateAddresses() || 
queueConfig.isTemporary()) {
+            // try to create the address if possible
+            try {
+               createAddress(queueConfig.getAddress(), 
queueConfig.getRoutingType(), true).setTemporary(queueConfig.isTemporary());
+            } catch (ActiveMQAddressExistsException e) {
+               // The address may have been created by another thread in the 
mean time.  Catch and do nothing.
+            }
+            result = AutoCreateResult.CREATED;
+         } else {
+            // if the address doesn't exist and can't be autocreated then 
return false immediately
+            return AutoCreateResult.NOT_FOUND;
+         }
+      } else {
+         // the address exists
+         if 
(addressInfo.getRoutingTypes().contains(queueConfig.getRoutingType())) {
+            // the existing address supports the requested routingType
+            result = AutoCreateResult.EXISTED;
+         } else {
+            // the existing address doesn't support the requested routingType
+            if (addressSettings.isAutoCreateAddresses() || 
queueConfig.isTemporary()) {
+               // try to update the address with the new routingType if 
possible
                try {
-                  createAddress(address, routingType, true);
+                  
createAddress(addressInfo.addRoutingType(queueConfig.getRoutingType()), true);
                } catch (ActiveMQAddressExistsException e) {
                   // The address may have been created by another thread in 
the mean time.  Catch and do nothing.
                }
-               result = true;
+               result = AutoCreateResult.UPDATED;
             } else {
-               result = false;
+               // if the address exists but doesn't support the requested 
routingType and can't be updated with the new routingType then return false 
immediately

Review Comment:
   Fixed.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to