java.util.ArrayDeque.pollFirst()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(8.6k)|赞(0)|评价(0)|浏览(141)

本文整理了Java中java.util.ArrayDeque.pollFirst()方法的一些代码示例,展示了ArrayDeque.pollFirst()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ArrayDeque.pollFirst()方法的具体详情如下:
包路径:java.util.ArrayDeque
类名称:ArrayDeque
方法名:pollFirst

ArrayDeque.pollFirst介绍

暂无

代码示例

代码示例来源:origin: robovm/robovm

/**
 * Retrieves and removes the head of the queue represented by this deque
 * (in other words, the first element of this deque), or returns
 * <tt>null</tt> if this deque is empty.
 *
 * <p>This method is equivalent to {@link #pollFirst}.
 *
 * @return the head of the queue represented by this deque, or
 *         <tt>null</tt> if this deque is empty
 */
public E poll() {
  return pollFirst();
}

代码示例来源:origin: real-logic/aeron

private int runTasks(final ArrayDeque<Runnable> taskQueue)
{
  int workCount = 0;
  Runnable runnable;
  while (null != (runnable = taskQueue.pollFirst()))
  {
    runnable.run();
    workCount += 1;
  }
  return workCount;
}

代码示例来源:origin: apache/ignite

/** {@inheritDoc} */
  @Override public E pollFirst() {
    E e = super.pollFirst();
    items.remove(e);
    return e;
  }
}

代码示例来源:origin: robovm/robovm

/**
 * @throws NoSuchElementException {@inheritDoc}
 */
public E removeFirst() {
  E x = pollFirst();
  if (x == null)
    throw new NoSuchElementException();
  return x;
}

代码示例来源:origin: apache/incubator-druid

private void tryEmitAndDrainAllFailedBuffers()
{
 for (FailedBuffer failedBuffer; (failedBuffer = failedBuffers.pollFirst()) != null; ) {
  sendWithRetries(failedBuffer.buffer, failedBuffer.length, failedBuffer.eventCount, false);
  approximateFailedBuffersCount.decrementAndGet();
 }
}

代码示例来源:origin: google/ExoPlayer

@Override
public SubtitleInputBuffer dequeueInputBuffer() throws SubtitleDecoderException {
 Assertions.checkState(dequeuedInputBuffer == null);
 if (availableInputBuffers.isEmpty()) {
  return null;
 }
 dequeuedInputBuffer = availableInputBuffers.pollFirst();
 return dequeuedInputBuffer;
}

代码示例来源:origin: wildfly/wildfly

/**
 * Get the next queued response, waiting if necessary.  The returned response <em>must</em> be closed.
 *
 * @return the queued response
 * @throws InterruptedException if the thread was interrupted while waiting
 */
public Response getResponse() throws InterruptedException {
  final ArrayDeque<Response> responses = this.responses;
  synchronized (responses) {
    if (cancelled) {
      throw new IllegalStateException("Waiting on cancelled response");
    }
    while (responses.isEmpty()) {
      responses.wait();
    }
    return responses.pollFirst();
  }
}

代码示例来源:origin: apache/incubator-druid

private void tryEmitOneFailedBuffer()
{
 FailedBuffer failedBuffer = failedBuffers.peekFirst();
 if (failedBuffer != null) {
  if (sendWithRetries(failedBuffer.buffer, failedBuffer.length, failedBuffer.eventCount, false)) {
   // Remove from the queue of failed buffer.
   failedBuffers.pollFirst();
   approximateFailedBuffersCount.decrementAndGet();
   // Don't add the failed buffer back to the buffersToReuse queue here, because in a situation when we were not
   // able to emit events for a while we don't have a way to discard buffers that were used to accumulate events
   // during that period, if they are added back to buffersToReuse. For instance it may result in having 100
   // buffers in rotation even if we need just 2.
  }
 }
}

代码示例来源:origin: redisson/redisson

