/** * Get an expired tasks. This is called instead of {@link #tick()} to obtain the next expired * Task, but without calling it's {@link Task#expire()} or {@link Task#expired()} methods. * * @return the next expired task or null. */ public Task expired() { synchronized (_lock) { long _expiry = _now - _duration; if (_head._next != _head) { Task task = _head._next; if (task._timestamp > _expiry) return null; task.unlink(); task._expired = true; return task; } return null; } }
/** * @param task * @param delay A delay in addition to the default duration of the timeout */ public void schedule(Task task, long delay) { synchronized (_lock) { if (task._timestamp != 0) { task.unlink(); task._timestamp = 0; } task._timeout = this; task._expired = false; task._delay = delay; task._timestamp = _now + delay; Task last = _head._prev; while (last != _head) { if (last._timestamp <= task._timestamp) break; last = last._prev; } last.link(task); } }
/* ------------------------------------------------------------ */ public void tick() { final long expiry = _now - _duration; Task task = null; while (true) { try { synchronized (_lock) { task = _head._next; if (task == _head || task._timestamp > expiry) break; task.unlink(); task._expired = true; task.expire(); } task.expired(); } catch (Throwable th) { LOG.warn(Log.EXCEPTION, th); } } }