java.util.concurrent.LinkedBlockingDeque.add()方法的使用及代码示例

x33g5p2x  于2022-01-23 转载在 其他  
字(6.9k)|赞(0)|评价(0)|浏览(200)

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

LinkedBlockingDeque.add介绍

[英]Inserts the specified element at the end of this deque unless it would violate capacity restrictions. When using a capacity-restricted deque, it is generally preferable to use method #offer(Object).

This method is equivalent to #addLast.
[中]在此数据块末尾插入指定的元素,除非它违反容量限制。当使用容量受限设备时,通常最好使用方法#offer(Object)。
此方法相当于#addLast。

代码示例

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

@Override
  public void operationComplete(Future<? super Void> future) throws Exception {
    isList.add(NettyInputStream.END_OF_INPUT_ERROR);
  }
});

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

@Override
  public void operationComplete(Future<? super Void> future) throws Exception {
    isList.add(NettyInputStream.END_OF_INPUT_ERROR);
  }
});

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

@Override
  public void operationComplete(Future<? super Void> future) throws Exception {
    isList.add(NettyInputStream.END_OF_INPUT_ERROR);
  }
});

代码示例来源:origin: testcontainers/testcontainers-java

@Override
public void accept(OutputFrame frame) {
  frames.add(frame);
}

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

protected void addWorkUnit (WorkUnit wu) {
  this.workUnits.add(wu);
 }
}

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

@Override
  public void exceptionCaught(ChannelHandlerContext ctx, final Throwable cause) {
    if (asyncConnectorCallback != null) {
      connector.executorService.execute(new Runnable() {
        @Override
        public void run() {
          asyncConnectorCallback.failure(cause);
        }
      });
    }
    future.completeExceptionally(cause);
    isList.add(NettyInputStream.END_OF_INPUT_ERROR);
  }
}

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

private void wakeupCnxn() {
  if (needSasl.get()) {
    waitSasl.release();
  }
  outgoingQueue.add(WakeupPacket.getInstance());
}

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

/**
 * Reconstitutes this deque from a stream (that is, deserializes it).
 */
private void readObject(java.io.ObjectInputStream s)
  throws java.io.IOException, ClassNotFoundException {
  s.defaultReadObject();
  count = 0;
  first = null;
  last = null;
  // Read in all elements and place in queue
  for (;;) {
    @SuppressWarnings("unchecked")
    E item = (E)s.readObject();
    if (item == null)
      break;
    add(item);
  }
}

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

/**
 * Process incoming data.
 */
private void onDataRead(ChannelHandlerContext ctx, Http2DataFrame data) throws Exception {
  isList.add(new ByteBufInputStream(data.content()));
  if (data.isEndStream()) {
    isList.add(NettyInputStream.END_OF_INPUT);
  }
}

代码示例来源:origin: alibaba/nacos

public void addUpdatedDom2Queue(String namespaceId, String domName, String serverIP, String checksum) {
  lock.lock();
  try {
    toBeUpdatedDomsQueue.offer(new DomainKey(namespaceId, domName, serverIP, checksum), 5, TimeUnit.MILLISECONDS);
  } catch (Exception e) {
    toBeUpdatedDomsQueue.poll();
    toBeUpdatedDomsQueue.add(new DomainKey(namespaceId, domName, serverIP, checksum));
    Loggers.SRV_LOG.error("[DOMAIN-STATUS] Failed to add domain to be updatd to queue.", e);
  } finally {
    lock.unlock();
  }
}

代码示例来源:origin: prestodb/presto

@Override
public synchronized void close()
{
  if (!closed.compareAndSet(false, true)) {
    return;
  }
  for (HttpPageBufferClient client : allClients.values()) {
    closeQuietly(client);
  }
  pageBuffer.clear();
  systemMemoryContext.setBytes(0);
  bufferRetainedSizeInBytes = 0;
  if (pageBuffer.peekLast() != NO_MORE_PAGES) {
    checkState(pageBuffer.add(NO_MORE_PAGES), "Could not add no more pages marker");
  }
  notifyBlockedCallers();
}

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

