private static void awaitTermination(OperationThread[] operationThreads) { for (OperationThread thread : operationThreads) { try { thread.awaitTermination(TERMINATION_TIMEOUT_SECONDS, SECONDS); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); } } }
public final void shutdown() { shutdown = true; interrupt(); }
public final void awaitTermination(int timeout, TimeUnit unit) throws InterruptedException { join(unit.toMillis(timeout)); } }
private void process(Object task) { try { if (task.getClass() == Packet.class) { process((Packet) task); } else if (task instanceof Operation) { process((Operation) task); } else if (task instanceof PartitionSpecificRunnable) { process((PartitionSpecificRunnable) task); } else if (task instanceof Runnable) { process((Runnable) task); } else if (task instanceof TaskBatch) { process((TaskBatch) task); } else { throw new IllegalStateException("Unhandled task:" + task); } completedTotalCount.inc(); } catch (Throwable t) { errorCount.inc(); inspectOutOfMemoryError(t); logger.severe("Failed to process: " + task + " on: " + getName(), t); } finally { currentRunner = null; } }
private void process(Operation operation) { currentRunner = operationRunner(operation.getPartitionId()); currentRunner.run(operation); completedOperationCount.inc(); }
private void process(TaskBatch batch) { Object task = batch.next(); if (task == null) { completedOperationBatchCount.inc(); return; } try { if (task instanceof Operation) { process((Operation) task); } else if (task instanceof Runnable) { process((Runnable) task); } else { throw new IllegalStateException("Unhandled task: " + task + " from " + batch.taskFactory()); } } finally { queue.add(batch, false); } }
private static void startAll(OperationThread[] operationThreads) { for (OperationThread thread : operationThreads) { thread.start(); } }
private static void shutdownAll(OperationThread[] operationThreads) { for (OperationThread thread : operationThreads) { thread.shutdown(); } }
@Override public void provideMetrics(MetricsRegistry registry) { registry.scanAndRegister(this, "operation.thread[" + getName() + "]"); }
public OperationThread(String name, int threadId, OperationQueue queue, ILogger logger, NodeExtension nodeExtension, boolean priority, ClassLoader configClassLoader) { super(name); setContextClassLoader(configClassLoader); this.queue = queue; this.threadId = threadId; this.logger = logger; this.nodeExtension = nodeExtension; this.priority = priority; }
private void process(Object task) { try { if (task.getClass() == Packet.class) { process((Packet) task); } else if (task instanceof Operation) { process((Operation) task); } else if (task instanceof PartitionSpecificRunnable) { process((PartitionSpecificRunnable) task); } else if (task instanceof Runnable) { process((Runnable) task); } else if (task instanceof TaskBatch) { process((TaskBatch) task); } else { throw new IllegalStateException("Unhandled task:" + task); } completedTotalCount.inc(); } catch (Throwable t) { errorCount.inc(); inspectOutOfMemoryError(t); logger.severe("Failed to process: " + task + " on: " + getName(), t); } finally { currentRunner = null; } }
private void process(Packet packet) throws Exception { currentRunner = operationRunner(packet.getPartitionId()); currentRunner.run(packet); completedPacketCount.inc(); }
private void process(TaskBatch batch) { Object task = batch.next(); if (task == null) { completedOperationBatchCount.inc(); return; } try { if (task instanceof Operation) { process((Operation) task); } else if (task instanceof Runnable) { process((Runnable) task); } else { throw new IllegalStateException("Unhandled task: " + task + " from " + batch.taskFactory()); } } finally { queue.add(batch, false); } }
private static void startAll(OperationThread[] operationThreads) { for (OperationThread thread : operationThreads) { thread.start(); } }
private static void shutdownAll(OperationThread[] operationThreads) { for (OperationThread thread : operationThreads) { thread.shutdown(); } }
@Override public void provideMetrics(MetricsRegistry registry) { registry.scanAndRegister(this, "operation.thread[" + getName() + "]"); }
public OperationThread(String name, int threadId, OperationQueue queue, ILogger logger, NodeExtension nodeExtension, boolean priority, ClassLoader configClassLoader) { super(name); setContextClassLoader(configClassLoader); this.queue = queue; this.threadId = threadId; this.logger = logger; this.nodeExtension = nodeExtension; this.priority = priority; }
private void process(Packet packet) throws Exception { currentRunner = operationRunner(packet.getPartitionId()); currentRunner.run(packet); completedPacketCount.inc(); }
@Override public final void run() { nodeExtension.onThreadStart(this); try { while (!shutdown) { Object task; try { task = queue.take(priority); } catch (InterruptedException e) { continue; } process(task); } } catch (Throwable t) { inspectOutOfMemoryError(t); logger.severe(t); } finally { nodeExtension.onThreadStop(this); } }
private static void awaitTermination(OperationThread[] operationThreads) { for (OperationThread thread : operationThreads) { try { thread.awaitTermination(TERMINATION_TIMEOUT_SECONDS, SECONDS); } catch (InterruptedException ignored) { Thread.currentThread().interrupt(); } } }