Example #1
0
 /**
  * Constructs a thread-pool stage.
  *
  * @param name the stage name
  * @param handler the event handler to execute
  * @param executor the external executor service provided for consistent tracking, it is
  *     recommended to create executor with {@link DefaultThreadFactory}
  * @param errorHandler the error handler
  */
 @Inject
 public ThreadPoolStage(
     @Parameter(StageName.class) final String name,
     @Parameter(StageHandler.class) final EventHandler<T> handler,
     @Parameter(StageExecutorService.class) final ExecutorService executor,
     @Parameter(ErrorHandler.class) final EventHandler<Throwable> errorHandler) {
   super(name);
   this.handler = handler;
   this.errorHandler = errorHandler;
   this.numThreads = 0;
   this.executor = executor;
   StageManager.instance().register(this);
 }
Example #2
0
 /**
  * Constructs a single thread stage.
  *
  * @param name the stage name
  * @param handler the event handler to execute
  * @param capacity the queue capacity
  */
 @Inject
 public SingleThreadStage(
     @Parameter(StageName.class) final String name,
     @Parameter(StageHandler.class) final EventHandler<T> handler,
     @Parameter(Capacity.class) final int capacity) {
   super(name);
   queue = new ArrayBlockingQueue<T>(capacity);
   interrupted = new AtomicBoolean(false);
   thread = new Thread(new Producer<T>(name, queue, handler, interrupted));
   thread.setName("SingleThreadStage<" + name + ">");
   thread.start();
   StageManager.instance().register(this);
 }
Example #3
0
 /**
  * Constructs a thread-pool stage.
  *
  * @param name the stage name
  * @param handler the event handler to execute
  * @param numThreads the number of threads to use
  * @param errorHandler the error handler
  * @throws WakeRuntimeException
  */
 @Inject
 public ThreadPoolStage(
     @Parameter(StageName.class) final String name,
     @Parameter(StageHandler.class) final EventHandler<T> handler,
     @Parameter(NumberOfThreads.class) final int numThreads,
     @Parameter(ErrorHandler.class) final EventHandler<Throwable> errorHandler) {
   super(name);
   this.handler = handler;
   this.errorHandler = errorHandler;
   if (numThreads <= 0) {
     throw new WakeRuntimeException(
         name + " numThreads " + numThreads + " is less than or equal to 0");
   }
   this.numThreads = numThreads;
   this.executor = Executors.newFixedThreadPool(numThreads, new DefaultThreadFactory(name));
   StageManager.instance().register(this);
 }