Skip to content

Commit

Permalink
Cleanup redundant ModelNode allocations in ProxyOperation
Browse files Browse the repository at this point in the history
  • Loading branch information
rhusar committed Oct 25, 2018
1 parent b8d786e commit 60a86a7
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 14 deletions.
Expand Up @@ -469,7 +469,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat
int waitTime = WAIT_TIME.resolveModelAttribute(context, operation).asInt();

boolean success = service.stop(waitTime, TimeUnit.SECONDS);
context.getResult().get(ProxyOperationExecutor.SESSION_DRAINING_COMPLETE).set(success);
context.getResult().get(SESSION_DRAINING_COMPLETE).set(success);

context.completeStep(new OperationContext.RollbackHandler() {
@Override
Expand Down Expand Up @@ -510,7 +510,7 @@ public void execute(OperationContext context, ModelNode operation) throws Operat

try {
boolean success = service.stopContext(webHost, webContext, waitTime, TimeUnit.SECONDS);
context.getResult().get(ProxyOperationExecutor.SESSION_DRAINING_COMPLETE).set(success);
context.getResult().get(SESSION_DRAINING_COMPLETE).set(success);
} catch (IllegalArgumentException e) {
throw new OperationFailedException(ModClusterLogger.ROOT_LOGGER.contextOrHostNotFound(webHost, webContext));
}
Expand All @@ -529,6 +529,8 @@ public void handleRollback(OperationContext context, ModelNode operation) {
},
;

static final String SESSION_DRAINING_COMPLETE = "session-draining-complete";

private static ServiceController<?> getService(OperationContext context) throws OperationFailedException {
PathAddress proxyAddress = LegacyMetricOperationsRegistration.translateProxyPath(context);
ServiceName serviceName = ProxyConfigurationResourceDefinition.Capability.SERVICE.getServiceName(proxyAddress);
Expand Down
Expand Up @@ -38,7 +38,6 @@
import org.jboss.as.controller.OperationDefinition;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.SimpleOperationDefinitionBuilder;
import org.jboss.as.controller.descriptions.ModelDescriptionConstants;
import org.jboss.dmr.ModelNode;
import org.jboss.dmr.ModelType;
import org.jboss.modcluster.ModClusterServiceMBean;
Expand Down Expand Up @@ -99,7 +98,7 @@ public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operat
result.add(entry.getValue());
}
}
return new ModelNode().set(result);
return result;
}

return null;
Expand All @@ -121,7 +120,7 @@ public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operat
for (InetSocketAddress address : addresses) {
result.add(address.getHostName() + ":" + address.getPort());
}
return new ModelNode().set(result);
return result;
}

return null;
Expand All @@ -147,7 +146,7 @@ public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operat
result.add(entry.getValue());
}
}
return new ModelNode().set(result);
return result;
}

return null;
Expand All @@ -172,15 +171,15 @@ public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operat
public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ModClusterServiceMBean service) {
boolean enabled = service.enable();

return new ModelNode().get(ModelDescriptionConstants.RESULT).set(enabled);
return new ModelNode(enabled);
}
},
DISABLE("disable") {
@Override
public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operation, ModClusterServiceMBean service) {
boolean disabled = service.disable();

return new ModelNode().get(ModelDescriptionConstants.RESULT).set(disabled);
return new ModelNode(disabled);
}
},
STOP("stop") {
Expand All @@ -194,7 +193,7 @@ public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operat
int waitTime = WAIT_TIME.resolveModelAttribute(expressionResolver, operation).asInt();

boolean success = service.stop(waitTime, TimeUnit.SECONDS);
return new ModelNode().get(ProxyOperationExecutor.SESSION_DRAINING_COMPLETE).set(success);
return new ModelNode(success);
}
},

Expand Down Expand Up @@ -232,7 +231,7 @@ public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operat

try {
boolean disabled = service.disableContext(virtualHost, webContext);
return new ModelNode().get(ModelDescriptionConstants.RESULT).set(disabled);
return new ModelNode(disabled);
} catch (IllegalArgumentException e) {
throw new OperationFailedException(ModClusterLogger.ROOT_LOGGER.contextOrHostNotFound(virtualHost, webContext));
}
Expand All @@ -252,7 +251,7 @@ public ModelNode execute(ExpressionResolver expressionResolver, ModelNode operat

try {
boolean success = service.stopContext(virtualHost, webContext, waitTime, TimeUnit.SECONDS);
return new ModelNode().get(ProxyOperationExecutor.SESSION_DRAINING_COMPLETE).set(success);
return new ModelNode(success);
} catch (IllegalArgumentException e) {
throw new OperationFailedException(ModClusterLogger.ROOT_LOGGER.contextOrHostNotFound(virtualHost, webContext));
}
Expand Down
Expand Up @@ -69,9 +69,6 @@ public class ProxyOperationExecutor implements OperationExecutor<ModClusterServi
.setStorageRuntime()
.build();

static final String SESSION_DRAINING_COMPLETE = "session-draining-complete";


@Override
public ModelNode execute(OperationContext context, ModelNode operation, Operation<ModClusterServiceMBean> executable) throws OperationFailedException {
ServiceName serviceName = ProxyConfigurationResourceDefinition.Capability.SERVICE.getDefinition().getCapabilityServiceName(context.getCurrentAddress());
Expand Down

0 comments on commit 60a86a7

Please sign in to comment.