public final T take() { if (!state) { return queue.poll(); } else { try { return queue.take(); } catch (InterruptedException e) { e.printStackTrace(); } return null; } }
public final void put(T item) { if (!state) { throw new RuntimeException("Putting Forbidden"); } else { try { queue.put(item); } catch (InterruptedException e) { e.printStackTrace(); } } }
static void oneRun(BlockingQueue<Runnable> q, int nThreads, int iters, boolean print) throws Exception { ThreadPoolExecutor pool = new ThreadPoolExecutor(nThreads + 1, Integer.MAX_VALUE, 1L, TimeUnit.SECONDS, q); CountDownLatch done = new CountDownLatch(iters); remaining.set(nThreads - 1); pool.prestartAllCoreThreads(); Task t = new Task(pool, done); long start = System.nanoTime(); pool.execute(t); done.await(); long time = System.nanoTime() - start; if (print) System.out.println("\t: " + LoopHelpers.rightJustify(time / iters) + " ns per task"); q.clear(); Thread.sleep(100); pool.shutdown(); Thread.sleep(100); pool.shutdownNow(); }
public int queueSize() { return changes.size(); }
@edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "RV_RETURN_VALUE_IGNORED_BAD_PRACTICE") private void sendInterruptMarker() { LOG.debug("Sending interrupt marker in order to interrupt feed consumer"); changes.offer(INTERRUPT_MARKER); }
private void checkIfInterrupted(DocumentChange c) throws InterruptedException { if (c == INTERRUPT_MARKER || (!shouldRun && changes.isEmpty())) { throw new InterruptedException(); } }
public DocumentChange next(long timeout, TimeUnit unit) throws InterruptedException { assertRunningState(); DocumentChange c = changes.poll(timeout, unit); checkIfInterrupted(c); return c; }
public DocumentChange poll() throws InterruptedException { assertRunningState(); DocumentChange c = changes.poll(); checkIfInterrupted(c); return c; }
private void handleChange(String line) throws IOException, InterruptedException, JsonParseException, JsonMappingException { changes.put(new StdDocumentChange(OBJECT_MAPPER.readTree(line))); }
public Iterator<T> iterator() { return queue.iterator(); }
public final int size() { return queue.size(); }
public final synchronized void init() { queue.clear(); state = true; }