Class SerialRequestWorker

java.lang.Object
com.ultikits.ultitools.utils.SerialRequestWorker

final class SerialRequestWorker extends Object
One dedicated worker thread for the file and server.properties requests of one connection (plan 22-21 fix round). Those handlers do blocking disk I/O -- a files.list of a directory with tens of thousands of entries takes seconds -- so they must not run on the connection's own thread, where every heartbeat, ack and other request would wait behind them.

Order. One thread and a FIFO queue: the wrapped requests are handled one at a time, in arrival order, so a files.write followed by a files.read of the same path still reads what was written.

Bounds. At most capacity requests wait; one more is answered at once with the generic error rate_limited (contract section 6) and never runs. The thread is a daemon named "UltiTools-CloudFiles" and ends when idle.

Failures. The router no longer surrounds a handler that runs here, so this worker answers as the router would: an InvalidFrameException becomes invalid_message (its code), any other runtime failure internal_error without the exception text. The reply goes out through the connection's channel.

Close. close() drops the requests that had not started (their connection is gone, so a reply could not reach the gateway, and an unanswered request is one the gateway reports as timed out -- never run twice) and lets the running one finish. Never waits for the thread.

Shutdown. A request the ShutdownGate covers (files.write, files.delete, properties.update) asks the gate again when it starts here, because it may have been queued before UltiTools#onDisable began: refused, it is answered with its shutting-down failure and never runs; let in, it keeps the gate's permit until it is answered, so onDisable waits for it before the action log closes.

  • Field Details

  • Constructor Details

    • SerialRequestWorker

      SerialRequestWorker(int capacity)
      A worker whose requests are never refused for a shutdown.
      Parameters:
      capacity - how many requests may wait behind the running one; at least 1
    • SerialRequestWorker

      SerialRequestWorker(int capacity, ShutdownGate shutdown)
      Parameters:
      capacity - how many requests may wait behind the running one; at least 1
      shutdown - the shutdown gate a covered request asks when it starts
  • Method Details