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

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

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

LinkedBlockingDeque.removeLast介绍

暂无

代码示例

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

@Override
protected void doRollback() {
 int takes = takeList.size();
 synchronized (queueLock) {
  Preconditions.checkState(queue.remainingCapacity() >= takeList.size(),
    "Not enough space in memory channel " +
    "queue to rollback takes. This should never happen, please report");
  while (!takeList.isEmpty()) {
   queue.addFirst(takeList.removeLast());
  }
  putList.clear();
 }
 putByteCounter = 0;
 takeByteCounter = 0;
 queueStored.release(takes);
 channelCounter.setChannelSize(queue.size());
}

代码示例来源: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: apache/flume

synchronized (queue) {
 while (!takeList.isEmpty()) {
  Preconditions.checkState(queue.addHead(takeList.removeLast()),
    "Queue add failed, this shouldn't be able to happen "
      + channelNameDescriptor);

代码示例来源:origin: apache/uima-uimaj

@Override
public MultiThreadInfo removeLast() {
 MultiThreadInfo e = super.removeLast();
 System.out.println(x(e, "removing Last"));
 return e;
}

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

public class AutoDiscardingDeque<E> extends LinkedBlockingDeque<E> {

  public AutoDiscardingDeque() {
    super();
  }

  public AutoDiscardingDeque(int capacity) {
    super(capacity);
  }

  @Override
  public synchronized boolean offerFirst(E e) {
    if (remainingCapacity() == 0) {
      removeLast();
    }
    super.offerFirst(e);
    return true;
  }
}

代码示例来源:origin: pinterest/pinlater

public synchronized void recordSample(String shardName, boolean success) {
 ImmutableMap<String, ShardState> shardHealthMap = shardHealthMapRef.get();
 ShardState shardState = shardHealthMap.get(shardName);
 if (shardState.healthSamples.remainingCapacity() == 0) {
  shardState.numSuccessesInWindow -= shardState.healthSamples.removeLast();
 }
 int successVal = success ? 1 : 0;
 shardState.numSuccessesInWindow += successVal;
 shardState.healthSamples.addFirst(successVal);
}

代码示例来源:origin: com.netflix.dyno/dyno-core

private void addNewBucket(long timestamp) {
  
  bucketCreateCount.incrementAndGet();
  
  Bucket  newBucket = new Bucket(timestamp);
  queue.removeLast();
  queue.addFirst(newBucket);
}

代码示例来源:origin: org.mobicents.servers.jainslee.core/common

/**
 * Callback for {@link SleeStateJMXMonitor}, to learn when SLEE is stopping.
 */
public void sleeShutdown() {
  logger.info("Undeploying all Deployable Units due to SLEE shutdown");    
  // undeploy each DU in reverse order 
  while(!deployedDUs.isEmpty()) {
    DeployableUnit du = deployedDUs.removeLast();
    try {
      uninstallDeployableUnit(du);            
    }
    catch (Exception e) {
      logger.error("Failed to uninstall DU, in SLEE shutdown",e);
    }
  }
}

代码示例来源:origin: apache/uima-uimaj

/**
  * When launching n threads at a barrier, hold up-to-n low priority threads.
  *   may be less than n threads available to hold due to ending state
  *   
  * called under lock
  */
 private void hold_n_low_pri(int nbr_to_hold) {    
  if (run_pool.isEmpty()) return;
  
  if (TRACE) sb.append(", hold_low_pri: removing:");

  for (int i = 0; i < nbr_to_hold; i++) {
//      from_low_prty_run_to_pending_waitf___rr();  //embeded directly here
   MultiThreadInfo ti = run_pool.removeLast();
   if (TRACE) {
    sb.append("t#").append(ti.t_number).append(", ");
   }  
   if (ti.isPendingLowPriWait) {      
    throw new RuntimeException("debug ERROR setting pending wait - found a pending wait in run_pool");          
   }
   ti.setPendingLowPriWait(true); // true: set pending wait in front, eventually
  }         
  if (TRACE) {
   System.out.println(sb.append(" from run_pool"));
  }
 }

代码示例来源:origin: com.twitter.common/stats

@Override
 public Double doSample() {
  T sample = input.read();

  if (samples.remainingCapacity() == 0) {
   sampleSum -= samples.removeLast().doubleValue();
  }

  samples.addFirst(sample);
  sampleSum += sample.doubleValue();

  return sampleSum / samples.size();
 }
}

代码示例来源:origin: numenta/htm.java

/**
 * Inserts the specified item at the head of this {@code Deque}
 * 
 * @param t        the object of type &lt;T&gt; to add
 * @return        flag indicating whether capacity had been reached 
 *                 <em><b>prior</b></em> to this call.
 */
public boolean insert(E t) {
  boolean ret = currentSize == capacity;
  if(ret) {
    backingList.removeLast();
    backingList.addFirst(t);
  }else{
    backingList.addFirst(t);
    currentSize++;
  }
  return ret;
}

代码示例来源:origin: numenta/htm.java

/**
 * Inserts the specified item at the head of this {@code Deque},
 * and if this deque was at capacity prior to this call, the object
 * residing at the tail of this queue is returned, otherwise null
 * is returned
 * 
 * @param t        the object of type &lt;T&gt; to add
 * @return        the object residing at the tail of this queue is 
 *                 returned if previously at capacity, otherwise null 
 *                 is returned
 */
public E pushFirst(E t) {
  E retVal = null;
  boolean ret = currentSize == capacity;
  if(ret) {
    retVal = backingList.removeLast();
    backingList.addFirst(t);
  }else{
    backingList.addFirst(t);
    currentSize++;
  }
  return retVal;
}

代码示例来源:origin: org.apache.distributedlog/distributedlog-common

private double doSample() {
    long newSample = total.sum();
    long newTimestamp = ticker.read();

    double rate = 0;
    if (!samples.isEmpty()) {
      Pair<Long, Long> oldestSample = samples.peekLast();

      double dy = newSample - oldestSample.getRight();
      double dt = newTimestamp - oldestSample.getLeft();

      rate = (dt == 0) ? 0 : (NANOS_PER_SEC * scaleFactor * dy) / dt;
    }

    if (samples.remainingCapacity() == 0) {
      samples.removeLast();
    } else {
      samples.addFirst(Pair.of(newTimestamp, newSample));
    }

    return rate;
  }
}

