final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
final String topicName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
ServiceController<?> hqService = context.getServiceRegistry(false).getService(hqServiceName);
HornetQServer hqServer = HornetQServer.class.cast(hqService.getValue());
TopicControl control = TopicControl.class.cast(hqServer.getManagementService().getResource(ResourceNames.JMS_TOPIC + topicName));
if (control == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
try {
if (LIST_ALL_SUBSCRIPTIONS.equals(operationName)) {
String json = control.listAllSubscriptionsAsJSON();
ModelNode jsonAsNode = ModelNode.fromJSONString(json);
context.getResult().set(jsonAsNode);
} else if (LIST_ALL_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listAllSubscriptionsAsJSON());
} else if (LIST_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
String json = control.listDurableSubscriptionsAsJSON();
ModelNode jsonAsNode = ModelNode.fromJSONString(json);
context.getResult().set(jsonAsNode);
} else if (LIST_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listDurableSubscriptionsAsJSON());
} else if (LIST_NON_DURABLE_SUBSCRIPTIONS.equals(operationName)) {
String json = control.listNonDurableSubscriptionsAsJSON();
ModelNode jsonAsNode = ModelNode.fromJSONString(json);
context.getResult().set(jsonAsNode);
} else if (LIST_NON_DURABLE_SUBSCRIPTIONS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listNonDurableSubscriptionsAsJSON());
} else if (LIST_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
String json = control.listMessagesForSubscriptionAsJSON(queueName);
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_MESSAGES_FOR_SUBSCRIPTION_AS_JSON.equals(operationName)) {
final String queueName = QUEUE_NAME.resolveModelAttribute(context, operation).asString();
context.getResult().set(control.listMessagesForSubscriptionAsJSON(queueName));
} else if (COUNT_MESSAGES_FOR_SUBSCRIPTION.equals(operationName)) {
String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
String filter = resolveFilter(context, operation);
context.getResult().set(control.countMessagesForSubscription(clientId, subscriptionName, filter));
} else if (DROP_DURABLE_SUBSCRIPTION.equals(operationName)) {
String clientId = CLIENT_ID.resolveModelAttribute(context, operation).asString();
String subscriptionName = SUBSCRIPTION_NAME.resolveModelAttribute(context, operation).asString();
control.dropDurableSubscription(clientId, subscriptionName);
context.getResult();
} else if (DROP_ALL_SUBSCRIPTIONS.equals(operationName)) {
control.dropAllSubscriptions();
context.getResult();
} else if (REMOVE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.removeMessages(filter));
} else {
// Bug
throw MessagingLogger.ROOT_LOGGER.unsupportedOperation(operationName);
}
} catch (RuntimeException e) {