public void add(E e) { if (e == null) throw new NullPointerException(); lock.lock(); try { addElement(e); waitCond.signal(); } finally { lock.unlock(); } }
E[] newObjects = (E[])new Object[capacity]; if (compareTimeouts(objects[tail - 1], elem) <= 0) { } else if (compareTimeouts(objects[head], elem) > 0) { } else { int index = upperBound(head, tail - 1, elem); int newIndex = (index - head); System.arraycopy(objects, head, newObjects, 0, newIndex); if (tail == head || compareTimeouts(objects[tail - 1], elem) <= 0) { } else if (head > 0 && compareTimeouts(objects[head], elem) > 0) { int index = upperBound(head, tail - 1, elem); System.arraycopy(objects, index, objects, index + 1, tail - index); objects[index] = elem;
@edu.umd.cs.findbugs.annotations.SuppressWarnings("WA_AWAIT_NOT_IN_LOOP") public E poll() { lock.lock(); try { if (isEmpty()) { waitCond.await(); return null; } E elem = objects[head]; long nanos = getNanosTimeout(elem); nanos = waitCond.awaitNanos(nanos); return nanos > 0 ? null : removeFirst(); } catch (InterruptedException e) { Thread.currentThread().interrupt(); return null; } finally { lock.unlock(); } }
waitingTimeout.add( new CompletedProcedureCleaner(conf, store, completed, nonceKeysToProcIdsMap));
private int compareTimeouts(final E a, final E b) { long t1 = getNanosTimeout(a); long t2 = getNanosTimeout(b); return (t1 < t2) ? -1 : (t1 > t2) ? 1 : 0; }
private int upperBound(int start, int end, E key) { while (start < end) { int mid = (start + end) >>> 1; E mitem = objects[mid]; int cmp = compareTimeouts(mitem, key); if (cmp > 0) { end = mid; } else { start = mid + 1; } } return start; }
public void join() { boolean interrupted = false; for (int i = 0; i < threads.length; ++i) { try { threads[i].join(); } catch (InterruptedException ex) { interrupted = true; } } if (interrupted) { Thread.currentThread().interrupt(); } completed.clear(); rollbackStack.clear(); procedures.clear(); nonceKeysToProcIdsMap.clear(); waitingTimeout.clear(); runnables.clear(); lastProcId.set(-1); }
public void stop() { if (!running.getAndSet(false)) { return; } LOG.info("Stopping the procedure executor"); runnables.signalAll(); waitingTimeout.signalAll(); }
Preconditions.checkArgument(rollbackStack.isEmpty()); Preconditions.checkArgument(procedures.isEmpty()); Preconditions.checkArgument(waitingTimeout.isEmpty()); Preconditions.checkArgument(runnables.size() == 0);