代码示例来源:origin: com.twitter.common/stats

@Override
public Double doSample() {
 T newSample = inputAccessor.get();
 long newTimestamp = ticker.read();
 double rate = 0;
 if (!samples.isEmpty()) {
  Pair<Long, Double> oldestSample = samples.peekLast();
  double dy = newSample.doubleValue() - oldestSample.getSecond();
  double dt = newTimestamp - oldestSample.getFirst();
  rate = dt == 0 ? 0 : (NANOS_PER_SEC * scaleFactor * dy) / dt;
 }
 if (samples.remainingCapacity() == 0) samples.removeLast();
 samples.addFirst(Pair.of(newTimestamp, newSample.doubleValue()));
 return rate;
}

代码示例来源:origin: mayconbordin/streaminer

public double add(T newSample) {
    long newTimestamp = ticker.read();

    double rate = 0;
    if (!samples.isEmpty()) {
     Pair<Long, Double> oldestSample = samples.peekLast();

     double dy = newSample.doubleValue() - oldestSample.getSecond();
     double dt = newTimestamp - oldestSample.getFirst();
     rate = dt == 0 ? 0 : (NANOS_PER_SEC * scaleFactor * dy) / dt;
    }

    if (samples.remainingCapacity() == 0) samples.removeLast();
    samples.addFirst(new Pair(newTimestamp, newSample.doubleValue()));
  
    return rate;
  }
}

代码示例来源:origin: org.alfresco/alfresco-solrclient-lib

public void add(T add)
{
  while (getDeque().size() > (max - 1))
  {
    getDeque().removeLast();
  }
  getDeque().addFirst(add);
}

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

@Override
protected void doRollback() {
 int takes = takeList.size();
 synchronized (queueLock) {
  Preconditions.checkState(queue.remainingCapacity() >= takeList.size(),
    "Not enough space in memory channel " +
    "queue to rollback takes. This should never happen, please report");
  while (!takeList.isEmpty()) {
   queue.addFirst(takeList.removeLast());
  }
  putList.clear();
 }
 putByteCounter = 0;
 takeByteCounter = 0;
 queueStored.release(takes);
 channelCounter.setChannelSize(queue.size());
}

代码示例来源:origin: com.bazaarvoice.astyanax/astyanax-core

@Override
public boolean check(long currentTimeMillis) {
  int maxCount = config.getConnectionLimiterMaxPendingCount();
  if (maxCount == 0)
    return true;
  // Haven't reached the count limit yet
  if (queue.size() < maxCount) {
    queue.addFirst(currentTimeMillis);
    return true;
  }
  else {
    long last = queue.getLast();
    if (currentTimeMillis - last < config.getConnectionLimiterWindowSize()) {
      return false;
    }
    queue.addFirst(currentTimeMillis);
    queue.removeLast();
    return true;
  }
}

代码示例来源:origin: com.netflix.astyanax/astyanax-core

@Override
public boolean check(long currentTimeMillis) {
  int maxCount = config.getConnectionLimiterMaxPendingCount();
  if (maxCount == 0)
    return true;
  // Haven't reached the count limit yet
  if (queue.size() < maxCount) {
    queue.addFirst(currentTimeMillis);
    return true;
  }
  else {
    long last = queue.getLast();
    if (currentTimeMillis - last < config.getConnectionLimiterWindowSize()) {
      return false;
    }
    queue.addFirst(currentTimeMillis);
    queue.removeLast();
    return true;
  }
}

代码示例来源:origin: apache/uima-uimaj

private void common_to_barrier_waitb(boolean remove_from_run_pool) {
 setBarrierWait(currentBarrier.barrier_wait_pool.size());  // for msg number waiting
 // remove must happen before wakeup - a low pri wakeup gets added to run pool, which might otherwise be full
 if (remove_from_run_pool) remove(run_pool); // remove skipped if pendingWait - already removed
 boolean okToWait = wakeup_hi_or_low();
 addLast(currentBarrier.barrier_wait_pool);
 boolean skipped_wait = ! okToWait;
 if (okToWait) {
  skipped_wait = do_wait();
 } 
 
 if (TRACE) set_thread_state('H');
 
 if (skipped_wait) {
  // these actions normally done by other thread waking this one up
  currentBarrier.barrier_wait_pool.removeLast();  // undo the addLast above
  currentBarrier.maybeResetBarrier();   
 }
}

相关文章

微信公众号

最新文章

更多