use of org.wildfly.common.function.ExceptionFunction in project wildfly by wildfly.
the class ProtocolMetricsHandler method executeRuntimeStep.
@Override
protected void executeRuntimeStep(OperationContext context, ModelNode operation) throws OperationFailedException {
String name = Operations.getAttributeName(operation);
String protocolName = context.getCurrentAddressValue();
ServiceName channelServiceName = JGroupsRequirement.CHANNEL.getServiceName(context, UnaryCapabilityNameResolver.PARENT);
ExceptionFunction<JChannel, ModelNode, Exception> function = new ExceptionFunction<JChannel, ModelNode, Exception>() {
@Override
public ModelNode apply(JChannel channel) throws Exception {
int index = protocolName.lastIndexOf('.');
Protocol protocol = channel.getProtocolStack().findProtocol((index < 0) ? protocolName : protocolName.substring(index + 1));
if (protocol == null) {
throw new IllegalArgumentException(protocolName);
}
Attribute attribute = getAttribute(protocol.getClass(), name);
if (attribute == null) {
throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.unknownMetric(name));
}
FieldType type = FieldType.valueOf(attribute.getType());
ModelNode result = new ModelNode();
Object value = attribute.read(protocol);
if (value != null) {
type.setValue(result, value);
}
return result;
}
};
FunctionExecutor<JChannel> executor = this.executors.get(channelServiceName);
try {
ModelNode value = (executor != null) ? executor.execute(function) : null;
if (value != null) {
context.getResult().set(value);
}
} catch (Exception e) {
context.getFailureDescription().set(e.getLocalizedMessage());
} finally {
context.completeStep(OperationContext.ResultHandler.NOOP_RESULT_HANDLER);
}
}
Aggregations