return OP_PROCESSOR_NAME;
}
@Override
public ThrowingConsumer<Context> select(final Context ctx) throws OpProcessorException {
final RequestMessage message = ctx.getRequestMessage();
logger.debug("Selecting processor for RequestMessage {}", message);
final ThrowingConsumer<Context> op;
switch (message.getOp()) {
case Tokens.OPS_VERSION:
op = ControlOps::versionOp;
break;
case Tokens.OPS_IMPORT:
op = validateImportMessage(message).orElse(ControlOps::importOp);
break;
case Tokens.OPS_RESET:
op = ControlOps::resetOp;
break;
case Tokens.OPS_SHOW:
op = validateShowMessage(message).orElse(ControlOps::showOp);
break;
case Tokens.OPS_USE:
op = validateUseMessage(message).orElse(ControlOps::useOp);
break;
case Tokens.OPS_INVALID:
final String msgInvalid = String.format("Message could not be parsed. Check the format of the request. [%s]", message);
throw new OpProcessorException(msgInvalid, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_MALFORMED_REQUEST).result(msgInvalid).create());
default:
final String msgDefault = String.format("Message with op code [%s] is not recognized.", message.getOp());
throw new OpProcessorException(msgDefault, ResponseMessage.build(message).code(ResponseStatusCode.REQUEST_ERROR_MALFORMED_REQUEST).result(msgDefault).create());
}
controlOpMeter.mark();
return op;