private <T extends AbstractSession<?>> void closeAndDispatchAllSessions(final PriorityQueue<T> timeoutQueue, final Map<String, T> openSessions, final String outputPortName) { synchronized (this) { while (!timeoutQueue.isEmpty()) { final T session = timeoutQueue.poll(); openSessions.remove(session.getSessionId()); this.dispatchCompletedSession(session, outputPortName); } } }
private <T extends AbstractSession<?>> void processTimeouts(final long currentTime, final String outputPortName, final PriorityQueue<T> timeoutQueue, final Map<String, T> openSessions) { while (!timeoutQueue.isEmpty()) { final T session = timeoutQueue.peek(); final long currentThinkTime = (currentTime - session.getEndTimestamp()); // The current session timed out if (currentThinkTime > this.maxThinkTime) { timeoutQueue.remove(); openSessions.remove(session.getSessionId()); this.dispatchCompletedSession(session, outputPortName); } else { // If the current session has not timed out, we are done due to the ordering of the queue break; } } }