/** * Pops an element from the stack represented by this deque. In other * words, removes and returns the first element of this deque. * * <p>This method is equivalent to {@link #removeFirst()}. * * @return the element at the front of this deque (which is the top * of the stack represented by this deque) * @throws NoSuchElementException {@inheritDoc} */ public E pop() { return removeFirst(); }
/** * Retrieves and removes the head of the queue represented by this deque. * * This method differs from {@link #poll poll} only in that it throws an * exception if this deque is empty. * * <p>This method is equivalent to {@link #removeFirst}. * * @return the head of the queue represented by this deque * @throws NoSuchElementException {@inheritDoc} */ public E remove() { return removeFirst(); }
/** * Triggers the next queued runnable and executes it synchronously. * This method throws an exception if no Runnable is currently queued. */ public void trigger() { final Runnable next; synchronized (queuedRunnables) { next = queuedRunnables.removeFirst(); } if (next != null) { next.run(); } else { throw new IllegalStateException("No runnable available"); } }
@Override public final O dequeueOutputBuffer() throws E { synchronized (lock) { maybeThrowException(); if (queuedOutputBuffers.isEmpty()) { return null; } return queuedOutputBuffers.removeFirst(); } }
public ByteBuffer allocate(int size) { while (!reuse.isEmpty()) { ByteBuffer bb = reuse.removeFirst(); // If we don't have a buffer of exactly the requested size, discard it. if (bb.remaining() == size) { return bb; } } return delegate.apply(size); }
private ExpandingFetchSource popFromStack() { final ExpandingFetchSource last = fetchSourceStack.removeFirst(); log.trace( "Popped fetch owner from stack : " + last ); propertyPathStack.pop(); return last; }
private CollectionReference popFromCollectionStack() { final CollectionReference last = collectionReferenceStack.removeFirst(); log.trace( "Popped collection reference from stack : " + last ); propertyPathStack.pop(); return last; }
/** * Returns a flattened list of Throwables from tree-like CompositeException chain. * @param t the starting throwable * @return the list of Throwables flattened in a depth-first manner */ public static List<Throwable> flatten(Throwable t) { List<Throwable> list = new ArrayList<Throwable>(); ArrayDeque<Throwable> deque = new ArrayDeque<Throwable>(); deque.offer(t); while (!deque.isEmpty()) { Throwable e = deque.removeFirst(); if (e instanceof CompositeException) { CompositeException ce = (CompositeException) e; List<Throwable> exceptions = ce.getExceptions(); for (int i = exceptions.size() - 1; i >= 0; i--) { deque.offerFirst(exceptions.get(i)); } } else { list.add(e); } } return list; }
/** * Returns the queue's next element and removes it, the queue is non-empty. * Otherwise, this method returns null. * * <p>The method throws an {@code IllegalStateException} if the queue is closed. * Checking whether the queue is open and removing the next element is one atomic operation. * * <p>This method never blocks. * * @return The queue's next element, or null, if the queue is empty. * @throws IllegalStateException Thrown, if the queue is closed. */ public E poll() { lock.lock(); try { if (open) { if (elements.size() > 0) { return elements.removeFirst(); } else { return null; } } else { throw new IllegalStateException("queue is closed"); } } finally { lock.unlock(); } }
/** * Returns the next element in the queue. If the queue is empty, this method * waits until at least one element is added. * * <p>The method throws an {@code IllegalStateException} if the queue is closed. * Checking whether the queue is open and removing the next element is one atomic operation. * * @return The next element in the queue, never null. * * @throws IllegalStateException Thrown, if the queue is closed. * @throws InterruptedException Throw, if the thread is interrupted while waiting for an * element to be added. */ public E getElementBlocking() throws InterruptedException { lock.lock(); try { while (open && elements.isEmpty()) { nonEmpty.await(); } if (open) { return elements.removeFirst(); } else { throw new IllegalStateException("queue is closed"); } } finally { lock.unlock(); } }
private void limitFailedBuffersSize() { if (failedBuffers.size() >= config.getBatchQueueSizeLimit()) { failedBuffers.removeFirst(); approximateFailedBuffersCount.decrementAndGet(); droppedBuffers.incrementAndGet(); log.error( "failedBuffers queue size reached the limit [%d], dropping the oldest failed buffer", config.getBatchQueueSizeLimit() ); } }
@Override public final void flush() { synchronized (lock) { flushed = true; skippedOutputBufferCount = 0; if (dequeuedInputBuffer != null) { releaseInputBufferInternal(dequeuedInputBuffer); dequeuedInputBuffer = null; } while (!queuedInputBuffers.isEmpty()) { releaseInputBufferInternal(queuedInputBuffers.removeFirst()); } while (!queuedOutputBuffers.isEmpty()) { queuedOutputBuffers.removeFirst().release(); } } }
/** * Returns a flattened list of Throwables from tree-like CompositeException chain. * @param t the starting throwable * @return the list of Throwables flattened in a depth-first manner */ public static List<Throwable> flatten(Throwable t) { List<Throwable> list = new ArrayList<Throwable>(); ArrayDeque<Throwable> deque = new ArrayDeque<Throwable>(); deque.offer(t); while (!deque.isEmpty()) { Throwable e = deque.removeFirst(); if (e instanceof CompositeException) { CompositeException ce = (CompositeException) e; List<Throwable> exceptions = ce.getExceptions(); for (int i = exceptions.size() - 1; i >= 0; i--) { deque.offerFirst(exceptions.get(i)); } } else { list.add(e); } } return list; }
private void outputPendingMetadataSamples(long sampleTimeUs) { while (!pendingMetadataSampleInfos.isEmpty()) { MetadataSampleInfo sampleInfo = pendingMetadataSampleInfos.removeFirst(); pendingMetadataSampleBytes -= sampleInfo.size; long metadataTimeUs = sampleTimeUs + sampleInfo.presentationTimeDeltaUs; if (timestampAdjuster != null) { metadataTimeUs = timestampAdjuster.adjustSampleTimestamp(metadataTimeUs); } for (TrackOutput emsgTrackOutput : emsgTrackOutputs) { emsgTrackOutput.sampleMetadata( metadataTimeUs, C.BUFFER_FLAG_KEY_FRAME, sampleInfo.size, pendingMetadataSampleBytes, null); } } }
private void updatePlaybackInfo( PlaybackInfo playbackInfo, boolean positionDiscontinuity, @Player.DiscontinuityReason int positionDiscontinuityReason, @Player.TimelineChangeReason int timelineChangeReason, boolean seekProcessed, boolean playWhenReadyChanged) { boolean isRunningRecursiveListenerNotification = !pendingPlaybackInfoUpdates.isEmpty(); pendingPlaybackInfoUpdates.addLast( new PlaybackInfoUpdate( playbackInfo, /* previousPlaybackInfo= */ this.playbackInfo, listeners, trackSelector, positionDiscontinuity, positionDiscontinuityReason, timelineChangeReason, seekProcessed, playWhenReady, playWhenReadyChanged)); // Assign playback info immediately such that all getters return the right values. this.playbackInfo = playbackInfo; if (isRunningRecursiveListenerNotification) { return; } while (!pendingPlaybackInfoUpdates.isEmpty()) { pendingPlaybackInfoUpdates.peekFirst().notifyListeners(); pendingPlaybackInfoUpdates.removeFirst(); } }
public void pop() { pathStack.removeFirst(); PropertyPath newHead = pathStack.peekFirst(); MDC.put( MDC_KEY, extractFullPath( newHead ) ); } }
public void takeOverflow(int takeCount) { MutableInteger headValue = queue.getFirst(); if (headValue.intValue() > -takeCount) { throw new IllegalStateException("Cannot take " + takeCount + " from " + headValue.intValue() + " in DrainOrder Queue head "); } headValue.add(takeCount); if (headValue.intValue() == 0) { queue.removeFirst(); } overflowCounter -= takeCount; }
public void takePrimary(int takeCount) { MutableInteger headValue = queue.getFirst(); // this condition is optimization to avoid redundant conversions of // int -> Integer -> string in hot path if (headValue.intValue() < takeCount) { throw new IllegalStateException("Cannot take " + takeCount + " from " + headValue.intValue() + " in DrainOrder Queue"); } headValue.add(-takeCount); if (headValue.intValue() == 0) { queue.removeFirst(); } }
return null; } else if (!resourceHolderList.isEmpty()) { ResourceHolder<V> holder = resourceHolderList.removeFirst(); if (System.currentTimeMillis() - holder.getLastAccessedTime() > unusedResourceTimeoutMillis) { factory.close(holder.getResource());
pendingCheckpoints.removeFirst(); pendingCheckpoints.removeFirst();