/** * Behaves as {@link LinkedBlockingQueue#take()}, except it will silently * skip all calls which it thinks should be dropped. * * @return the head of this queue * @throws InterruptedException if interrupted while waiting */ @Override public CallRunner take() throws InterruptedException { CallRunner cr; while(true) { if (((double) queue.size() / this.maxCapacity) > lifoThreshold) { numLifoModeSwitches.increment(); cr = queue.takeLast(); } else { cr = queue.takeFirst(); } if (needToDrop(cr)) { numGeneralCallsDropped.increment(); cr.drop(); } else { return cr; } } }
@Override public CallRunner poll() { CallRunner cr; boolean switched = false; while(true) { if (((double) queue.size() / this.maxCapacity) > lifoThreshold) { // Only count once per switch. if (!switched) { switched = true; numLifoModeSwitches.increment(); } cr = queue.pollLast(); } else { switched = false; cr = queue.pollFirst(); } if (cr == null) { return cr; } if (needToDrop(cr)) { numGeneralCallsDropped.increment(); cr.drop(); } else { return cr; } } }