java.lang.Object
net.i2p.util.SimpleTimer2.TimedEvent
net.i2p.util.SocketTimeout
- All Implemented Interfaces:
Runnable
Implements one or two timers; one for inactivity, that is reset by
resetTimer(), and optionally, a total time since instantiation, that is configured by setTotalTimeoutPeriod(long).On timer expiration, this will close a provided socket, and/or run a configured job.
Deprecated for external use. It is only used by EepGet, its subclasses, and Syndie. Take care not to break Syndie. The only advantage seems to be a total timeout period, which is the second argument to EepGet.fetch(long, long, long), which is most likely always set to -1.
Not for use by plugins or external applications, subject to change.
Use socket.setsotimeout instead?
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTrue once the timeout will not fire.private RunnableWhat runs when the timeout fires.private longQuiet time past which the socket times out, in ms.private longWhen the socket last carried data.private final longWhen the timeout was created.private SocketThe socket this timeout watches.private longAbsolute deadline past which the socket times out.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
ConstructorsConstructorDescriptionSocketTimeout(long delay) Create a timer that runs a command after a period of socket inactivity.SocketTimeout(Socket socket, long delay) If socket is non-null, or is set later bysetSocket(Socket), it will be closed when the timer expires.Method Summary
All MethodsModifier and TypeMethodDescriptionbooleancancel()Change in return value from void to boolean in 0.9.3 accidentally broke Syndie, sorry.voidCall when there is activity.voidsetInactivityTimeout(long delay) Changes the delay provided in the constructor.voidIf non-null, will be closed when the timer expires.voidIf non-null, will be run when the timer expires.voidsetTotalTimeoutPeriod(long timeoutPeriod) If greater than zero, must be greater than the inactivity timeout.voidCalled when this event's scheduled time arrives.toString()Timer summary for log messages.Methods inherited from class SimpleTimer2.TimedEvent
forceReschedule, reschedule, reschedule, run, schedule, setFuzz, setPoolModifier and TypeMethodDescriptionvoidforceReschedule(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.
Field Details
_targetSocket
The socket this timeout watches._startTime
private final long _startTimeWhen the timeout was created._inactivityDelay
private volatile long _inactivityDelayQuiet time past which the socket times out, in ms._lastActivity
private volatile long _lastActivityWhen the socket last carried data._totalTimeoutTime
private volatile long _totalTimeoutTimeAbsolute deadline past which the socket times out._cancelled
private volatile boolean _cancelledTrue once the timeout will not fire._command
What runs when the timeout fires.
Constructor Details
SocketTimeout
public SocketTimeout(long delay) Create a timer that runs a command after a period of socket inactivity.- Parameters:
delay- The inactivity delay, greater than zero
SocketTimeout
If socket is non-null, or is set later bysetSocket(Socket), it will be closed when the timer expires.- Parameters:
socket- may be nulldelay- The inactivity delay, greater than zero
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
cancel
public boolean cancel()Change in return value from void to boolean in 0.9.3 accidentally broke Syndie, sorry. Recompile Syndie to fix it.- Overrides:
cancelin classSimpleTimer2.TimedEvent- Returns:
- true if the event will not execute, false if already idle/cancelled
setSocket
If non-null, will be closed when the timer expires.- Parameters:
s- the socket to close on expiry, or null to leave the socket alone
resetTimer
public void resetTimer()Call when there is activity.setInactivityTimeout
public void setInactivityTimeout(long delay) Changes the delay provided in the constructor.- Parameters:
delay- greater than zero
setTotalTimeoutPeriod
public void setTotalTimeoutPeriod(long timeoutPeriod) If greater than zero, must be greater than the inactivity timeout.- Parameters:
timeoutPeriod- Time since constructed, or less than or equal to zero to disable
setTimeoutCommand
If non-null, will be run when the timer expires.- Parameters:
job- the command to run on expiry, or null to leave the current command in place
toString
Description copied from class:SimpleTimer2.TimedEventTimer summary for log messages.- Overrides:
toStringin classSimpleTimer2.TimedEvent- Returns:
- the simple class name for log messages