Search in sources :

Example 61 with AddressInfo

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

the class SimpleAddressManager method updateAddressInfo.

@Override
public AddressInfo updateAddressInfo(SimpleString addressName, EnumSet<RoutingType> routingTypes) throws Exception {
    AddressInfo info = addressInfoMap.get(addressName);
    if (info == null) {
        throw ActiveMQMessageBundle.BUNDLE.addressDoesNotExist(addressName);
    }
    if (routingTypes == null || isEquals(routingTypes, info.getRoutingTypes())) {
        // there are no changes.. we just give up now
        return info;
    }
    validateRoutingTypes(addressName, routingTypes);
    final EnumSet<RoutingType> updatedRoutingTypes = EnumSet.copyOf(routingTypes);
    info.setRoutingTypes(updatedRoutingTypes);
    if (storageManager != null) {
        // it change the address info without any lock!
        final long txID = storageManager.generateID();
        try {
            storageManager.deleteAddressBinding(txID, info.getId());
            storageManager.addAddressBinding(txID, info);
            storageManager.commitBindings(txID);
        } catch (Exception e) {
            try {
                storageManager.rollbackBindings(txID);
            } catch (Throwable ignored) {
            }
            throw e;
        }
    }
    return info;
}
Also used : AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) RoutingType(org.apache.activemq.artemis.api.core.RoutingType)

Example 62 with AddressInfo

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

the class AddressCommandTest method testFailUpdateAddressRoutingTypesWhenExistsQueues.

@Test
public void testFailUpdateAddressRoutingTypesWhenExistsQueues() throws Exception {
    final String addressName = "address";
    final SimpleString addressSimpleString = new SimpleString(addressName);
    final AddressInfo addressInfo = new AddressInfo(addressSimpleString, EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST));
    server.addAddressInfo(addressInfo);
    server.createQueue(addressSimpleString, RoutingType.MULTICAST, new SimpleString("queue1"), null, true, false);
    final UpdateAddress updateAddress = new UpdateAddress();
    updateAddress.setName(addressName);
    updateAddress.setAnycast(true);
    updateAddress.setMulticast(false);
    updateAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
    final String expectedErrorMessage = MessageFormat.format("Can''t remove routing type {0}, queues exists for address: {1}. Please delete queues before removing this routing type.", RoutingType.MULTICAST, addressName);
    checkExecutionFailure(updateAddress, expectedErrorMessage);
}
Also used : PrintStream(java.io.PrintStream) UpdateAddress(org.apache.activemq.artemis.cli.commands.address.UpdateAddress) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActionContext(org.apache.activemq.artemis.cli.commands.ActionContext) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 63 with AddressInfo

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

the class AddressCommandTest method testFailDeleteAddressWhenExistsQueues.

@Test
public void testFailDeleteAddressWhenExistsQueues() throws Exception {
    final String addressName = "address";
    final SimpleString addressSimpleString = new SimpleString(addressName);
    final AddressInfo addressInfo = new AddressInfo(addressSimpleString, EnumSet.of(RoutingType.ANYCAST, RoutingType.MULTICAST));
    server.addAddressInfo(addressInfo);
    server.createQueue(addressSimpleString, RoutingType.MULTICAST, new SimpleString("queue1"), null, true, false);
    final DeleteAddress deleteAddress = new DeleteAddress();
    deleteAddress.setName(addressName);
    deleteAddress.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
    checkExecutionFailure(deleteAddress, "Address " + addressName + " has bindings");
}
Also used : PrintStream(java.io.PrintStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) DeleteAddress(org.apache.activemq.artemis.cli.commands.address.DeleteAddress) ActionContext(org.apache.activemq.artemis.cli.commands.ActionContext) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 64 with AddressInfo

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

the class AddressCommandTest method testCreateAddress.

@Test
public void testCreateAddress() throws Exception {
    String address = "address";
    CreateAddress command = new CreateAddress();
    command.setName(address);
    command.setAnycast(true);
    command.setMulticast(true);
    command.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
    checkExecutionPassed(command);
    AddressInfo addressInfo = server.getAddressInfo(new SimpleString(address));
    assertNotNull(addressInfo);
    assertTrue(addressInfo.getRoutingTypes().contains(RoutingType.ANYCAST));
    assertTrue(addressInfo.getRoutingTypes().contains(RoutingType.MULTICAST));
}
Also used : PrintStream(java.io.PrintStream) CreateAddress(org.apache.activemq.artemis.cli.commands.address.CreateAddress) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) ActionContext(org.apache.activemq.artemis.cli.commands.ActionContext) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 65 with AddressInfo

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

the class QueueCommandTest method testUpdateCoreQueueCannotLowerMaxConsumers.

@Test
public void testUpdateCoreQueueCannotLowerMaxConsumers() throws Exception {
    final String queueName = "updateQueue";
    final SimpleString queueNameString = new SimpleString(queueName);
    final String addressName = "address";
    final SimpleString addressSimpleString = new SimpleString(addressName);
    final int oldMaxConsumers = 2;
    final RoutingType oldRoutingType = RoutingType.MULTICAST;
    final boolean oldPurgeOnNoConsumers = false;
    final AddressInfo addressInfo = new AddressInfo(addressSimpleString, oldRoutingType);
    server.addAddressInfo(addressInfo);
    server.createQueue(addressSimpleString, oldRoutingType, queueNameString, null, true, false, oldMaxConsumers, oldPurgeOnNoConsumers, false);
    server.locateQueue(queueNameString).addConsumer(new DummyServerConsumer());
    server.locateQueue(queueNameString).addConsumer(new DummyServerConsumer());
    final int newMaxConsumers = 1;
    final UpdateQueue updateQueue = new UpdateQueue();
    updateQueue.setName(queueName);
    updateQueue.setMaxConsumers(newMaxConsumers);
    updateQueue.execute(new ActionContext(System.in, new PrintStream(output), new PrintStream(error)));
    checkExecutionFailure(updateQueue, "AMQ119210");
    final QueueQueryResult queueQueryResult = server.queueQuery(queueNameString);
    assertEquals("maxConsumers", oldMaxConsumers, queueQueryResult.getMaxConsumers());
}
Also used : PrintStream(java.io.PrintStream) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueQueryResult(org.apache.activemq.artemis.core.server.QueueQueryResult) ActionContext(org.apache.activemq.artemis.cli.commands.ActionContext) UpdateQueue(org.apache.activemq.artemis.cli.commands.queue.UpdateQueue) RoutingType(org.apache.activemq.artemis.api.core.RoutingType) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

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