/** Handles size after put. */ private void onPut() { cnt.incrementAndGet(); int c; while ((c = cnt.get()) > max) { // Decrement count. if (cnt.compareAndSet(c, c - 1)) { try { K key = firstEntry().getKey(); V val; // Make sure that an element is removed. while ((val = super.remove(firstEntry().getKey())) == null) { // No-op. } assert val != null; GridInClosure2<K, V> lsnr = this.lsnr; // Listener notification. if (lsnr != null) lsnr.apply(key, val); } catch (NoSuchElementException e1) { e1.printStackTrace(); // Should never happen. assert false : "Internal error in grid bounded ordered set."; } } } }
/** {@inheritDoc} */ @Override public int getCurrentHeldJobsNumber() { return heldCnt.get(); }
/** {@inheritDoc} */ @Override public int getCurrentRunningJobsNumber() { return runningCnt.get(); }
/** {@inheritDoc} */ @Override public int getCurrentActiveJobsNumber() { return runningCnt.get() + heldCnt.get(); }
/** {@inheritDoc} */ @Override public int getCurrentWaitJobsNumber() { return waitingCnt.get(); }
/** * Approximate size at this point of time. Note, that unlike {@code size} methods on other {@code * concurrent} collections, this method executes in constant time without traversal of the * elements. * * @return Approximate set size at this point of time. */ @Override public int size() { return cnt.get(); }