private void sendAllValid(final ChannelHandlerContext ctx, final PerChannel perChannel, final long now) {
    // write operations need synchronization
    synchronized (perChannel) {
      ToSend newToSend = perChannel.messagesQueue.pollFirst();
      for (; newToSend != null; newToSend = perChannel.messagesQueue.pollFirst()) {
        if (newToSend.relativeTimeAction <= now) {
          long size = newToSend.size;
          trafficCounter.bytesRealWriteFlowControl(size);
          perChannel.queueSize -= size;
          queuesSize.addAndGet(-size);
          ctx.write(newToSend.toSend, newToSend.promise);
          perChannel.lastWriteTimestamp = now;
        } else {
          perChannel.messagesQueue.addFirst(newToSend);
          break;
        }
      }
      if (perChannel.messagesQueue.isEmpty()) {
        releaseWriteSuspended(ctx);
      }
    }
    ctx.flush();
  }
}

代码示例来源:origin: google/agera

@Nullable
@Override
public Object poll() {
 return store.pollFirst();
}

代码示例来源:origin: redisson/redisson

private void sendAllValid(final ChannelHandlerContext ctx, final long now) {
  // write order control
  synchronized (this) {
    ToSend newToSend = messagesQueue.pollFirst();
    for (; newToSend != null; newToSend = messagesQueue.pollFirst()) {
      if (newToSend.relativeTimeAction <= now) {
        long size = calculateSize(newToSend.toSend);
        trafficCounter.bytesRealWriteFlowControl(size);
        queueSize -= size;
        ctx.write(newToSend.toSend, newToSend.promise);
      } else {
        messagesQueue.addFirst(newToSend);
        break;
      }
    }
    if (messagesQueue.isEmpty()) {
      releaseWriteSuspended(ctx);
    }
  }
  ctx.flush();
}

代码示例来源:origin: redisson/redisson

private void sendAllValid(final ChannelHandlerContext ctx, final PerChannel perChannel, final long now) {
  // write operations need synchronization
  synchronized (perChannel) {
    ToSend newToSend = perChannel.messagesQueue.pollFirst();
    for (; newToSend != null; newToSend = perChannel.messagesQueue.pollFirst()) {
      if (newToSend.relativeTimeAction <= now) {
        long size = newToSend.size;
        trafficCounter.bytesRealWriteFlowControl(size);
        perChannel.channelTrafficCounter.bytesRealWriteFlowControl(size);
        perChannel.queueSize -= size;
        queuesSize.addAndGet(-size);
        ctx.write(newToSend.toSend, newToSend.promise);
        perChannel.lastWriteTimestamp = now;
      } else {
        perChannel.messagesQueue.addFirst(newToSend);
        break;
      }
    }
    if (perChannel.messagesQueue.isEmpty()) {
      releaseWriteSuspended(ctx);
    }
  }
  ctx.flush();
}

代码示例来源:origin: wildfly/wildfly

public void close() {
  synchronized (lock) {
    safeClose(sourceChannel);
    ByteBuffer buffer;
    while ((buffer = queue.pollFirst()) != null) {
      ByteBufferPool.free(buffer);
    }
  }
}

代码示例来源:origin: apache/flink

private void completeBufferedSequence() throws IOException {
  LOG.debug("{}: Finished feeding back buffered data.", inputGate.getOwningTaskName());
  currentBuffered.cleanup();
  currentBuffered = queuedBuffered.pollFirst();
  if (currentBuffered != null) {
    currentBuffered.open();
    numQueuedBytes -= currentBuffered.size();
  }
}

代码示例来源:origin: wildfly/wildfly

private void sendAllValid(final ChannelHandlerContext ctx, final long now) {
  // write order control
  synchronized (this) {
    ToSend newToSend = messagesQueue.pollFirst();
    for (; newToSend != null; newToSend = messagesQueue.pollFirst()) {
      if (newToSend.relativeTimeAction <= now) {
        long size = calculateSize(newToSend.toSend);
        trafficCounter.bytesRealWriteFlowControl(size);
        queueSize -= size;
        ctx.write(newToSend.toSend, newToSend.promise);
      } else {
        messagesQueue.addFirst(newToSend);
        break;
      }
    }
    if (messagesQueue.isEmpty()) {
      releaseWriteSuspended(ctx);
    }
  }
  ctx.flush();
}

