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();
}
}
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;
}
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);
}
}
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();
}
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();
}
}
Aggregations