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

x33g5p2x  于2022-01-18 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(120)

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

ConcurrentSkipListMap.pollFirstEntry介绍

[英]Removes and returns a key-value mapping associated with the least key in this map, or null if the map is empty. The returned entry does not support the Entry.setValue method.
[中]移除并返回与此映射中最小键关联的键值映射,如果映射为空,则返回null。返回的条目支持该条目。设置值方法。

代码示例

代码示例来源:origin: qunarcorp/qmq

private void removeOldestSnapshot() {
  final Map.Entry<Long, Snapshot<T>> firstEntry = snapshots.pollFirstEntry();
  final File snapshotFile = getSnapshotFile(firstEntry.getValue());
  final boolean success = snapshotFile.delete();
  if (success) {
    LOG.debug("delete snapshot file {} success.", snapshotFile.getAbsolutePath());
  } else {
    LOG.warn("delete snapshot file {} failed.", snapshotFile.getAbsolutePath());
  }
}

代码示例来源:origin: lealone/Lealone

void schedule(Work work) {
  // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to
  // be empty
  // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we
  // find;
  // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are
  // both
  // empty we schedule a new thread
  Map.Entry<Long, SEPWorker> e;
  while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry()))
    if (e.getValue().assign(work, false))
      return;
  if (!work.isStop())
    new SEPWorker(workerId.incrementAndGet(), work, this);
}

代码示例来源:origin: mulesoft/mule

private int trimToMaxSize(int currentSize) {
 if (maxEntries < 0) {
  return currentSize;
 }
 int excess = (currentSize - maxEntries);
 if (excess > 0) {
  while (currentSize > maxEntries) {
   store.pollFirstEntry();
   currentSize--;
  }
  if (logger.isDebugEnabled()) {
   logger.debug("Expired " + excess + " excess entries");
  }
 }
 return excess;
}

代码示例来源:origin: kaazing/gateway

@Override
ConnectFuture pollFirstEntry() {
  Entry<Long, ConnectFuture> entry = connectFutures.pollFirstEntry();
  return entry == null ? null : entry.getValue();
}

代码示例来源:origin: cinchapi/concourse

@Override
public Entry<T> pollFirstEntry() {
  return backing.pollFirstEntry().getValue();
}

代码示例来源:origin: org.mule.tests/mule-tests-unit

private int trimToMaxSize(int currentSize) {
 if (maxEntries < 0) {
  return currentSize;
 }
 int excess = (currentSize - maxEntries);
 if (excess > 0) {
  while (currentSize > maxEntries) {
   store.pollFirstEntry();
   currentSize--;
  }
  if (logger.isDebugEnabled()) {
   logger.debug("Expired " + excess + " excess entries");
  }
 }
 return excess;
}

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

private int trimToMaxSize(int currentSize)
{
  if (maxEntries < 0)
  {
    return 0;
  }
  int excess = (currentSize - maxEntries);
  if (excess > 0)
  {
    while (currentSize > maxEntries)
    {
      store.pollFirstEntry();
      currentSize--;
    }
    if (logger.isDebugEnabled())
    {
      logger.debug("Expired " + excess + " excess entries");
    }
    return excess;
  }
  return 0;
}

代码示例来源:origin: stackoverflow.com

int maxSize = 100;
ConcurrentSkipListMap<String, String> cache = new ConcurrentSkipListMap<>();

// Check if max size is reached before inserting something in it. Make some room for new entry.
while (cache.size() >= maxSize) {
  cache.pollFirstEntry();
}

代码示例来源:origin: org.apache.cassandra/cassandra-all

void schedule(Work work)
{
  // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty
  // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find;
  // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both
  // empty we schedule a new thread
  Map.Entry<Long, SEPWorker> e;
  while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry()))
    if (e.getValue().assign(work, false))
      return;
  if (!work.isStop())
    new SEPWorker(workerId.incrementAndGet(), work, this);
}

代码示例来源:origin: jsevellec/cassandra-unit

void schedule(Work work)
{
  // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty
  // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find;
  // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both
  // empty we schedule a new thread
  Map.Entry<Long, SEPWorker> e;
  while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry()))
    if (e.getValue().assign(work, false))
      return;
  if (!work.isStop())
    new SEPWorker(workerId.incrementAndGet(), work, this);
}

代码示例来源:origin: com.strapdata.cassandra/cassandra-all

void schedule(Work work)
{
  // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty
  // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find;
  // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both
  // empty we schedule a new thread
  Map.Entry<Long, SEPWorker> e;
  while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry()))
    if (e.getValue().assign(work, false))
      return;
  if (!work.isStop())
    new SEPWorker(workerId.incrementAndGet(), work, this);
}

代码示例来源:origin: com.facebook.presto.cassandra/cassandra-server