代码示例来源:origin: org.apache.lucene/lucene-core

private void rewriteToBlockSize(int targetBlockBits) {
 assert targetBlockBits <= maxBitsPerBlock;
 // We copy over data blocks to an output with one-larger block bit size.
 // We also discard references to blocks as we're copying to allow GC to
 // clean up partial results in case of memory pressure.
 ByteBuffersDataOutput cloned = new ByteBuffersDataOutput(targetBlockBits, targetBlockBits, blockAllocate, NO_REUSE);
 ByteBuffer block;
 while ((block = blocks.pollFirst()) != null) {
  block.flip();
  cloned.writeBytes(block);
  if (blockReuse != NO_REUSE) {
   blockReuse.accept(block);
  }
 }
 assert blocks.isEmpty();
 this.blockBits = targetBlockBits;
 blocks.addAll(cloned.blocks);
}

代码示例来源:origin: apache/ignite

/**
 * @param type Message type.
 * @param customMsg Custom message.
 * @return {@code True} if should not process message.
 */
private boolean skipMessage(int type, @Nullable DiscoveryCustomMessage customMsg) {
  if (type == EVT_DISCOVERY_CUSTOM_EVT) {
    assert customMsg != null && customMsg.id() != null : customMsg;
    if (rcvdCustomMsgs.contains(customMsg.id())) {
      if (log.isDebugEnabled())
        log.debug("Received duplicated custom message, will ignore [msg=" + customMsg + "]");
      return true;
    }
    rcvdCustomMsgs.addLast(customMsg.id());
    while (rcvdCustomMsgs.size() > DISCOVERY_HISTORY_SIZE)
      rcvdCustomMsgs.pollFirst();
  }
  return false;
}

代码示例来源:origin: real-logic/aeron

private int sendQueuedResponses()
{
  int workCount = 0;
  if (!controlPublication.isConnected())
  {
    state = State.INACTIVE;
  }
  else
  {
    if (!queuedResponses.isEmpty())
    {
      if (sendFirst(queuedResponses))
      {
        queuedResponses.pollFirst();
        activityDeadlineMs = Aeron.NULL_VALUE;
        workCount++;
      }
      else if (activityDeadlineMs == Aeron.NULL_VALUE)
      {
        activityDeadlineMs = epochClock.time() + connectTimeoutMs;
      }
      else if (hasGoneInactive())
      {
        state = State.INACTIVE;
      }
    }
  }
  return workCount;
}

代码示例来源:origin: google/ExoPlayer

SubtitleOutputBuffer outputBuffer = availableOutputBuffers.pollFirst();
outputBuffer.addFlag(C.BUFFER_FLAG_END_OF_STREAM);
releaseInputBuffer(inputBuffer);
 SubtitleOutputBuffer outputBuffer = availableOutputBuffers.pollFirst();
 outputBuffer.setContent(inputBuffer.timeUs, subtitle, Format.OFFSET_SAMPLE_RELATIVE);
 releaseInputBuffer(inputBuffer);

代码示例来源:origin: apache/ignite

/**
 * @param rcvCnt Number of messages received by remote node.
 */
public void ackReceived(long rcvCnt) {
  if (log.isDebugEnabled())
    log.debug("Handle acknowledgment [acked=" + acked + ", rcvCnt=" + rcvCnt +
      ", msgReqs=" + msgReqs.size() + ']');
  while (acked < rcvCnt) {
    SessionWriteRequest req = msgReqs.pollFirst();
    assert req != null : "Missed message [rcvCnt=" + rcvCnt +
      ", acked=" + acked +
      ", desc=" + this + ']';
    if (req.ackClosure() != null)
      req.ackClosure().apply(null);
    req.onAckReceived();
    acked++;
  }
}

相关文章