java.lang.Object
net.i2p.i2ptunnel.I2PTunnelRunner.ResumeBudget
- Enclosing class:
I2PTunnelRunner
Progress-based budget for body-resume cycles. Pure decision state so the
I2PTunnelRunner.resumeIncompleteBody(OutputStream) loop stays thin and tests can pin stall-reset and absolute-cap behaviour without a live transfer.Only consecutive no-progress cycles count against the size-scaled stall cap (I2PTunnelRunner.stallCycleLimit(long); baseline I2PTunnelRunner.MAX_EMPTY_RECONNECT_CYCLES); any forward progress resets that counter. I2PTunnelRunner.totalCycleLimit(long) bounds total attempts regardless of progress so a pathological trickle still terminates.
Constructor Summary
ConstructorsConstructorDescriptionBudget bounded by cycle caps alone, for callers that want the historical behaviour and tests that pin the cycle arithmetic.ResumeBudget(long deadlineMs) Budget bounded by wall clock, so a stalled tunnel cannot spend the sequence, orI2PTunnelRunner.NO_DEADLINEto rely on the cycle caps alone.ResumeBudget(long deadlineMs, Clock clock) When a deadline is actually set (so the cycle-only path costs no clock lookup at all).ResumeBudget(Clock clock) Production constructor: bounds the sequence by wall clock as well as by cycle count.Method Summary
All MethodsModifier and TypeMethodDescription(package private) intStall cycles consumed so far (including the in-flight one).(package private) intTotal resume attempts consumed so far.(package private) voidRefund the last consume's stall charge when a resume attempt failed with a transient status (408/502/503/504) rather than a real stall.(package private) booleantryConsume(long bodyReceived, long contentLength) Consume one resume cycle for the given body progress.
Constructor Details
ResumeBudget
ResumeBudget()Budget bounded by cycle caps alone, for callers that want the historical behaviour and tests that pin the cycle arithmetic.ResumeBudget
ResumeBudget(long deadlineMs) Budget bounded by wall clock, so a stalled tunnel cannot spend the sequence, orI2PTunnelRunner.NO_DEADLINEto rely on the cycle caps alone.- Parameters:
deadlineMs- absolute wall-clock deadline for the whole resume
ResumeBudget
ResumeBudget(Clock clock) Production constructor: bounds the sequence by wall clock as well as by cycle count.- Parameters:
clock- the context clock, used for the deadline only
ResumeBudget
ResumeBudget(long deadlineMs, Clock clock) When a deadline is actually set (so the cycle-only path costs no clock lookup at all).- Parameters:
deadlineMs- absolute wall-clock deadline, orI2PTunnelRunner.NO_DEADLINEclock- clock to read, or null to read the system clock only
Method Details
tryConsume
boolean tryConsume(long bodyReceived, long contentLength) Consume one resume cycle for the given body progress.- Parameters:
bodyReceived- entity-body bytes delivered so farcontentLength- entity Content-Length in bytes, or -1 if unknown; scales both caps- Returns:
- true if another resume attempt may proceed
getStallCycles
int getStallCycles()Stall cycles consumed so far (including the in-flight one).- Returns:
- the number of stall cycles this budget has burned
getTotalCycles
int getTotalCycles()Total resume attempts consumed so far.- Returns:
- the number of resume attempts this budget has burned
refundLast
void refundLast()Refund the last consume's stall charge when a resume attempt failed with a transient status (408/502/503/504) rather than a real stall. A gateway timeout must not eat the empty/stall budget, or the next non-Range retry would be blocked for an unrelated reason.Only the stall charge is refunded. The total count stays consumed so
I2PTunnelRunner.totalCycleLimit(long)remains an absolute cap over ALL attempts; refunding it would let a persistently transient-failing upstream reconnect forever.