java.util.concurrent.BlockingQueue#toArray ( )源码实例Demo

下面列出了java.util.concurrent.BlockingQueue#toArray ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: disruptor   文件: DisruptorBlockingQueueTest.java
@Test
public void testToArray() {

    final int cap = 100;
    final BlockingQueue<Integer> dbq = new DisruptorBlockingQueue<Integer>(cap);

    for(int i=0; i<cap; i++) {

        Assert.assertTrue(dbq.offer(Integer.valueOf(i)));
    }

    Object[] objArray = dbq.toArray();
    for(int i=0; i<cap; i++) {
        Assert.assertEquals(objArray[i], Integer.valueOf(i));
    }

}
 
源代码2 项目: disruptor   文件: PushPullBlockingQueueTest.java
@Test
public void testToArray() {

    final int cap = 100;
    final BlockingQueue<Integer> dbq = new PushPullBlockingQueue<Integer>(cap);

    for(int i=0; i<cap; i++) {

        dbq.offer(Integer.valueOf(i));
    }

    Object[] objArray = dbq.toArray();
    for(int i=0; i<cap; i++) {
        Assert.assertEquals(objArray[i], Integer.valueOf(i));
    }

}
 
源代码3 项目: HBase.MCC   文件: HTableStats.java
public static long getRollingAvg(BlockingQueue<Long> queue) {
  Long[] times = queue.toArray(new Long[0]);
  
  long totalTime = 0;
  long totalCount = 0;
  
  for (Long time: times) {
    if (time > -1) {
      totalCount++;
      totalTime += time;
    }
  }
  if (totalCount != 0) {
    return totalTime/totalCount;
  } else {
    return 0;
  }
}
 
源代码4 项目: uavstack   文件: QueueWorkerThreadPoolExecutor.java
/**
 * Drains the task queue into a new list, normally using drainTo. But if the queue is a DelayQueue or any other kind
 * of queue for which poll or drainTo may fail to remove some elements, it deletes them one by one.
 */
private List<Runnable> drainQueue() {

    BlockingQueue<Runnable> q = workQueue;
    List<Runnable> taskList = new ArrayList<Runnable>();
    q.drainTo(taskList);
    if (!q.isEmpty()) {
        for (Runnable r : q.toArray(new Runnable[0])) {
            if (q.remove(r))
                taskList.add(r);
        }
    }
    return taskList;
}
 
源代码5 项目: ThreadDebugger   文件: ExceedWait.java
public List<Runnable> drainExceedQueue() {
    BlockingQueue<Runnable> q = mExceedQueue;
    ArrayList<Runnable> taskList = new ArrayList<>();
    q.drainTo(taskList);
    if (!q.isEmpty()) {
        for (Runnable r : q.toArray(new Runnable[0])) {
            if (q.remove(r))
                taskList.add(r);
        }
    }
    return taskList;
}
 
源代码6 项目: disruptor   文件: MPMCBlockingQueueTest.java
@Test
public void testToArray() {

    final int cap = 100;
    final BlockingQueue<Integer> dbq = new MPMCBlockingQueue<>(cap);

    for(int i=0; i<cap; i++) {
        Assert.assertTrue(dbq.offer(Integer.valueOf(i)));
    }

    Object[] objArray = dbq.toArray();
    for(int i=0; i<cap; i++) {
        Assert.assertEquals(Integer.valueOf(i), objArray[i]);
    }
}
 
源代码7 项目: disruptor   文件: MPMCBlockingQueueTest.java
@Test
public void testTypeToArray() {
    final int cap = 100;
    final BlockingQueue<Integer> dbq = new MPMCBlockingQueue<>(cap);

    for(int i=0; i<cap; i++) {
        dbq.offer(Integer.valueOf(i));
    }

    Integer[] t = new Integer[cap];
    dbq.toArray(t);
    for(int i=0; i<cap; i++) {
        Assert.assertEquals(Integer.valueOf(i), t[i]);
    }
}
 
源代码8 项目: disruptor   文件: DisruptorBlockingQueueTest.java
@Test
public void testTypeToArray() {
    final int cap = 100;
    final BlockingQueue<Integer> dbq = new DisruptorBlockingQueue<Integer>(cap);

    for(int i=0; i<cap; i++) {
        dbq.offer(Integer.valueOf(i));
    }

    Integer[] t = new Integer[cap];
    dbq.toArray(t);
    for(int i=0; i<cap; i++) {
        Assert.assertEquals(Integer.valueOf(i), t[i]);
    }
}
 
源代码9 项目: disruptor   文件: PushPullBlockingQueueTest.java
@Test
public void testTypeToArray() {
    final int cap = 100;
    final BlockingQueue<Integer> dbq = new PushPullBlockingQueue<Integer>(cap);

    for(int i=0; i<cap; i++) {
        dbq.offer(Integer.valueOf(i));
    }

    Integer[] t = new Integer[cap];
    dbq.toArray(t);
    for(int i=0; i<cap; i++) {
        Assert.assertEquals(Integer.valueOf(i), t[i]);
    }
}
 
源代码10 项目: HBase.MCC   文件: HTableStats.java
public static long getRollingMax(BlockingQueue<Long> queue) {
  Long[] times = queue.toArray(new Long[0]);
  
  long maxTime = 0;
  
  for (Long time: times) {
    if (time > maxTime) {
      maxTime = time;
    }
  }
  
  return maxTime;
  
}
 
源代码11 项目: database   文件: ChunkedRunningQuery.java
/**
 * Return a summary of the work queue for the operators in this query
 * (non-blocking).
 * 
 * @return A map whose keys are the operator identifiers and whose values
 *         provide summary statistics for the work queue(s) for those
 *         operators.
 *         <p>
 *         Note: For a cluster, there is one work queue per (operator,shard)
 *         pair.
 */
protected Map<Integer/* bopId */, QueueStats> getQueueStats() {
    
    final Map<Integer, QueueStats> map = new HashMap<Integer, QueueStats>();

    for (Map.Entry<BSBundle, BlockingQueue<IChunkMessage<IBindingSet>>> e : operatorQueues
            .entrySet()) {

        final BSBundle bundle = e.getKey();

        final BlockingQueue<IChunkMessage<IBindingSet>> queue = e
                .getValue();

        @SuppressWarnings("unchecked")
        final IChunkMessage<IBindingSet>[] chunks = queue
                .toArray(new IChunkMessage[0]);

        if (chunks.length == 0)
            continue;

        final Integer bopId = Integer.valueOf(bundle.bopId);

        QueueStats stats = map.get(bopId);

        if (stats == null) {

            map.put(bopId, stats = new QueueStats());

        }
        
        stats.shardSet.add(bundle.shardId);
        
        for (IChunkMessage<IBindingSet> msg : chunks) {

            stats.chunkCount++;

            stats.solutionCount += msg.getSolutionCount();

        }

    }

    return map;
    
}