Exemplo n.º 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);
 }
Exemplo n.º 2
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);
 }