@Override public int compare(final AbstractSession<?> o1, final AbstractSession<?> o2) { final long endTimestamp1 = o1.getEndTimestamp(); final long endTimestamp2 = o2.getEndTimestamp(); if (endTimestamp1 == endTimestamp2) { return 0; } else if (endTimestamp1 < endTimestamp2) { return -1; } else { return 1; } }
/** * Creates a new abstract session with the given session ID. * * @param sessionId * The session ID for this session */ public AbstractSession(final String sessionId) { this.sessionId = sessionId; this.containedTraces = new TreeSet<T>(this.getOrderComparator()); }
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; } } }
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 dispatchCompletedSession(final T session, final String outputPortName) { session.setCompleted(); this.deliver(outputPortName, session); }