Java Code Examples for java.util.concurrent.BlockingQueue#toArray()
The following examples show how to use
java.util.concurrent.BlockingQueue#toArray() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DisruptorBlockingQueueTest.java From disruptor with Apache License 2.0 | 6 votes |
@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)); } }
Example 2
Source File: PushPullBlockingQueueTest.java From disruptor with Apache License 2.0 | 6 votes |
@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)); } }
Example 3
Source File: HTableStats.java From HBase.MCC with Apache License 2.0 | 6 votes |
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; } }
Example 4
Source File: QueueWorkerThreadPoolExecutor.java From uavstack with Apache License 2.0 | 5 votes |
/** * 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; }
Example 5
Source File: ExceedWait.java From ThreadDebugger with Apache License 2.0 | 5 votes |
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; }
Example 6
Source File: MPMCBlockingQueueTest.java From disruptor with Apache License 2.0 | 5 votes |
@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]); } }
Example 7
Source File: MPMCBlockingQueueTest.java From disruptor with Apache License 2.0 | 5 votes |
@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]); } }
Example 8
Source File: DisruptorBlockingQueueTest.java From disruptor with Apache License 2.0 | 5 votes |
@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]); } }
Example 9
Source File: PushPullBlockingQueueTest.java From disruptor with Apache License 2.0 | 5 votes |
@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]); } }
Example 10
Source File: HTableStats.java From HBase.MCC with Apache License 2.0 | 5 votes |
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; }
Example 11
Source File: ChunkedRunningQuery.java From database with GNU General Public License v2.0 | 2 votes |
/** * 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; }