Class RemoteCommandHandler

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

final class RemoteCommandHandler extends Object implements CloudRequestHandler
Handles a validated command.execute through the shared acknowledgement and dedupe gate.

Order is fixed by D-16/D-17/S-52: the envelope id is recorded and persisted in the DedupeLedger first, the request is acknowledged second, and only a first delivery is handed to CommandExecutionManager for main-thread execution. A redelivered id is acknowledged again and never executed again; a persistence failure is logged by AckFirstGate and does not stop the acknowledgement or the first execution.

The capability switch is enforced by AgentMessageRouter before this handler runs; CommandExecutionManager.execute(java.lang.String, java.lang.String, java.util.concurrent.Executor, com.ultikits.ultitools.manager.CommandExecutionManager.CommandResultSink) keeps its own defensive check. Truncation to the negotiated commandOutputMaxBytes happens here because only the channel knows the limits of the accepted welcome; the per-line and per-item schema caps are applied by the manager.

  • Field Details

    • LOGGER

      private static final Logger LOGGER
    • COMMAND

      private static final Pattern COMMAND
    • MAX_DETAIL_CHARS

      private static final int MAX_DETAIL_CHARS
      command.result.payload.details property values and keys maxLength.
      See Also:
    • GSON

      private static final com.google.gson.Gson GSON
    • manager

      private final CommandExecutionManager manager
    • ledger

      private final DedupeLedger ledger
    • mainThread

      private final Executor mainThread
    • disabling

      private final BooleanSupplier disabling
  • Constructor Details

  • Method Details

    • handle

      public void handle(CloudRequest request, CloudChannel channel)
      Description copied from interface: CloudRequestHandler
      Validates the payload and handles it on the dispatching thread. No Bukkit main-thread scheduling is implied; handlers must schedule such work themselves. Synchronous payload validation failures become correlated invalid_message replies; other runtime failures become internal_error without exposing exception text. Asynchronous failures are the handler's responsibility.
      Specified by:
      handle in interface CloudRequestHandler
      Parameters:
      request - the parsed envelope with a defensively copied payload
      channel - the reply channel, which may close during processing
    • fitOutput

      private static RemoteCommandHandler.BoundedOutput fitOutput(List<String> lines, int maxBytes)
      Keeps as many leading output lines as fit the negotiated cap on the serialized array's UTF-8 size, dropping trailing lines. The cap bounds the array itself, not the whole frame.
    • cut

      private static String cut(String text, int maxChars)
    • runUnlessDisabling

      private void runUnlessDisabling(Runnable action, CloudRequest request, CloudChannel channel)
      Runs one step of the acknowledged request unless the plugin is disabling. The check is applied twice — once after the acknowledgement, and once on the main thread, for the window between validation and the dispatch itself (D-16's disabling clause). A command the check stops is answered with a failed command.result (internal_error, the server is shutting down; maintainer decision of 2026-10-26), never left acknowledged without a result. A command that arrives once disabling started never gets here: the router's ShutdownGate answers it the same way.
    • internalError

      private static void internalError(CloudRequest request, CloudChannel channel, RuntimeException failure)