public TaskScheduler(String threadName) { executor = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(threadName)) .onCycle(this::cycle) .build(); }
public AsyncReceiver(Consumer<K, V> consumer, int pollTimeoutMillis, String threadName, RecordHandler<K, V> recordHandler, ExceptionHandler exceptionHandler) { this.consumer = consumer; this.pollTimeoutMillis = pollTimeoutMillis; this.recordHandler = recordHandler; this.exceptionHandlerHandler = exceptionHandler; thread = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(threadName)) .onCycle(this::cycle) .onShutdown(this::shutdown) .buildAndStart(); }
@Override public void dispose() { thread.terminate().joinSilently(); } }
@Override public Joinable terminate() { scavengerThread.terminate(); return this; }
@Override public boolean join(long timeoutMillis) throws InterruptedException { return executor.join(timeoutMillis); } }
@Override public void dispose() { Terminator.of(threads).terminate().joinSilently(); } }
@Override public Joinable terminate() { synchronized (terminateLock) { // as flows are created lazily, it's possible that some flows are created after termination of // this container; this flag ensures that new flows are stillborn terminated = true; Terminator.of(createdFlows).terminate(); } return this; }
public Election start() { scavengerThread.start(); return this; }
/** * Waits until this concurrent entity terminates.<p> * * This variant suppresses an {@link InterruptedException} and will re-assert the interrupt * prior to returning. */ default void joinSilently() { joinSilently(0); }
/** * Waits until this concurrent entity terminates. * * @throws InterruptedException If the thread is interrupted. */ default void join() throws InterruptedException { join(0); }
private void handleUncaughtException(Throwable exception) { if (exception != null && ! (exception instanceof InterruptedException)) { onUncaughtException.handle(this, exception); } }
public static Terminator blank() { return new Terminator(); } }
public Flow(FiringStrategy.Factory firingStrategyFactory, String threadName) { executor = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(threadName)) .onCycle(firingStrategyFactory.create(this, tail)) .buildAndStart(); }
@Override public Joinable terminate() { publishThread.terminate(); return this; }
@Override public boolean join(long timeoutMillis) throws InterruptedException { return scavengerThread.join(timeoutMillis); } }
/** * Terminates the flow, shutting down the worker thread and preventing further * task executions. * * @return A {@link Joinable} for the caller to wait on. */ @Override public Joinable terminate() { executor.terminate(); return this; }
@Override public boolean join(long timeoutMillis) throws InterruptedException { return thread.join(timeoutMillis); } }
@Override public Joinable terminate() { scavengerThread.terminate(); return this; }
@Override public boolean join(long timeoutMillis) throws InterruptedException { return pollerThread.join(timeoutMillis); }