@Override
public void close() throws IOException {
  if (queue.size() == CAPACITY) {
    boolean offer = false;
    try {
      offer = queue.offer(VOID, WRITE_TIMEOUT, TimeUnit.MILLISECONDS);
    } catch (InterruptedException e) {
      // ignore.
    }
    if (!offer) {
      queue.removeLast();
      queue.add(VOID);
    }
  } else {
    queue.add(VOID);
  }
  ctx.flush();
}

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

/**
 * Ingest metric in snapshot data structure while maintaining interval {@inheritDoc}
 *
 * @see azkaban.metric.IMetricEmitter#reportMetric(azkaban.metric.IMetric)
 */
@Override
public void reportMetric(final IMetric<?> metric) throws MetricException {
 final String metricName = metric.getName();
 if (!this.historyListMapping.containsKey(metricName)) {
  logger.info("First time capturing metric: " + metricName);
  this.historyListMapping.put(metricName, new LinkedBlockingDeque<>());
 }
 synchronized (this.historyListMapping.get(metricName)) {
  logger.debug("Ingesting metric: " + metricName);
  this.historyListMapping.get(metricName).add(new InMemoryHistoryNode(metric.getValue()));
  cleanUsingTime(metricName, this.historyListMapping.get(metricName).peekLast().getTimestamp());
 }
}

代码示例来源:origin: prestodb/presto

checkState(pageBuffer.add(NO_MORE_PAGES), "Could not add no more pages marker");

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

void runInIoThread(Runnable task) {
  this.taskRunQueue.add(task);
  try {
    getIoThread().execute(taskRunQueueRunnable);
  } catch (RejectedExecutionException e) {
    //thread is shutting down
    ShutdownFallbackExecutor.execute(taskRunQueueRunnable);
  }
}

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

@Override
public void channelRead(final ChannelHandlerContext ctx, Object msg) {
  if (msg instanceof HttpRequest) {
    final HttpRequest req = (HttpRequest) msg;
    if (HttpUtil.is100ContinueExpected(req)) {
      ctx.write(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
    }
    isList.clear(); // clearing the content - possible leftover from previous request processing.
    final ContainerRequest requestContext = createContainerRequest(ctx, req);
    requestContext.setWriter(new NettyResponseWriter(ctx, req, container));
    // must be like this, since there is a blocking read from Jersey
    container.getExecutorService().execute(new Runnable() {
      @Override
      public void run() {
        container.getApplicationHandler().handle(requestContext);
      }
    });
  }
  if (msg instanceof HttpContent) {
    HttpContent httpContent = (HttpContent) msg;
    ByteBuf content = httpContent.content();
    if (content.isReadable()) {
      isList.add(new ByteBufInputStream(content));
    }
    if (msg instanceof LastHttpContent) {
      isList.add(NettyInputStream.END_OF_INPUT);
    }
  }
}

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

@Override
public void dataArrived(QueryDataBatch result, ConnectionThrottle throttle) {
 lastReceivedBatchNumber++;
 logger.debug( "[#{}] Received query data batch #{}: {}.",
        instanceId, lastReceivedBatchNumber, result );
 // If we're in a closed state, just release the message.
 if (closed) {
  result.release();
  // TODO:  Revisit member completed:  Is ResultListener really completed
  // after only one data batch after being closed?
  completed = true;
  return;
 }
 // We're active; let's add to the queue.
 batchQueue.add(result);
 // Throttle server if queue size has exceed threshold.
 if (batchQueue.size() > batchQueueThrottlingThreshold ) {
  if ( startThrottlingIfNot( throttle ) ) {
   logger.debug( "[#{}] Throttling started at queue size {}.",
          instanceId, batchQueue.size() );
  }
 }
 releaseIfFirst();
}

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

digestList.add(digest);

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

closing = true;
outgoingQueue.add(packet);

代码示例来源:origin: jankotek/mapdb

/**
 * containsAll(c) is true when c contains a subset of elements
 */
public void testContainsAll() {
  BlockingDeque q = populatedDeque(SIZE);
  LinkedBlockingDeque p = new LinkedBlockingDeque(SIZE);
  for (int i = 0; i < SIZE; ++i) {
    assertTrue(q.containsAll(p));
    assertFalse(p.containsAll(q));
    p.add(new Integer(i));
  }
  assertTrue(p.containsAll(q));
}

相关文章

微信公众号

最新文章

更多