Search in sources :

Example 51 with QueueControl

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

the class LocalTestServer method removeAllMessages.

@Override
public void removeAllMessages(final String queueName) throws Exception {
    QueueControl queue = (QueueControl) getActiveMQServer().getManagementService().getResource(ResourceNames.QUEUE + queueName);
    queue.removeMessages(null);
}
Also used : QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 52 with QueueControl

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

the class BridgeTestBase method checkEmpty.

public boolean checkEmpty(final Queue queue, final int index) throws Exception {
    ManagementService managementService = server0.getManagementService();
    if (index == 1) {
        managementService = server1.getManagementService();
    }
    QueueControl queueControl = (QueueControl) managementService.getResource(ResourceNames.QUEUE + queue.getQueueName());
    // server may be closed
    if (queueControl != null) {
        queueControl.flushExecutor();
        Long messageCount = queueControl.getMessageCount();
        if (messageCount > 0) {
            queueControl.removeMessages(null);
        }
    }
    return true;
}
Also used : ManagementService(org.apache.activemq.artemis.core.server.management.ManagementService) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 53 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project wildfly by wildfly.

the class JMSTopicControlHandler method listSubscribersInfosAsJSON.

private String listSubscribersInfosAsJSON(final DurabilityType durability, AddressControl addressControl, ManagementService managementService) {
    javax.json.JsonArrayBuilder array = JsonLoader.createArrayBuilder();
    try {
        List<QueueControl> queues = JMSTopicReadAttributeHandler.getQueues(durability, addressControl, managementService);
        for (QueueControl queue : queues) {
            String clientID = null;
            String subName = null;
            if (queue.isDurable() && RoutingType.MULTICAST.toString().equals(queue.getRoutingType())) {
                Pair<String, String> pair = ActiveMQDestination.decomposeQueueNameForDurableSubscription(queue.getName());
                clientID = pair.getA();
                subName = pair.getB();
            } else if (RoutingType.MULTICAST.toString().equals(queue.getRoutingType())) {
                // in the case of heirarchical topics the queue name will not follow the <part>.<part> pattern of normal
                // durable subscribers so skip decomposing the name for the client ID and subscription name and just
                // hard-code it
                clientID = "ActiveMQ";
                subName = "ActiveMQ";
            }
            String filter = queue.getFilter() != null ? queue.getFilter() : null;
            JsonObject info = JsonLoader.createObjectBuilder().add("queueName", queue.getName()).add("clientID", nullSafe(clientID)).add("selector", nullSafe(filter)).add("name", nullSafe(subName)).add("durable", queue.isDurable()).add("messageCount", queue.getMessageCount()).add("deliveringCount", queue.getDeliveringCount()).add("consumers", queue.listConsumersAsJSON()).build();
            array.add(info);
        }
    } catch (Exception e) {
        rethrow(e);
    }
    return array.build().toString();
}
Also used : JsonArrayBuilder(javax.json.JsonArrayBuilder) JsonObject(javax.json.JsonObject) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 54 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project wildfly by wildfly.

the class JMSTopicControlHandler method dropDurableSubscription.

private void dropDurableSubscription(final String clientID, final String subscriptionName, ManagementService managementService) throws Exception {
    SimpleString queueName = ActiveMQDestination.createQueueNameForSubscription(true, clientID, subscriptionName);
    QueueControl coreQueueControl = (QueueControl) managementService.getResource(ResourceNames.QUEUE + queueName);
    if (coreQueueControl == null) {
        throw new IllegalArgumentException("No subscriptions with name " + queueName + " for clientID " + clientID);
    }
    ActiveMQServerControl serverControl = (ActiveMQServerControl) managementService.getResource(ResourceNames.BROKER);
    serverControl.destroyQueue(queueName.toString(), true);
}
Also used : ActiveMQServerControl(org.apache.activemq.artemis.api.core.management.ActiveMQServerControl) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 55 with QueueControl

use of org.apache.activemq.artemis.api.core.management.QueueControl in project wildfly by wildfly.

the class JMSTopicReadAttributeHandler method getMessageCount.

private int getMessageCount(final DurabilityType durability, AddressControl addressControl, ManagementService managementService) {
    List<QueueControl> queues = getQueues(durability, addressControl, managementService);
    int count = 0;
    for (QueueControl queue : queues) {
        count += queue.getMessageCount();
    }
    return count;
}
Also used : QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Aggregations

QueueControl (org.apache.activemq.artemis.api.core.management.QueueControl)109 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)87 Test (org.junit.Test)79 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)50 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)33 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)24 HashMap (java.util.HashMap)21 Map (java.util.Map)18 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)15 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)9 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)9 ArrayList (java.util.ArrayList)7 JsonObject (javax.json.JsonObject)7 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)7 MessageProducer (javax.jms.MessageProducer)6 TextMessage (javax.jms.TextMessage)6 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)6 Session (javax.jms.Session)5 JsonArray (javax.json.JsonArray)5 Queue (org.apache.activemq.artemis.core.server.Queue)5