Skip to content

Commit

Permalink
Code cleanup.
Browse files Browse the repository at this point in the history
  • Loading branch information
pferraro committed Sep 23, 2015
1 parent 525414f commit a76b793
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 18 deletions.
Expand Up @@ -70,21 +70,21 @@ public ChainedOperationTransformer(List<OperationTransformer> transformers, bool
*/
@Override
public TransformedOperation transformOperation(TransformationContext context, PathAddress address, ModelNode originalOperation) throws OperationFailedException {
String originalName = originalOperation.get(ModelDescriptionConstants.OP).asString();
ModelNode originalAddress = originalOperation.get(ModelDescriptionConstants.OP_ADDR);
String originalName = Operations.getName(originalOperation);
PathAddress originalAddress = Operations.getPathAddress(originalOperation);
Deque<ModelNode> preSteps = new LinkedList<>();
Deque<ModelNode> postSteps = new LinkedList<>();
ModelNode operation = originalOperation;
for (OperationTransformer transformer: this.transformers) {
operation = transformer.transformOperation(context, address, operation).getTransformedOperation();
// If the transformed operation is a composite operation, locate the modified operation and record any pre/post operations
if (collate && operation.get(ModelDescriptionConstants.OP).asString().equals(ModelDescriptionConstants.COMPOSITE)) {
if (this.collate && operation.get(ModelDescriptionConstants.OP).asString().equals(ModelDescriptionConstants.COMPOSITE)) {
List<ModelNode> stepList = operation.get(ModelDescriptionConstants.STEPS).asList();
ListIterator<ModelNode> steps = stepList.listIterator();
while (steps.hasNext()) {
ModelNode step = steps.next();
String operationName = step.get(ModelDescriptionConstants.OP).asString();
ModelNode operationAddress = step.get(ModelDescriptionConstants.OP_ADDR);
String operationName = Operations.getName(step);
PathAddress operationAddress = Operations.getPathAddress(step);
if (operationName.equals(originalName) && operationAddress.equals(originalAddress)) {
operation = step;
break;
Expand All @@ -94,16 +94,16 @@ public TransformedOperation transformOperation(TransformationContext context, Pa
steps = stepList.listIterator(stepList.size());
while (steps.hasPrevious()) {
ModelNode step = steps.previous();
String operationName = step.get(ModelDescriptionConstants.OP).asString();
ModelNode operationAddress = step.get(ModelDescriptionConstants.OP_ADDR);
String operationName = Operations.getName(step);
PathAddress operationAddress = Operations.getPathAddress(step);
if (operationName.equals(originalName) && operationAddress.equals(originalAddress)) {
break;
}
postSteps.addFirst(step);
}
}
}
if (collate) {
if (this.collate) {
int count = preSteps.size() + postSteps.size() + 1;
// If there are any pre or post steps, we need a composite operation
if (count > 1) {
Expand Down
Expand Up @@ -40,18 +40,17 @@ public class InitialAttributeValueOperationContextAttachment {

public static final OperationContext.AttachmentKey<InitialAttributeValueOperationContextAttachment> INITIAL_VALUES_ATTACHMENT = OperationContext.AttachmentKey.create(InitialAttributeValueOperationContextAttachment.class);

private volatile Map<String, ModelNode> initialValues = new HashMap<>();
private final Map<PathAddress, ModelNode> initialValues = new HashMap<>();

public ModelNode putIfAbsentInitialValue(PathAddress address, String attributeName, ModelNode initialValue) {
return initialValues.putIfAbsent(this.keyFor(address, attributeName), initialValue.clone());
return this.initialValues.putIfAbsent(keyFor(address, attributeName), initialValue.clone());
}

public ModelNode getInitialValue(PathAddress address, String attributeName) {
return initialValues.get(this.keyFor(address, attributeName));
return this.initialValues.get(keyFor(address, attributeName));
}


private String keyFor(PathAddress address, String attributeName) {
return address.toString() + attributeName;
private static PathAddress keyFor(PathAddress address, String attributeName) {
return address.append(attributeName);
}
}
Expand Up @@ -51,7 +51,7 @@ public TransformedOperation transformOperation(TransformationContext context, Pa
if (attachment != null) {
ModelNode value = attachment.getInitialValue(address, Operations.getAttributeName(operation));
if (value != null) {
attachment.putIfAbsentInitialValue(addressTransformer.transform(address), Operations.getAttributeName(operation), value);
attachment.putIfAbsentInitialValue(this.addressTransformer.transform(address), Operations.getAttributeName(operation), value);
}
}

Expand Down
Expand Up @@ -22,6 +22,8 @@

package org.jboss.as.clustering.controller.transform;

import java.util.Collection;

import org.jboss.as.clustering.controller.Attribute;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.registry.Resource;
Expand All @@ -39,16 +41,16 @@
*/
public class UndefinedAttributesDiscardPolicy implements DynamicDiscardPolicy {

private final Iterable<Attribute> attributes;
private final Collection<Attribute> attributes;

public UndefinedAttributesDiscardPolicy(Iterable<Attribute> attributes) {
public UndefinedAttributesDiscardPolicy(Collection<Attribute> attributes) {
this.attributes = attributes;
}

@Override
public DiscardPolicy checkResource(TransformationContext context, PathAddress address) {
ModelNode model = Resource.Tools.readModel(context.readResourceFromRoot(address));
for (Attribute attribute : attributes) {
for (Attribute attribute : this.attributes) {
if (model.hasDefined(attribute.getDefinition().getName())) {
return DiscardPolicy.REJECT_AND_WARN;
}
Expand Down

0 comments on commit a76b793

Please sign in to comment.