/** Start to build a {@code DocBuilder}. */ public DocBuilder() { stack.addLast(base); }
/** * Inserts the specified element at the end of this deque. * * @param e the element to add * @return <tt>true</tt> (as specified by {@link Deque#offerLast}) * @throws NullPointerException if the specified element is null */ public boolean offerLast(E e) { addLast(e); return true; }
/** * Inserts the specified element at the end of this deque. * * <p>This method is equivalent to {@link #addLast}. * * @param e the element to add * @return <tt>true</tt> (as specified by {@link Collection#add}) * @throws NullPointerException if the specified element is null */ public boolean add(E e) { addLast(e); return true; }
@Override public void execute(@Nonnull Runnable command) { synchronized (queuedRunnables) { queuedRunnables.addLast(command); } }
public void reuse(ByteBuffer buffer) { buffer.rewind(); reuse.addLast(buffer); } }
/** {@inheritDoc} */ @Override public void addLast(E e) { if (!items.contains(e)) { super.addLast(e); items.add(e); } }
/** * Adds the element to the queue, or fails with an exception, if the queue is closed. * Checking whether the queue is open and adding the element is one atomic operation. * * @param element The element to add. * @throws IllegalStateException Thrown, if the queue is closed. */ public void add(E element) throws IllegalStateException { requireNonNull(element); lock.lock(); try { if (open) { elements.addLast(element); if (elements.size() == 1) { nonEmpty.signalAll(); } } else { throw new IllegalStateException("queue is closed"); } } finally { lock.unlock(); } }
/** * Tries to add an element to the queue, if the queue is still open. Checking whether the queue * is open and adding the element is one atomic operation. * * <p>Unlike the {@link #add(Object)} method, this method never throws an exception, * but only indicates via the return code if the element was added or the * queue was closed. * * @param element The element to add. * @return True, if the element was added, false if the queue was closes. */ public boolean addIfOpen(E element) { requireNonNull(element); lock.lock(); try { if (open) { elements.addLast(element); if (elements.size() == 1) { nonEmpty.signalAll(); } } return open; } finally { lock.unlock(); } }
/** * Open a new {@link Doc.Level}. * * @param plusIndent the extra indent for the {@link Doc.Level} */ void open(Indent plusIndent) { Doc.Level level = Doc.Level.make(plusIndent); stack.addLast(level); }
/** * @param req Write request. * @return {@code False} if queue limit is exceeded. */ public boolean add(SessionWriteRequest req) { assert req != null; if (!req.skipRecovery()) { if (resendCnt == 0) { msgReqs.addLast(req); sentCnt++; return msgReqs.size() < queueLimit; } else resendCnt--; } return true; }
private void emitLargeEvent(byte[] eventBytes) { byte[] buffer = acquireBuffer(); int bufferOffset = batchingStrategy.writeBatchStart(buffer); System.arraycopy(eventBytes, 0, buffer, bufferOffset, eventBytes.length); bufferOffset += eventBytes.length; bufferOffset = batchingStrategy.writeBatchEnd(buffer, bufferOffset); if (sendWithRetries(buffer, bufferOffset, 1, true)) { buffersToReuse.add(buffer); approximateBuffersToReuseCount.incrementAndGet(); } else { limitFailedBuffersSize(); failedBuffers.addLast(new FailedBuffer(buffer, bufferOffset, 1)); approximateFailedBuffersCount.incrementAndGet(); } }
/** * Add the given {@link StreamElementQueueEntry} to the queue. Additionally, this method * registers a onComplete callback which is triggered once the given queue entry is completed. * * @param streamElementQueueEntry to be inserted * @param <T> Type of the stream element queue entry's result */ private <T> void addEntry(StreamElementQueueEntry<T> streamElementQueueEntry) { assert(lock.isHeldByCurrentThread()); queue.addLast(streamElementQueueEntry); streamElementQueueEntry.onComplete( (StreamElementQueueEntry<T> value) -> { try { onCompleteHandler(value); } catch (InterruptedException e) { // we got interrupted. This indicates a shutdown of the executor LOG.debug("AsyncBufferEntry could not be properly completed because the " + "executor thread has been interrupted.", e); } catch (Throwable t) { operatorActions.failOperator(new Exception("Could not complete the " + "stream element queue entry: " + value + '.', t)); } }, executor); }
@Override public final void queueInputBuffer(I inputBuffer) throws E { synchronized (lock) { maybeThrowException(); Assertions.checkArgument(inputBuffer == dequeuedInputBuffer); queuedInputBuffers.addLast(inputBuffer); maybeNotifyDecodeLoop(); dequeuedInputBuffer = null; } }
@Override public void snapshotState(FunctionSnapshotContext context) throws Exception { Preconditions.checkState(this.checkpointedState != null, "The " + getClass().getSimpleName() + " has not been properly initialized."); if (LOG.isDebugEnabled()) { LOG.debug("{} checkpointing: Messages: {}, checkpoint id: {}, timestamp: {}", idsForCurrentCheckpoint, context.getCheckpointId(), context.getCheckpointTimestamp()); } pendingCheckpoints.addLast(new Tuple2<>(context.getCheckpointId(), idsForCurrentCheckpoint)); idsForCurrentCheckpoint = new HashSet<>(64); this.checkpointedState.clear(); this.checkpointedState.add(SerializedCheckpointData.fromDeque(pendingCheckpoints, idSerializer)); }
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(); } }
@Override void submitWrite(final ChannelHandlerContext ctx, final Object msg, final long size, final long delay, final long now, final ChannelPromise promise) { final ToSend newToSend; // write order control synchronized (this) { if (delay == 0 && messagesQueue.isEmpty()) { trafficCounter.bytesRealWriteFlowControl(size); ctx.write(msg, promise); return; } newToSend = new ToSend(delay + now, msg, promise); messagesQueue.addLast(newToSend); queueSize += size; checkWriteSuspend(ctx, delay, queueSize); } final long futureNow = newToSend.relativeTimeAction; ctx.executor().schedule(new Runnable() { @Override public void run() { sendAllValid(ctx, futureNow); } }, delay, TimeUnit.MILLISECONDS); }
} else { limitFailedBuffersSize(); failedBuffers.addLast(new FailedBuffer(batch.buffer, bufferEndOffset, eventCount)); approximateFailedBuffersCount.incrementAndGet();
deque.addLast(new Tuple2<Long, Set<T>>(checkpoint.checkpointId, ids));
public void putPrimary(Integer eventCount) { totalPuts += eventCount; if ((queue.peekLast() == null) || queue.getLast().intValue() < 0) { queue.addLast(new MutableInteger(eventCount)); } else { queue.getLast().add(eventCount); } }
public void putOverflow(Integer eventCount) { totalPuts += eventCount; if ((queue.peekLast() == null) || queue.getLast().intValue() > 0) { queue.addLast(new MutableInteger(-eventCount)); } else { queue.getLast().add(-eventCount); } overflowCounter += eventCount; }