Search in sources :

Example 1 with JMSQueueControl

use of org.apache.activemq.artemis.api.jms.management.JMSQueueControl in project wildfly by wildfly.

the class JMSQueueReadAttributeHandler method getControl.

private JMSQueueControl 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());
    JMSQueueControl control = JMSQueueControl.class.cast(server.getManagementService().getResource(ResourceNames.JMS_QUEUE + queueName));
    return control;
}
Also used : ActiveMQServer(org.apache.activemq.artemis.core.server.ActiveMQServer) JMSQueueControl(org.apache.activemq.artemis.api.jms.management.JMSQueueControl) ServiceName(org.jboss.msc.service.ServiceName)

Example 2 with JMSQueueControl

use of org.apache.activemq.artemis.api.jms.management.JMSQueueControl 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();
    JMSQueueControl 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 : JMSQueueControl(org.apache.activemq.artemis.api.jms.management.JMSQueueControl) PathAddress(org.jboss.as.controller.PathAddress) ModelNode(org.jboss.dmr.ModelNode) OperationFailedException(org.jboss.as.controller.OperationFailedException)

Aggregations

JMSQueueControl (org.apache.activemq.artemis.api.jms.management.JMSQueueControl)2 ActiveMQServer (org.apache.activemq.artemis.core.server.ActiveMQServer)1 OperationFailedException (org.jboss.as.controller.OperationFailedException)1 PathAddress (org.jboss.as.controller.PathAddress)1 ModelNode (org.jboss.dmr.ModelNode)1 ServiceName (org.jboss.msc.service.ServiceName)1