Skip to content

Instantly share code, notes, and snippets.

@pferraro
Created June 11, 2014 13:56
Show Gist options
  • Save pferraro/b760f8cb3ab06405f550 to your computer and use it in GitHub Desktop.
Save pferraro/b760f8cb3ab06405f550 to your computer and use it in GitHub Desktop.
batching transformer
/**
* Registers cache transformations for model changes introduced in 3.0.0
*/
private static void registerCacheTransformations200(final ResourceTransformationDescriptionBuilder cacheBuilder, CacheMode mode) {
AttributeConverter transactionModeConverter = new AttributeConverter() {
@Override
public void convertOperationParameter(PathAddress address, String attributeName, ModelNode attributeValue, ModelNode operation, TransformationContext context) {
convert(attributeValue, operation);
}
@Override
public void convertResourceAttribute(PathAddress address, String attributeName, ModelNode attributeValue, TransformationContext context) {
ModelNode cacheModel = context.readResourceFromRoot(address).getModel();
convert(attributeValue, cacheModel);
}
private void convert(ModelNode attributeValue, ModelNode operation) {
if (attributeValue.isDefined() && TransactionMode.valueOf(attributeValue.asString()) == TransactionMode.BATCH) {
attributeValue.set(TransactionMode.NONE.name());
try {
CacheResourceDefinition.BATCHING.validateAndSet(operation, new ModelNode(true));
} catch (OperationFailedException e) {
throw new IllegalStateException(e);
}
}
}
};
cacheBuilder.addChildResource(TransactionResourceDefinition.TRANSACTION_PATH).getAttributeBuilder()
.setValueConverter(transactionModeConverter, TransactionResourceDefinition.MODE)
;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment