public void run() { long inactiveMillis = System.currentTimeMillis() - timeoutObject.getLastUse(); if (inactiveMillis >= timeoutObject.getTimeoutPeriod()) { timeoutObject.timeout(); if (Log.isDebug()) Log.getLogger(LOG_CATEGORY).debug("TimeoutManager '" + System.identityHashCode(TimeoutManager.this) + "' has run the timeout task for instance '" + System.identityHashCode(timeoutObject) + "' of type '" + timeoutObject.getClass().getName() + "'. Task queue size: "+ timeoutService.getQueue().size()); } else { // Reschedule timeout and store new Future for cancellation. timeoutObject.setTimeoutFuture(timeoutService.schedule(this, (timeoutObject.getTimeoutPeriod()-inactiveMillis), TimeUnit.MILLISECONDS)); if (Log.isDebug()) Log.getLogger(LOG_CATEGORY).debug("TimeoutManager '" + System.identityHashCode(TimeoutManager.this) + "' has rescheduled a timeout for the active instance '" + System.identityHashCode(timeoutObject) + "' of type '" + timeoutObject.getClass().getName() + "'. Task queue size: "+ timeoutService.getQueue().size()); } } }
System.identityHashCode(timeoutAbstract) + "' of type '" + timeoutAbstract.getClass().getName() + "' that has requested its timeout be cancelled. Task queue size: "+ timeoutService.getQueue().size()); if (Log.isDebug()) Log.getLogger(LOG_CATEGORY).debug("TimeoutManager '" + System.identityHashCode(this) + "' cancelling timeout task for instance '" + System.identityHashCode(timeoutAbstract) + "' of type '" + timeoutAbstract.getClass().getName() + "' that has requested its timeout be cancelled. Task queue size: "+ timeoutService.getQueue().size()); if (timeoutFuture.isDone()) Log.getLogger(LOG_CATEGORY).debug("TimeoutManager '" + System.identityHashCode(this) + "' purged queue of any cancelled or completed tasks. Task queue size: "+ timeoutService.getQueue().size());
/** * Schedule a task to be executed in the future. * * @param t task to be executed at some future time * @return a Future object that enables access to the value(s) returned by the task */ public Future scheduleTimeout(TimeoutCapable t) { Future future = null; if (t.getTimeoutPeriod() > 0) { Runnable timeoutTask = new TimeoutTask(t); future = timeoutService.schedule(timeoutTask, t.getTimeoutPeriod(), TimeUnit.MILLISECONDS); t.setTimeoutFuture(future); if (t instanceof TimeoutAbstractObject) { TimeoutAbstractObject timeoutAbstract = (TimeoutAbstractObject)t; timeoutAbstract.setTimeoutManager(this); timeoutAbstract.setTimeoutTask(timeoutTask); } if (Log.isDebug()) Log.getLogger(LOG_CATEGORY).debug("TimeoutManager '" + System.identityHashCode(this) + "' has scheduled instance '" + System.identityHashCode(t) + "' of type '" + t.getClass().getName() + "' to be timed out in " + t.getTimeoutPeriod() + " milliseconds. Task queue size: "+ timeoutService.getQueue().size()); } return future; }