public class DefaultTimeoutController extends Object implements TimeoutController
TimeoutController implementation.| Modifier and Type | Class and Description |
|---|---|
static interface |
DefaultTimeoutController.TimeoutTask
A timeout task that is invoked when the deadline exceeded.
|
| Constructor and Description |
|---|
DefaultTimeoutController(DefaultTimeoutController.TimeoutTask timeoutTask,
io.netty.channel.EventLoop eventLoop)
Creates a new instance with the specified
DefaultTimeoutController.TimeoutTask and EventLoop. |
DefaultTimeoutController(io.netty.channel.EventLoop eventLoop)
Creates a new instance with the specified
EventLoop. |
| Modifier and Type | Method and Description |
|---|---|
boolean |
cancelTimeout()
Cancels the current timeout scheduled.
|
boolean |
extendTimeout(long adjustmentMillis)
Extends the current timeout by the specified
adjustmentMillis. |
boolean |
isTimedOut()
Returns whether the timeout has been triggered or not.
|
boolean |
resetTimeout(long newTimeoutMillis)
Sets the amount of time that is after the specified
newTimeoutMillis from now. |
boolean |
scheduleTimeout(long timeoutMillis)
Schedules a new timeout with the specified
timeoutMillis. |
void |
setTimeoutTask(DefaultTimeoutController.TimeoutTask timeoutTask)
Sets the
DefaultTimeoutController.TimeoutTask that is invoked when the deadline exceeded. |
Long |
startTimeNanos()
Returns the start time of the initial timeout in nanoseconds
or
null if no timeout was scheduled previously. |
boolean |
timeoutNow()
Trigger the current timeout immediately.
|
public DefaultTimeoutController(DefaultTimeoutController.TimeoutTask timeoutTask, io.netty.channel.EventLoop eventLoop)
DefaultTimeoutController.TimeoutTask and EventLoop.public DefaultTimeoutController(io.netty.channel.EventLoop eventLoop)
EventLoop.public void setTimeoutTask(DefaultTimeoutController.TimeoutTask timeoutTask)
DefaultTimeoutController.TimeoutTask that is invoked when the deadline exceeded.public boolean scheduleTimeout(long timeoutMillis)
timeoutMillis.
If a timeout is scheduled already, this method will not start a new timeout.
Note that the DefaultTimeoutController.TimeoutTask should be set via the setTimeoutTask(TimeoutTask) or
the DefaultTimeoutController(TimeoutTask, EventLoop) before calling this method.
scheduleTimeout in interface TimeoutControllertimeoutMillis - a positive time amount value in milliseconds.true if the timeout is scheduled.
false if the timeout has been scheduled, the timeout has been triggered already
or the DefaultTimeoutController.TimeoutTask.canSchedule() returned false.public boolean extendTimeout(long adjustmentMillis)
adjustmentMillis.
Note that a negative adjustmentMillis reduces the current timeout.
Note that the DefaultTimeoutController.TimeoutTask should be set via the setTimeoutTask(TimeoutTask) or
the DefaultTimeoutController(TimeoutTask, EventLoop) before calling this method.
extendTimeout in interface TimeoutControlleradjustmentMillis - the adjustment of time amount value in milliseconds.true if the current timeout is extended by the specified adjustmentMillis.
false if no timeout was scheduled previously, the timeout has been triggered already
or the DefaultTimeoutController.TimeoutTask.canSchedule() returned false.public boolean resetTimeout(long newTimeoutMillis)
newTimeoutMillis from now.
Note that the DefaultTimeoutController.TimeoutTask should be set via the setTimeoutTask(TimeoutTask) or
the DefaultTimeoutController(TimeoutTask, EventLoop) before calling this method.
resetTimeout in interface TimeoutControllernewTimeoutMillis - the new timeout value in milliseconds. 0 if disabled.true if the current timeout is reset by the specified newTimeoutMillis.
false if the timeout has been triggered already
or the DefaultTimeoutController.TimeoutTask.canSchedule() returned false.public boolean timeoutNow()
timeoutNow in interface TimeoutControllertrue if the current timeout is triggered successfully.
false the timeout has been triggered already
or the DefaultTimeoutController.TimeoutTask.canSchedule() returned false.public boolean cancelTimeout()
TimeoutControllerTimeoutController.scheduleTimeout(long) if the current timeout is cancelled successfully.cancelTimeout in interface TimeoutControllertrue if the current timeout is cancelled.
false if the timeout has been triggered already or no timeout was scheduled previously.public boolean isTimedOut()
TimeoutControllerisTimedOut in interface TimeoutControllertrue if the timeout has been triggered already.
false if the timeout is scheduled now or no timeout was scheduled previously.public Long startTimeNanos()
TimeoutControllernull if no timeout was scheduled previously.startTimeNanos in interface TimeoutControllerCopyright © 2020 LeanCloud. All rights reserved.