Class PowerActionHandler

java.lang.Object
com.ultikits.ultitools.utils.PowerActionHandler
All Implemented Interfaces:
CloudRequestHandler

final class PowerActionHandler extends Object implements CloudRequestHandler
Handles the ack-first server.power request: a structured stop or restart that never passes through the command blocklist and is allowed only while the operator's ultipanel.capabilities.power-actions switch is on.

The id is recorded and persisted before command.ack is sent, so a redelivered id is acknowledged again but never stops or restarts the server a second time. The result frame is handed to the channel before the pre-shutdown hook runs and before the power action is scheduled, so the panel always learns what happened before the server begins to go down.

Restart is pre-checked against the server's restart-script: Spigot's own restart stops the server when that script is missing, which would turn a requested restart into a stop that nobody asked for. The check therefore answers power_unsupported instead of degrading.

Package-private framework plumbing; not for module use.

Since:
6.3.1
  • Field Details

  • Constructor Details

    • PowerActionHandler

      PowerActionHandler(DedupeLedger ledger, BooleanSupplier powerEnabled, PowerActionHandler.PowerExecutor executor, Runnable preShutdownHook, Consumer<RemoteActionLog.Entry> actionLog)
      Creates the handler.
      Parameters:
      ledger - the session ledger the request id is recorded in before the acknowledgement
      powerEnabled - the operator's power-actions switch, read on every delivery
      executor - schedules the stop or restart and reports whether a restart is possible
      preShutdownHook - runs after the result frame and before the power action is scheduled
      actionLog - receives one allowed or denied entry per delivery, or null to record nothing
  • Method Details

    • handle

      public void handle(CloudRequest request, CloudChannel channel)
      Validates the action, then runs persist-acknowledge-execute. A payload that does not match the contract propagates as invalid_message before anything is recorded.
      Specified by:
      handle in interface CloudRequestHandler
      Parameters:
      request - the parsed request
      channel - the reply channel
    • execute

      private void execute(CloudRequest request, CloudChannel channel, String action)
      Runs once per newly recorded id: the operator switch, then (for a restart) the restart pre-check, then the result, the pre-shutdown hook and the scheduled power action in that order.
    • runPreShutdownHook

      private void runPreShutdownHook(String action)
      A failing hook must not cancel an action the operator asked for: it is logged once and the power action proceeds.
    • schedule

      private void schedule(String action)
      The result frame was already handed to the channel, so a scheduler refusal is reported locally and nothing tries to answer the panel a second time.
    • record

      private void record(RemoteActionLog.Entry entry)
    • actionType

      private static String actionType(String action)