Search in sources :

Example 1 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class PostOfficeImpl method removeAddressInfo.

@Override
public AddressInfo removeAddressInfo(SimpleString address, boolean force) throws Exception {
    synchronized (addressLock) {
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.beforeRemoveAddress(address));
        }
        final Bindings bindingsForAddress = getDirectBindings(address);
        if (force) {
            for (Binding binding : bindingsForAddress.getBindings()) {
                if (binding instanceof QueueBinding) {
                    ((QueueBinding) binding).getQueue().deleteQueue(true);
                }
            }
        } else {
            if (bindingsForAddress.getBindings().size() > 0) {
                throw ActiveMQMessageBundle.BUNDLE.addressHasBindings(address);
            }
        }
        managementService.unregisterAddress(address);
        final AddressInfo addressInfo = addressManager.removeAddressInfo(address);
        if (server.hasBrokerPlugins()) {
            server.callBrokerPlugins(plugin -> plugin.afterRemoveAddress(address, addressInfo));
        }
        return addressInfo;
    }
}
Also used : Binding(org.apache.activemq.artemis.core.postoffice.Binding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) Bindings(org.apache.activemq.artemis.core.postoffice.Bindings) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 2 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class PostOfficeImpl method updateQueue.

@Override
public QueueBinding updateQueue(SimpleString name, RoutingType routingType, Integer maxConsumers, Boolean purgeOnNoConsumers, Boolean exclusive) throws Exception {
    synchronized (addressLock) {
        final QueueBinding queueBinding = (QueueBinding) addressManager.getBinding(name);
        if (queueBinding == null) {
            return null;
        }
        final Queue queue = queueBinding.getQueue();
        boolean changed = false;
        // validate update
        if (maxConsumers != null && maxConsumers.intValue() != Queue.MAX_CONSUMERS_UNLIMITED) {
            final int consumerCount = queue.getConsumerCount();
            if (consumerCount > maxConsumers) {
                throw ActiveMQMessageBundle.BUNDLE.invalidMaxConsumersUpdate(name.toString(), maxConsumers, consumerCount);
            }
        }
        if (routingType != null) {
            final SimpleString address = queue.getAddress();
            final AddressInfo addressInfo = addressManager.getAddressInfo(address);
            final EnumSet<RoutingType> addressRoutingTypes = addressInfo.getRoutingTypes();
            if (!addressRoutingTypes.contains(routingType)) {
                throw ActiveMQMessageBundle.BUNDLE.invalidRoutingTypeUpdate(name.toString(), routingType, address.toString(), addressRoutingTypes);
            }
        }
        // atomic update
        if (maxConsumers != null && queue.getMaxConsumers() != maxConsumers.intValue()) {
            changed = true;
            queue.setMaxConsumer(maxConsumers);
        }
        if (routingType != null && queue.getRoutingType() != routingType) {
            changed = true;
            queue.setRoutingType(routingType);
        }
        if (purgeOnNoConsumers != null && queue.isPurgeOnNoConsumers() != purgeOnNoConsumers.booleanValue()) {
            changed = true;
            queue.setPurgeOnNoConsumers(purgeOnNoConsumers);
        }
        if (exclusive != null && queue.isExclusive() != exclusive.booleanValue()) {
            changed = true;
            queue.setExclusive(exclusive);
        }
        if (changed) {
            final long txID = storageManager.generateID();
            try {
                storageManager.updateQueueBinding(txID, queueBinding);
                storageManager.commitBindings(txID);
            } catch (Throwable throwable) {
                storageManager.rollback(txID);
                logger.warn(throwable.getMessage(), throwable);
                throw throwable;
            }
        }
        return queueBinding;
    }
}
Also used : QueueBinding(org.apache.activemq.artemis.core.postoffice.QueueBinding) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Queue(org.apache.activemq.artemis.core.server.Queue) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 3 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class WildcardAddressManager method removeAddressInfo.

@Override
public AddressInfo removeAddressInfo(SimpleString address) throws Exception {
    final AddressInfo removed = super.removeAddressInfo(address);
    if (removed != null) {
        // Remove from mappings so removeAndUpdateAddressMap processes and cleanup
        mappings.remove(address);
        removeAndUpdateAddressMap(new AddressImpl(removed.getName(), wildcardConfiguration));
    }
    return removed;
}
Also used : AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 4 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method getAddressInfo.

@Override
public String getAddressInfo(String address) throws ActiveMQAddressDoesNotExistException {
    checkStarted();
    clearIO();
    try {
        final AddressInfo addressInfo = server.getAddressInfo(SimpleString.toSimpleString(address));
        if (addressInfo == null) {
            throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(SimpleString.toSimpleString(address));
        } else {
            return AddressInfoTextFormatter.Long.format(addressInfo, new StringBuilder()).toString();
        }
    } finally {
        blockOnIO();
    }
}
Also used : AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Example 5 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class ActiveMQServerControlImpl method createAddress.

@Override
public String createAddress(String name, String routingTypes) throws Exception {
    checkStarted();
    clearIO();
    try {
        EnumSet<RoutingType> set = EnumSet.noneOf(RoutingType.class);
        for (String routingType : ListUtil.toList(routingTypes)) {
            set.add(RoutingType.valueOf(routingType));
        }
        final AddressInfo addressInfo = new AddressInfo(new SimpleString(name), set);
        if (server.addAddressInfo(addressInfo)) {
            return AddressInfoTextFormatter.Long.format(addressInfo, new StringBuilder()).toString();
        } else {
            throw ActiveMQMessageBundle.BUNDLE.addressAlreadyExists(addressInfo.getName());
        }
    } finally {
        blockOnIO();
    }
}
Also used : SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DivertConfigurationRoutingType(org.apache.activemq.artemis.core.server.DivertConfigurationRoutingType) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo)

Aggregations

AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)116 Test (org.junit.Test)89 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)73 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)32 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)24 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)23 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)23 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)22 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)21 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)19 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)18 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)17 JsonObject (javax.json.JsonObject)16 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)16 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)16 JsonArray (javax.json.JsonArray)15 Queue (org.apache.activemq.artemis.core.server.Queue)15 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)13 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Session (javax.jms.Session)11