java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
net.i2p.i2ptunnel.I2PTunnelHTTPServer.BodyWatchdog
- All Implemented Interfaces:
Runnable
- Enclosing class:
I2PTunnelHTTPServer
Watchdog for an async (detached) body handoff. After
I2PTunnelHTTPServer.handOffBody(ThreadPoolExecutor, I2PTunnelHTTPServer.Sender, String) queues the Server-to-Client Sender and the handler thread returns, nothing supervises the pool worker: a browser that stops reading pins it in a blocked write indefinitely (socket soTimeout bounds reads only). This periodic event polls the Sender's last-read stamp and, once no progress is made for I2PTunnelHTTPServer.ioStallTimeoutMs, closes the streams to unblock the worker and runs the idempotent finish so the connection is torn down exactly once. Polling is every 5s, the SimpleTimer2 minimum; detection therefore lands within one poll of the stall window.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final I2PTunnelHTTPServer.SenderThe sender copying the request body.private final InputStreamThe browser's input stream.private final OutputStreamThe browser's output stream.private final RunnableCallback run when the copy finishes.private final AtomicBooleanSet when the copy is finished.private final LogLogger for this copy.private final InputStreamThe web server's input stream.private final OutputStreamThe web server's output stream.private static final longSimpleTimer2 rejects periods below 5s.Fields inherited from class SimpleTimer2.TimedEvent
_state, DEFAULT_FUZZModifier and TypeFieldDescriptionprotected SimpleTimer2.TimedEventStateState of the current event.protected static final intDefault fuzz threshold in milliseconds.Constructor Summary
ConstructorsConstructorDescriptionBodyWatchdog(I2PTunnelHTTPServer.Sender body, AtomicBoolean finished, Runnable finish, InputStream browserin, OutputStream browserout, InputStream serverin, OutputStream serverout, Log log) Watches a stalled response body and aborts the connection.Method Summary
All MethodsMethods inherited from class SimpleTimer2.TimedEvent
cancel, forceReschedule, reschedule, reschedule, run, schedule, setFuzz, setPool, toStringModifier and TypeMethodDescriptionbooleancancel()Cancel the timed event.voidforceReschedule(long timeoutMs) Always use the new time - ignores fuzz.voidreschedule(long timeoutMs) Use the earliest of the new time and the old time May be called from within timeReached(), but schedule() is better there.voidreschedule(long timeoutMs, boolean useEarliestTime) May be called from within timeReached(), but schedule() is better there.voidrun()voidschedule(long timeoutMs) Schedule this event.voidsetFuzz(int fuzz) Reschedule threshold in ms.voidsetPool(SimpleTimer2 pool) Timer pool for this event.toString()Timer summary for log messages.
Field Details
POLL_MS
private static final long POLL_MSSimpleTimer2 rejects periods below 5s.- See Also:
_body
The sender copying the request body._finished
Set when the copy is finished._finish
Callback run when the copy finishes._browserin
The browser's input stream._browserout
The browser's output stream._serverin
The web server's input stream._serverout
The web server's output stream._log
Logger for this copy.
Constructor Details
BodyWatchdog
BodyWatchdog(I2PTunnelHTTPServer.Sender body, AtomicBoolean finished, Runnable finish, InputStream browserin, OutputStream browserout, InputStream serverin, OutputStream serverout, Log log) Watches a stalled response body and aborts the connection.- Parameters:
body- the detached Server-to-Client Sender being supervisedfinished- request-wide finish-once flagfinish- idempotent finish to run once a stall is confirmedbrowserin- browser-side request stream; may be nullbrowserout- browser-side response stream; may be nullserverin- I2P-side response body stream; may be nullserverout- I2P-side request stream; may be nulllog- may be null
Method Details
timeReached
public void timeReached()Description copied from class:SimpleTimer2.TimedEventCalled when this event's scheduled time arrives. Must NOT block. For periodic events, call schedule(period) at the end to self-reschedule.- Specified by:
timeReachedin classSimpleTimer2.TimedEvent