public void engage() {
    // starts WorkerPool workers in separate thread(s)
    RingBuffer<DemoEvent> ringBuf = workerPool.start(execService);

    // publish lots of events
    for (int i = 0; i < 5 * NUM_WORKERS; i++) {
      long seq = ringBuf.next();
      ringBuf.get(seq).setProcessId(i);
      ringBuf.publish(seq);
      // try it with and without the sleep
      // try { Thread.sleep(33); } catch (Exception e) { }
    }

    // wait until all published events are processed, then stop the workers
    workerPool.drainAndHalt();
  }
示例#2
0
 @Override
 public void halt() {
   workerPool.halt();
 }
示例#3
0
 @Override
 public void start(final Executor executor) {
   workerPool.start(executor);
 }
示例#4
0
 @Override
 public Sequence[] getSequences() {
   return workerPool.getWorkerSequences();
 }