use of org.jboss.dmr.ModelType.INT in project wildfly by wildfly.
the class AbstractQueueControlHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
if (rollbackOperationIfServerNotActive(context, operation)) {
return;
}
final String operationName = operation.require(ModelDescriptionConstants.OP).asString();
final String queueName = PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)).getLastElement().getValue();
final ServiceName activeMQServiceName = MessagingServices.getActiveMQServiceName(PathAddress.pathAddress(operation.get(ModelDescriptionConstants.OP_ADDR)));
ServiceController<?> activeMQService = context.getServiceRegistry(false).getService(activeMQServiceName);
ActiveMQServer server = ActiveMQServer.class.cast(activeMQService.getValue());
final DelegatingQueueControl<T> control = getQueueControl(server, queueName);
if (control == null) {
PathAddress address = PathAddress.pathAddress(operation.require(OP_ADDR));
throw ControllerLogger.ROOT_LOGGER.managementResourceNotFound(address);
}
boolean reversible = false;
Object handback = null;
try {
if (LIST_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
String json = control.listMessagesAsJSON(filter);
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_MESSAGES_AS_JSON.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.listMessagesAsJSON(filter));
} else if (LIST_DELIVERING_MESSAGES.equals(operationName)) {
String json = control.listDeliveringMessagesAsJSON();
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_DELIVERING_MESSAGES_AS_JSON.equals(operationName)) {
context.getResult().set(control.listDeliveringMessagesAsJSON());
} else if (LIST_SCHEDULED_MESSAGES.equals(operationName)) {
String json = control.listScheduledMessagesAsJSON();
context.getResult().set(ModelNode.fromJSONString(json));
} else if (LIST_SCHEDULED_MESSAGES_AS_JSON.equals(operationName)) {
context.getResult().set(control.listScheduledMessagesAsJSON());
} else if (COUNT_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.countMessages(filter));
} else if (REMOVE_MESSAGE.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
context.getResult().set(control.removeMessage(id));
} else if (REMOVE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.removeMessages(filter));
} else if (EXPIRE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.expireMessages(filter));
} else if (EXPIRE_MESSAGE.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
context.getResult().set(control.expireMessage(id));
} else if (SEND_MESSAGE_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
context.getResult().set(control.sendMessageToDeadLetterAddress(id));
} else if (SEND_MESSAGES_TO_DEAD_LETTER_ADDRESS.equals(operationName)) {
String filter = resolveFilter(context, operation);
context.getResult().set(control.sendMessagesToDeadLetterAddress(filter));
} else if (CHANGE_MESSAGE_PRIORITY.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
context.getResult().set(control.changeMessagePriority(id, priority));
} else if (CHANGE_MESSAGES_PRIORITY.equals(operationName)) {
String filter = resolveFilter(context, operation);
int priority = NEW_PRIORITY.resolveModelAttribute(context, operation).asInt();
context.getResult().set(control.changeMessagesPriority(filter, priority));
} else if (MOVE_MESSAGE.equals(operationName)) {
ModelNode id = getMessageIDAttributeDefinition().resolveModelAttribute(context, operation);
String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
if (rejectDuplicates.isDefined()) {
context.getResult().set(control.moveMessage(id, otherQueue, rejectDuplicates.asBoolean()));
} else {
context.getResult().set(control.moveMessage(id, otherQueue));
}
} else if (MOVE_MESSAGES.equals(operationName)) {
String filter = resolveFilter(context, operation);
String otherQueue = OTHER_QUEUE_NAME.resolveModelAttribute(context, operation).asString();
ModelNode rejectDuplicates = REJECT_DUPLICATES.resolveModelAttribute(context, operation);
if (rejectDuplicates.isDefined()) {
context.getResult().set(control.moveMessages(filter, otherQueue, rejectDuplicates.asBoolean()));
} else {
context.getResult().set(control.moveMessages(filter, otherQueue));
}
} else if (LIST_MESSAGE_COUNTER_AS_JSON.equals(operationName)) {
context.getResult().set(control.listMessageCounter());
} else if (LIST_MESSAGE_COUNTER_AS_HTML.equals(operationName)) {
context.getResult().set(control.listMessageCounterAsHTML());
} else if (LIST_MESSAGE_COUNTER_HISTORY_AS_JSON.equals(operationName)) {
context.getResult().set(control.listMessageCounterHistory());
} else if (LIST_MESSAGE_COUNTER_HISTORY_AS_HTML.equals(operationName)) {
context.getResult().set(control.listMessageCounterHistoryAsHTML());
} else if (RESET_MESSAGE_COUNTER.equals(operationName)) {
control.resetMessageCounter();
// undefined
context.getResult();
} else if (PAUSE.equals(operationName)) {
control.pause();
reversible = true;
// undefined
context.getResult();
} else if (RESUME.equals(operationName)) {
control.resume();
reversible = true;
// undefined
context.getResult();
} else if (LIST_CONSUMERS_AS_JSON.equals(operationName)) {
context.getResult().set(control.listConsumersAsJSON());
} else {
// TODO dmr-based LIST_MESSAGE_COUNTER, LIST_MESSAGE_COUNTER_HISTORY, LIST_CONSUMERS
handback = handleAdditionalOperation(operationName, operation, context, control.getDelegate());
reversible = handback == null;
}
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
}
OperationContext.RollbackHandler rh;
if (reversible) {
final Object rhHandback = handback;
rh = new OperationContext.RollbackHandler() {
@Override
public void handleRollback(OperationContext context, ModelNode operation) {
try {
if (PAUSE.equals(operationName)) {
control.resume();
} else if (RESUME.equals(operationName)) {
control.pause();
} else {
revertAdditionalOperation(operationName, operation, context, control.getDelegate(), rhHandback);
}
} catch (Exception e) {
ROOT_LOGGER.revertOperationFailed(e, getClass().getSimpleName(), operation.require(ModelDescriptionConstants.OP).asString(), PathAddress.pathAddress(operation.require(ModelDescriptionConstants.OP_ADDR)));
}
}
};
} else {
rh = OperationContext.RollbackHandler.NOOP_ROLLBACK_HANDLER;
}
context.completeStep(rh);
}
Aggregations