void schedule(Work work)
{
  // we try to hand-off our work to the spinning queue before the descheduled queue, even though we expect it to be empty
  // all we're doing here is hoping to find a worker without work to do, but it doesn't matter too much what we find;
  // we atomically set the task so even if this were a collection of all workers it would be safe, and if they are both
  // empty we schedule a new thread
  Map.Entry<Long, SEPWorker> e;
  while (null != (e = spinning.pollFirstEntry()) || null != (e = descheduled.pollFirstEntry()))
    if (e.getValue().assign(work, false))
      return;
  if (!work.isStop())
    new SEPWorker(workerId.incrementAndGet(), work, this);
}

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

public V firstEntry(boolean poll) {
  Map.Entry<CacheKey, V> entry = null;
  if (poll) {
    entry = evictionQueue.pollFirstEntry();
    if (entry != null) {
      int result = size.addAndGet(-1);
      assert result >=0 || !isSuspectSize(size);
    }
  } else {
    entry = evictionQueue.firstEntry();
  }
  if (entry != null) {
    return entry.getValue();
  }
  return null;
}

代码示例来源:origin: kontalk/tigase-server

/**
 * Method description
 *
 */
public synchronized void sendWaitingPackets() {
  if (log.isLoggable(Level.FINEST)) {
    log.finest("trying to send waiting packets from queue of " + getSid() +
        " after timer = " + waiting_packets.size());
  }
  if (!waiting_packets.isEmpty()) {
    Map.Entry<BoshTask, BoshIOService> entry = connections.pollFirstEntry();
    if (entry == null) {
      return;
    }
    BoshIOService serv = entry.getValue();
    sendBody(serv, null);
  }
}

代码示例来源:origin: org.teiid/teiid-engine

public V firstEntry(boolean poll) {
  Map.Entry<CacheKey, V> entry = null;
  if (poll) {
    entry = evictionQueue.pollFirstEntry();
    if (entry != null) {
      int result = size.addAndGet(-1);
      assert result >=0 || !isSuspectSize(size);
    }
  } else {
    entry = evictionQueue.firstEntry();
  }
  if (entry != null) {
    return entry.getValue();
  }
  return null;
}

代码示例来源:origin: org.jboss.teiid/teiid-engine

public V firstEntry(boolean poll) {
  Map.Entry<CacheKey, V> entry = null;
  if (poll) {
    entry = evictionQueue.pollFirstEntry();
    if (entry != null) {
      int result = size.addAndGet(-1);
      assert result >=0 || !isSuspectSize(size);
    }
  } else {
    entry = evictionQueue.firstEntry();
  }
  if (entry != null) {
    return entry.getValue();
  }
  return null;
}

代码示例来源:origin: kontalk/tigase-server

private void retireAllOldConnections() {
  while (connections.size() > 1) {
    Map.Entry<BoshTask, BoshIOService> entry = connections.pollFirstEntry();
    handler.cancelTask(entry.getKey());
    BoshIOService serv = entry.getValue();
    if (serv != null) {
      retireConnectionService(serv);
    } else {
      if (log.isLoggable(Level.WARNING)) {
        log.warning("connections queue size is greater than 1 but poll returns null" +
            getSid());
      }
    }
  }
}

代码示例来源:origin: cinchapi/concourse

@Override
public java.util.Map.Entry<K, V> pollFirstEntry() {
  long[] stamps = grabAllSegmentWriteLocks();
  try {
    sort();
    return sorted.pollFirstEntry();
  }
  finally {
    releaseSegmentLocks(stamps);
  }
}

代码示例来源:origin: com.github.vladimir-bukhtoyarov/rolling-metrics

@Override
protected void updateConcurrently(long timestamp, long latencyTime, TimeUnit latencyUnit, Supplier<String> descriptionSupplier, long latencyNanos) {
  Map.Entry<PositionKey, Position> firstEntry = positions.firstEntry();
  PositionKey firstKey = firstEntry.getKey();
  Position firstPosition = firstEntry.getValue();
  long currentPhase = phaseSequence.get();
  if (!isNeedToAdd(timestamp, latencyNanos, firstPosition, firstKey, currentPhase)) {
    return;
  }
  Position position = new Position(timestamp, latencyTime, latencyUnit, descriptionSupplier, maxDescriptionLength);
  if (positions.putIfAbsent(new PositionKey(currentPhase, position), position) == null) {
    positions.pollFirstEntry();
  }
}

代码示例来源:origin: vladimir-bukhtoyarov/rolling-metrics

@Override
protected void updateConcurrently(long timestamp, long latencyTime, TimeUnit latencyUnit, Supplier<String> descriptionSupplier, long latencyNanos) {
  Map.Entry<PositionKey, Position> firstEntry = positions.firstEntry();
  PositionKey firstKey = firstEntry.getKey();
  Position firstPosition = firstEntry.getValue();
  long currentPhase = phaseSequence.get();
  if (!isNeedToAdd(timestamp, latencyNanos, firstPosition, firstKey, currentPhase)) {
    return;
  }
  Position position = new Position(timestamp, latencyTime, latencyUnit, descriptionSupplier, maxDescriptionLength);
  if (positions.putIfAbsent(new PositionKey(currentPhase, position), position) == null) {
    positions.pollFirstEntry();
  }
}

相关文章

ConcurrentSkipListMap类方法