void onTimeout(int hand) { final ReentrantLock lock = m_lock; // If the lock cannot be acquired, which means this notifier is being // cancelled or rescheduled or closed, just skip. if (!lock.tryLock()) return; try { // If this notifier is not in the same timeout sublist, // which means it has been cancelled or rescheduled, // then skip. TimeoutEvent event = m_node.get(); if (event == null || hand != event.getIndex()) return; if (event.getTimeLeft() < 1) { changeState(TimedOut.getInstance()); m_admin.fireTimeout(this); } else m_admin.scheduleNextRound(this); } finally { lock.unlock(); } }
@Override public boolean schedule(TimeoutNotifier notifier, int timeout) { notifier.getTimeoutAdmin().schedule(notifier, timeout); notifier.changeState(Scheduled.getInstance()); return true; }
@Override public void close(TimeoutNotifier notifier) { notifier.getTimeoutAdmin().cancel(notifier); notifier.changeState(Closed.getInstance()); }
@Override public boolean cancel(TimeoutNotifier notifier) { notifier.getTimeoutAdmin().cancel(notifier); notifier.changeState(Unscheduled.getInstance()); return true; }
@Override public void close(TimeoutNotifier notifier) { notifier.changeState(Closed.getInstance()); }
@Override public boolean reset(TimeoutNotifier notifier) { notifier.changeState(Unscheduled.getInstance()); return true; }