Source:
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final boolean restart = RESTART.resolveModelAttribute(context, operation).asBoolean(); final int timeout = TIMEOUT.resolveModelAttribute(context, operation).asInt(); context.acquireControllerLock(); context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { context.authorize(operation, EnumSet.of(Action.ActionEffect.WRITE_RUNTIME)); context.completeStep(new OperationContext.ResultHandler() { @Override public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) { if(resultAction == OperationContext.ResultAction.KEEP) { final ShutdownAction shutdown = new ShutdownAction(restart); final ServiceRegistry registry = context.getServiceRegistry(false); final ServiceController<SuspendController> suspendControllerServiceController = (ServiceController<SuspendController>) registry.getRequiredService(SuspendController.SERVICE_NAME); final SuspendController suspendController = suspendControllerServiceController.getValue(); OperationListener listener = new OperationListener() { @Override public void suspendStarted() { } @Override public void complete() { suspendController.removeListener(this); shutdown.shutdown(); } @Override public void cancelled() { suspendController.removeListener(this); shutdown.cancel(); } @Override public void timeout() { suspendController.removeListener(this); shutdown.shutdown(); } }; suspendController.suspend(timeout > 0 ? timeout * 1000 : timeout); if(timeout == 0) { shutdown.shutdown(); } } } }); } }, OperationContext.Stage.RUNTIME); context.stepCompleted(); }

Target:
public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { final boolean restart = RESTART.resolveModelAttribute(context, operation).asBoolean(); final int timeout = TIMEOUT.resolveModelAttribute(context, operation).asInt(); context.acquireControllerLock(); context.addStep(new OperationStepHandler() { @Override public void execute(OperationContext context, ModelNode operation) throws OperationFailedException { context.authorize(operation, EnumSet.of(Action.ActionEffect.WRITE_RUNTIME)); context.completeStep(new OperationContext.ResultHandler() { @Override public void handleResult(OperationContext.ResultAction resultAction, OperationContext context, ModelNode operation) { if(resultAction == OperationContext.ResultAction.KEEP) { final ShutdownAction shutdown = new ShutdownAction(restart); final ServiceRegistry registry = context.getServiceRegistry(false); final ServiceController<SuspendController> suspendControllerServiceController = (ServiceController<SuspendController>) registry.getRequiredService(SuspendController.SERVICE_NAME); final SuspendController suspendController = suspendControllerServiceController.getValue(); OperationListener listener = new OperationListener() { @Override public void suspendStarted() { } @Override public void complete() { suspendController.removeListener(this); shutdown.shutdown(); } @Override public void cancelled() { suspendController.removeListener(this); shutdown.cancel(); } @Override public void timeout() { suspendController.removeListener(this); shutdown.shutdown(); } }; suspendController.addListener(listener); suspendController.suspend(timeout > 0 ? timeout * 1000 : timeout); if(timeout == 0) { shutdown.shutdown(); } } } }); } }, OperationContext.Stage.RUNTIME); context.stepCompleted(); }