Search in sources :

Example 1 with ActiveMQAddressExistsException

use of org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException in project activemq-artemis by apache.

the class OpenWireConnection method addDestination.

public void addDestination(DestinationInfo info) throws Exception {
    boolean created = false;
    ActiveMQDestination dest = info.getDestination();
    if (!protocolManager.isSupportAdvisory() && AdvisorySupport.isAdvisoryTopic(dest)) {
        return;
    }
    SimpleString qName = SimpleString.toSimpleString(dest.getPhysicalName());
    if (server.locateQueue(qName) == null) {
        AddressSettings addressSettings = server.getAddressSettingsRepository().getMatch(dest.getPhysicalName());
        AddressInfo addressInfo = new AddressInfo(qName, dest.isTopic() ? RoutingType.MULTICAST : RoutingType.ANYCAST);
        if (AdvisorySupport.isAdvisoryTopic(dest) && protocolManager.isSuppressInternalManagementObjects()) {
            addressInfo.setInternal(true);
        }
        if (dest.isQueue() && (addressSettings.isAutoCreateQueues() || dest.isTemporary())) {
            try {
                internalSession.createQueue(addressInfo, qName, null, dest.isTemporary(), !dest.isTemporary(), !dest.isTemporary());
                created = true;
            } catch (ActiveMQQueueExistsException exists) {
            // The queue may have been created by another thread in the mean time.  Catch and do nothing.
            }
        } else if (dest.isTopic() && (addressSettings.isAutoCreateAddresses() || dest.isTemporary())) {
            try {
                internalSession.createAddress(addressInfo, !dest.isTemporary());
                created = true;
            } catch (ActiveMQAddressExistsException exists) {
            // The address may have been created by another thread in the mean time.  Catch and do nothing.
            }
        }
    }
    if (dest.isTemporary()) {
        // Openwire needs to store the DestinationInfo in order to send
        // Advisory messages to clients
        this.state.addTempDestination(info);
    }
    if (created && !AdvisorySupport.isAdvisoryTopic(dest)) {
        AMQConnectionContext context = getContext();
        DestinationInfo advInfo = new DestinationInfo(context.getConnectionId(), DestinationInfo.ADD_OPERATION_TYPE, dest);
        ActiveMQTopic topic = AdvisorySupport.getDestinationAdvisoryTopic(dest);
        protocolManager.fireAdvisory(context, topic, advInfo);
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) DestinationInfo(org.apache.activemq.command.DestinationInfo) ActiveMQTopic(org.apache.activemq.command.ActiveMQTopic) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException) AMQConnectionContext(org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActiveMQDestination(org.apache.activemq.command.ActiveMQDestination) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 2 with ActiveMQAddressExistsException

use of org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException in project activemq-artemis by apache.

the class AMQPSessionCallback method bindingQuery.

public boolean bindingQuery(SimpleString address, RoutingType routingType) throws Exception {
    BindingQueryResult bindingQueryResult = bindingQueryCache.getResult(address);
    if (bindingQueryResult != null) {
        return bindingQueryResult.isExists();
    }
    bindingQueryResult = serverSession.executeBindingQuery(address);
    if (routingType == RoutingType.MULTICAST && !bindingQueryResult.isExists() && bindingQueryResult.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.
        }
        bindingQueryResult = serverSession.executeBindingQuery(address);
    } else if (routingType == RoutingType.ANYCAST && bindingQueryResult.isAutoCreateQueues()) {
        QueueQueryResult queueBinding = serverSession.executeQueueQuery(address);
        if (!queueBinding.isExists()) {
            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.
            }
        }
        bindingQueryResult = serverSession.executeBindingQuery(address);
    }
    bindingQueryCache.setResult(address, bindingQueryResult);
    return bindingQueryResult.isExists();
}
Also used : BindingQueryResult(org.apache.activemq.artemis.core.server.BindingQueryResult) ActiveMQAddressExistsException(org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException) ActiveMQQueueExistsException(org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult)

Aggregations

ActiveMQAddressExistsException (org.apache.activemq.artemis.api.core.ActiveMQAddressExistsException)2 ActiveMQQueueExistsException (org.apache.activemq.artemis.api.core.ActiveMQQueueExistsException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)1 AMQConnectionContext (org.apache.activemq.artemis.core.protocol.openwire.amq.AMQConnectionContext)1 BindingQueryResult (org.apache.activemq.artemis.core.server.BindingQueryResult)1 QueueQueryResult (org.apache.activemq.artemis.core.server.QueueQueryResult)1 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)1 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)1 ActiveMQDestination (org.apache.activemq.command.ActiveMQDestination)1 ActiveMQTopic (org.apache.activemq.command.ActiveMQTopic)1 DestinationInfo (org.apache.activemq.command.DestinationInfo)1