/** * 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); } }
public Election start() { scavengerThread.start(); return this; }
public SingleNodeQueueLedger(Config config) { maxYields = config.maxYields; thread = WorkerThread.builder() .withOptions(new WorkerOptions() .daemon() .withName(SingleNodeQueueLedger.class, Integer.toHexString(System.identityHashCode(this)))) .onCycle(this::cycle) .buildAndStart(); }
public WorkerThread build() { if (onCycle == null) { throw new IllegalStateException("onCycle behaviour not set"); } return new WorkerThread(options, onCycle, onStartup, onShutdown, onUncaughtException); }
public TaskScheduler(String threadName) { executor = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(threadName)) .onCycle(this::cycle) .build(); }
@Override public void attach(MessageHandler handler) { if (handler.getGroupId() != null && ! groups.add(handler.getGroupId())) return; final WorkerThread thread = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(MultiNodeQueueLedger.class, handler.getGroupId())) .onCycle(new NodeWorker(handler, handler.getGroupId(), queue.consumer())) .buildAndStart(); threads.add(thread); }
@Override public Joinable terminate() { scavengerThread.terminate(); return this; }
@Override public boolean join(long timeoutMillis) throws InterruptedException { return executor.join(timeoutMillis); } }
public void start() { executor.start(); }
public MonitorEngine(MonitorAction action, String groupId, MonitorEngineConfig config) { this.groupId = groupId; trackingEnabled = config.isTrackingEnabled(); gcIntervalMillis = config.getGCInterval(); outcomeLifetimeMillis = config.getOutcomeLifetime(); timeoutIntervalMillis = config.getTimeoutInterval(); metadataEnabled = config.isMetadataEnabled(); this.action = action; if (trackingEnabled) { gcThread = WorkerThread.builder() .withOptions(new WorkerOptions() .daemon() .withName(MonitorEngine.class, groupId, "gc", Integer.toHexString(System.identityHashCode(this)))) .onCycle(this::gcCycle) .buildAndStart(); } else { gcThread = null; } timeoutThread = WorkerThread.builder() .withOptions(new WorkerOptions() .daemon() .withName(MonitorEngine.class, groupId, "timeout", Integer.toHexString(System.identityHashCode(this)))) .onCycle(this::timeoutCycle) .buildAndStart(); }
@Override public Joinable terminate() { publishThread.terminate(); return this; }
@Override public boolean join(long timeoutMillis) throws InterruptedException { return scavengerThread.join(timeoutMillis); } }
public Election start() { scavengerThread.start(); return this; }
public ConsumerPipe(ConsumerPipeConfig config, RecordHandler<K, V> handler, String threadName) { this.handler = handler; if (config.isAsync()) { mustExist(threadName, "Thread name cannot be null"); queue = new LinkedBlockingQueue<>(config.getBacklogBatches()); thread = WorkerThread.builder() .withOptions(new WorkerOptions().daemon().withName(threadName)) .onCycle(this::cycle) .buildAndStart(); } else { queue = null; thread = null; } }
@Override public Joinable terminate() { pollerThread.terminate(); return this; }
@Override public boolean join(long timeoutMillis) throws InterruptedException { return pollerThread.join(timeoutMillis); }
public WorkerThread buildAndStart() { final WorkerThread thread = build(); thread.start(); return thread; } }
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(); }
/** * Terminates the scheduler, 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; }