Search in sources :

Example 56 with QueueControl

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

the class JMSTopicReadAttributeHandler method getQueues.

public static List<QueueControl> getQueues(final DurabilityType durability, AddressControl addressControl, ManagementService managementService) {
    try {
        List<QueueControl> matchingQueues = new ArrayList<>();
        String[] queues = addressControl.getQueueNames();
        for (String queue : queues) {
            QueueControl coreQueueControl = (QueueControl) managementService.getResource(ResourceNames.QUEUE + queue);
            // Ignore the "special" subscription
            if (coreQueueControl != null && !coreQueueControl.getName().equals(addressControl.getAddress()) && (durability == DurabilityType.ALL || durability == DurabilityType.DURABLE && coreQueueControl.isDurable() || durability == DurabilityType.NON_DURABLE && !coreQueueControl.isDurable())) {
                matchingQueues.add(coreQueueControl);
            }
        }
        return matchingQueues;
    } catch (Exception e) {
        return Collections.emptyList();
    }
}
Also used : ArrayList(java.util.ArrayList) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 57 with QueueControl

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

the class JMSQueueReadAttributeHandler method getControl.

private QueueControl getControl(OperationContext context, ModelNode operation) {
    String queueName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
    final ServiceName serviceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
    ServiceController<?> service = context.getServiceRegistry(false).getService(serviceName);
    ActiveMQServer server = ActiveMQServer.class.cast(service.getValue());
    QueueControl control = QueueControl.class.cast(server.getManagementService().getResource(ResourceNames.QUEUE + JMS_QUEUE_PREFIX + queueName));
    return control;
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) ServiceName(org.jboss.msc.service.ServiceName) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 58 with QueueControl

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

the class JMSQueueReadAttributeHandler method executeRuntimeStep.

@Override
public void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
    if (ignoreOperationIfServerNotActive(context, operation)) {
        return;
    }
    validator.validate(operation);
    final String attributeName = operation.require(ModelDescriptionConstants.NAME).asString();
    QueueControl control = getControl(context, operation);
    if (control == null) {
        PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
        throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
    }
    if (CommonAttributes.MESSAGE_COUNT.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.getMessageCount());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (CommonAttributes.SCHEDULED_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getScheduledCount());
    } else if (CommonAttributes.CONSUMER_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getConsumerCount());
    } else if (CommonAttributes.DELIVERING_COUNT.getName().equals(attributeName)) {
        context.getResult().set(control.getDeliveringCount());
    } else if (CommonAttributes.MESSAGES_ADDED.getName().equals(attributeName)) {
        context.getResult().set(control.getMessagesAdded());
    } else if (JMSQueueDefinition.QUEUE_ADDRESS.getName().equals(attributeName)) {
        context.getResult().set(control.getAddress());
    } else if (JMSQueueDefinition.EXPIRY_ADDRESS.getName().equals(attributeName)) {
        // create the result node in all cases
        ModelNode result = context.getResult();
        String expiryAddress = control.getExpiryAddress();
        if (expiryAddress != null) {
            result.set(expiryAddress);
        }
    } else if (JMSQueueDefinition.DEAD_LETTER_ADDRESS.getName().equals(attributeName)) {
        // create the result node in all cases
        ModelNode result = context.getResult();
        String dla = control.getDeadLetterAddress();
        if (dla != null) {
            result.set(dla);
        }
    } else if (CommonAttributes.PAUSED.getName().equals(attributeName)) {
        try {
            context.getResult().set(control.isPaused());
        } catch (RuntimeException e) {
            throw e;
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
    } else if (CommonAttributes.TEMPORARY.getName().equals(attributeName)) {
        context.getResult().set(control.isTemporary());
    } else {
        throw MessagingLogger.ROOT_LOGGER.unsupportedAttribute(attributeName);
    }
}
Also used : PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Example 59 with QueueControl

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

the class JMSServerControlHandler method enrichConsumer.

private JsonObject enrichConsumer(JsonObject originalConsumer, ActiveMQServer server) {
    JsonObjectBuilder enrichedConsumer = Json.createObjectBuilder();
    for (Map.Entry<String, JsonValue> entry : originalConsumer.entrySet()) {
        enrichedConsumer.add(entry.getKey(), entry.getValue());
    }
    String queueName = originalConsumer.getString("queueName");
    final QueueControl queueControl = QueueControl.class.cast(server.getManagementService().getResource(ResourceNames.QUEUE + queueName));
    if (queueControl == null) {
        return originalConsumer;
    }
    enrichedConsumer.add("durable", queueControl.isDurable());
    String routingType = queueControl.getRoutingType();
    String destinationType = routingType.equals("ANYCAST") ? "queue" : "topic";
    enrichedConsumer.add("destinationType", destinationType);
    String address = queueControl.getAddress();
    String destinationName = inferDestinationName(address);
    enrichedConsumer.add("destinationName", destinationName);
    return enrichedConsumer.build();
}
Also used : JsonValue(javax.json.JsonValue) JsonObjectBuilder(javax.json.JsonObjectBuilder) HashMap(java.util.HashMap) Map(java.util.Map) QueueControl(org.apache.activemq.artemis.api.core.management.QueueControl)

Example 60 with QueueControl

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

the class ActiveMQServerControlImpl method listQueues.

@Override
public String listQueues(String options, int page, int pageSize) throws Exception {
    checkStarted();
    clearIO();
    try {
        List<QueueControl> queues = new ArrayList<>();
        Object[] qs = server.getManagementService().getResources(QueueControl.class);
        for (int i = 0; i < qs.length; i++) {
            queues.add((QueueControl) qs[i]);
        }
        QueueView view = new QueueView(server);
        view.setCollection(queues);
        view.setOptions(options);
        return view.getResultsAsJson(page, pageSize);
    } finally {
        blockOnIO();
    }
}
Also used : QueueView(org.apache.activemq.artemis.core.management.impl.view.QueueView) ArrayList(java.util.ArrayList) JsonObject(javax.json.JsonObject) 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