Class SerialRequestWorker
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 Summary
FieldsModifier and TypeFieldDescription(package private) static final intHow many file requests may wait behind the running one.private final ThreadPoolExecutorprivate static final longprivate static final Loggerprivate final BlockingQueue<Runnable> private final ShutdownGate(package private) static final StringThe name of the worker thread. -
Constructor Summary
ConstructorsConstructorDescriptionSerialRequestWorker(int capacity) A worker whose requests are never refused for a shutdown.SerialRequestWorker(int capacity, ShutdownGate shutdown) -
Method Summary
Modifier and TypeMethodDescription(package private) voidclose()Drops the requests that had not started and stops the thread once the running one ends.private static voidhandle(CloudRequestHandler handler, CloudRequest request, CloudChannel channel) private voidhandleUnlessShuttingDown(CloudRequestHandler handler, CloudRequest request, CloudChannel channel) private voidsubmit(CloudRequestHandler handler, CloudRequest request, CloudChannel channel) (package private) CloudRequestHandlerwrap(CloudRequestHandler handler)
-
Field Details
-
THREAD_NAME
The name of the worker thread.- See Also:
-
DEFAULT_CAPACITY
static final int DEFAULT_CAPACITYHow many file requests may wait behind the running one.- See Also:
-
LOGGER
-
IDLE_SECONDS
private static final long IDLE_SECONDS- See Also:
-
queue
-
executor
-
shutdown
-
-
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 1shutdown- the shutdown gate a covered request asks when it starts
-
-
Method Details
-
wrap
- Parameters:
handler- the blocking handler- Returns:
- a handler that queues each request for this worker and returns at once
-
close
void close()Drops the requests that had not started and stops the thread once the running one ends. -
submit
-
handleUnlessShuttingDown
private void handleUnlessShuttingDown(CloudRequestHandler handler, CloudRequest request, CloudChannel channel) -
handle
-