use of org.jboss.as.clustering.controller.WriteAttributeStepHandler in project wildfly by wildfly.
the class TransportResourceDefinition method register.
@Override
public ManagementResourceRegistration register(ManagementResourceRegistration parent) {
ManagementResourceRegistration registration = super.register(parent);
new WriteAttributeStepHandler(new WriteThreadingAttributeStepHandlerDescriptor()) {
@Override
protected void validateUpdatedModel(OperationContext context, Resource model) throws OperationFailedException {
// Add a new step to validate instead of doing it directly in this method.
// This allows a composite op to change both attributes and then the
// validation occurs after both have done their work.
context.addStep(new OperationStepHandler() {
@Override
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException {
ModelNode conf = context.readResource(PathAddress.EMPTY_ADDRESS).getModel();
// TODO doesn't cover the admin-only modes
if (context.getProcessType().isServer()) {
for (ThreadingAttribute attribute : EnumSet.allOf(ThreadingAttribute.class)) {
if (conf.hasDefined(attribute.getName())) {
// That is not supported.
throw new OperationFailedException(JGroupsLogger.ROOT_LOGGER.threadsAttributesUsedInRuntime());
}
}
}
}
}, OperationContext.Stage.MODEL);
}
}.register(registration);
if (registration.getPathAddress().getLastElement().isWildcard()) {
for (ThreadPoolResourceDefinition pool : EnumSet.allOf(ThreadPoolResourceDefinition.class)) {
pool.register(registration);
}
parent.registerAlias(LEGACY_PATH, new AliasEntry(registration) {
@Override
public PathAddress convertToTargetAddress(PathAddress aliasAddress, AliasContext aliasContext) {
PathAddress target = this.getTargetAddress();
List<PathElement> result = new ArrayList<>(aliasAddress.size());
for (int i = 0; i < aliasAddress.size(); ++i) {
PathElement element = aliasAddress.getElement(i);
if (i == target.size() - 1) {
final ModelNode operation = aliasContext.getOperation();
final String stackName;
if (ModelDescriptionConstants.ADD.equals(Operations.getName(operation)) && operation.hasDefined("type")) {
stackName = operation.get("type").asString();
} else {
Resource root = null;
try {
root = aliasContext.readResourceFromRoot(PathAddress.pathAddress(result));
} catch (Resource.NoSuchResourceException ignored) {
}
if (root == null) {
stackName = "*";
} else {
Set<String> names = root.getChildrenNames("transport");
if (names.size() > 1) {
throw new AssertionError("There should be at most one child");
} else if (names.size() == 0) {
stackName = "*";
} else {
stackName = names.iterator().next();
}
}
}
result.add(PathElement.pathElement("transport", stackName));
} else if (i < target.size()) {
PathElement targetElement = target.getElement(i);
result.add(targetElement.isWildcard() ? PathElement.pathElement(targetElement.getKey(), element.getValue()) : targetElement);
} else {
result.add(element);
}
}
return PathAddress.pathAddress(result);
}
});
}
return registration;
}
Aggregations