/**
   * Default restart implementation for an entity.
   *
   * <p>Stops processes if possible, then starts the entity again.
   */
  public void restart(ConfigBag parameters) {
    ServiceStateLogic.setExpectedState(entity(), Lifecycle.STOPPING);

    RestartMachineMode isRestartMachine =
        parameters.get(RestartSoftwareParameters.RESTART_MACHINE_TYPED);
    if (isRestartMachine == null) isRestartMachine = RestartMachineMode.AUTO;
    if (isRestartMachine == RestartMachineMode.AUTO)
      isRestartMachine =
          getDefaultRestartStopsMachine() ? RestartMachineMode.TRUE : RestartMachineMode.FALSE;

    // Calling preStopCustom without a corresponding postStopCustom invocation
    // doesn't look right so use a separate callback pair; Also depending on the arguments
    // stop() could be called which will call the {pre,post}StopCustom on its own.
    DynamicTasks.queue("pre-restart", new PreRestartTask());

    if (isRestartMachine == RestartMachineMode.FALSE) {
      DynamicTasks.queue("stopping (process)", new StopProcessesAtMachineTask());
    } else {
      Map<String, Object> stopMachineFlags = MutableMap.of();
      if (Entitlements.getEntitlementContext() != null) {
        stopMachineFlags.put(
            "tags",
            MutableSet.of(
                BrooklynTaskTags.tagForEntitlement(Entitlements.getEntitlementContext())));
      }
      Task<String> stopTask =
          Tasks.<String>builder()
              .displayName("stopping (machine)")
              .body(new StopMachineTask())
              .flags(stopMachineFlags)
              .build();
      DynamicTasks.queue(stopTask);
    }

    DynamicTasks.queue("starting", new StartInLocationsTask());
    restartChildren(parameters);
    DynamicTasks.queue("post-restart", new PostRestartTask());

    DynamicTasks.waitForLast();
    ServiceStateLogic.setExpectedState(entity(), Lifecycle.RUNNING);
  }