public abstract class IdleTimeout
extends java.lang.Object
This implementation is optimised that timeout operations are not cancelled on every operation. Rather timeout are allowed to expire and a check is then made to see when the last operation took place. If the idle timeout has not expired, the timeout is rescheduled for the earliest possible time a timeout could occur.
Modifier and Type | Field and Description |
---|---|
private long |
_idleTimeout |
private long |
_idleTimestamp |
private Scheduler |
_scheduler |
private java.util.concurrent.atomic.AtomicReference<Scheduler.Task> |
_timeout |
private static Logger |
LOG |
Constructor and Description |
---|
IdleTimeout(Scheduler scheduler) |
Modifier and Type | Method and Description |
---|---|
private void |
activate() |
protected long |
checkIdleTimeout() |
private void |
deactivate() |
long |
getIdleFor() |
long |
getIdleTimeout() |
Scheduler |
getScheduler() |
private void |
idleCheck() |
abstract boolean |
isOpen()
This abstract method should be called to check if idle timeouts
should still be checked.
|
void |
notIdle()
This method should be called when non-idle activity has taken place.
|
void |
onClose() |
protected abstract void |
onIdleExpired(java.util.concurrent.TimeoutException timeout)
This abstract method is called when the idle timeout has expired.
|
void |
onOpen() |
private void |
scheduleIdleTimeout(long delay) |
void |
setIdleTimeout(long idleTimeout)
Sets the idle timeout in milliseconds.
|
private static final Logger LOG
private final Scheduler _scheduler
private final java.util.concurrent.atomic.AtomicReference<Scheduler.Task> _timeout
private volatile long _idleTimeout
private volatile long _idleTimestamp
public IdleTimeout(Scheduler scheduler)
scheduler
- A scheduler used to schedule checks for the idle timeout.public Scheduler getScheduler()
public long getIdleFor()
public long getIdleTimeout()
setIdleTimeout(long)
public void setIdleTimeout(long idleTimeout)
Sets the idle timeout in milliseconds.
A value that is less than or zero disables the idle timeout checks.
idleTimeout
- the idle timeout in millisecondsgetIdleTimeout()
public void notIdle()
private void idleCheck()
private void scheduleIdleTimeout(long delay)
public void onOpen()
private void activate()
public void onClose()
private void deactivate()
protected long checkIdleTimeout()
protected abstract void onIdleExpired(java.util.concurrent.TimeoutException timeout)
timeout
- a TimeoutExceptionpublic abstract boolean isOpen()