/** * Constructs a thread-pool stage. * * @param handler the event handler to execute * @param executor the external executor service provided * @param errorHandler the error handler */ @Inject public ThreadPoolStage( @Parameter(StageHandler.class) final EventHandler<T> handler, @Parameter(StageExecutorService.class) final ExecutorService executor, @Parameter(ErrorHandler.class) final EventHandler<Throwable> errorHandler) { this(handler.getClass().getName(), handler, executor, errorHandler); }
@Override public void run() { while (true) { try { final U value = queue.take(); handler.onNext(value); SingleThreadStage.this.afterOnNext(); } catch (final InterruptedException e) { if (interrupted.get()) { LOG.log(Level.FINEST, name + " Closing Producer due to interruption"); break; } } catch (final Throwable t) { LOG.log(Level.SEVERE, name + " Exception from event handler", t); throw t; } } }
/** * Constructs a thread-pool stage. * * @param handler the event handler to execute * @param numThreads the number of threads to use * @throws WakeRuntimeException */ @Inject public ThreadPoolStage( @Parameter(StageHandler.class) final EventHandler<T> handler, @Parameter(NumberOfThreads.class) final int numThreads) { this(handler.getClass().getName(), handler, numThreads, null); }
/** * Constructs a single thread stage. * * @param handler the event handler to execute * @param capacity the queue capacity */ @Inject public SingleThreadStage( @Parameter(StageHandler.class) final EventHandler<T> handler, @Parameter(Capacity.class) final int capacity) { this(handler.getClass().getName(), handler, capacity); }