Skip to content

Commit

Permalink
ARTEMIS-2072 refactor logic to fix tests
Browse files Browse the repository at this point in the history
(cherry picked from commit 24fa0f9)
  • Loading branch information
jbertram authored and clebertsuconic committed Sep 6, 2018
1 parent 64568ef commit 4e03b40
Showing 1 changed file with 28 additions and 21 deletions.
Expand Up @@ -45,6 +45,7 @@
import org.apache.activemq.artemis.core.server.ServerSession;
import org.apache.activemq.artemis.core.server.impl.AddressInfo;
import org.apache.activemq.artemis.core.server.impl.ServerConsumerImpl;
import org.apache.activemq.artemis.core.settings.impl.AddressSettings;
import org.apache.activemq.artemis.core.transaction.Transaction;
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException;
import org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPInternalErrorException;
Expand Down Expand Up @@ -306,33 +307,39 @@ public QueueQueryResult queueQuery(SimpleString queueName, RoutingType routingTy


public boolean checkAddressAndAutocreateIfPossible(SimpleString address, RoutingType routingType) throws Exception {
AddressInfo addressInfo = manager.getServer().getAddressInfo(address);

// if the address exists go ahead and return
if (addressInfo != null) {
return true;
}

// if the address and/or queue don't exist then create them if possible
if (routingType == RoutingType.MULTICAST && addressInfo == null) {
if (manager.getServer().getAddressSettingsRepository().getMatch(address.toString()).isAutoCreateAddresses()) {
try {
serverSession.createAddress(address, routingType, true);
} catch (ActiveMQAddressExistsException e) {
// The address may have been created by another thread in the mean time. Catch and do nothing.
boolean result = false;
SimpleString unPrefixedAddress = serverSession.removePrefix(address);
AddressSettings addressSettings = manager.getServer().getAddressSettingsRepository().getMatch(unPrefixedAddress.toString());

if (routingType == RoutingType.MULTICAST) {
if (manager.getServer().getAddressInfo(unPrefixedAddress) == null) {
if (addressSettings.isAutoCreateAddresses()) {
try {
serverSession.createAddress(address, routingType, true);
} catch (ActiveMQAddressExistsException e) {
// The address may have been created by another thread in the mean time. Catch and do nothing.
}
result = true;
}
} else {
result = true;
}
} else if (routingType == RoutingType.ANYCAST && manager.getServer().locateQueue(address) == null) {
if (manager.getServer().getAddressSettingsRepository().getMatch(address.toString()).isAutoCreateQueues()) {
try {
serverSession.createQueue(address, address, routingType, null, false, true, true);
} catch (ActiveMQQueueExistsException e) {
// The queue may have been created by another thread in the mean time. Catch and do nothing.
} else if (routingType == RoutingType.ANYCAST) {
if (manager.getServer().locateQueue(unPrefixedAddress) == null) {
if (addressSettings.isAutoCreateQueues()) {
try {
serverSession.createQueue(address, address, routingType, null, false, true, true);
} catch (ActiveMQQueueExistsException e) {
// The queue may have been created by another thread in the mean time. Catch and do nothing.
}
result = true;
}
} else {
result = true;
}
}

return manager.getServer().getAddressInfo(address) != null;
return result;
}


Expand Down

0 comments on commit 4e03b40

Please sign in to comment.