DisruptorWizard<MyEvent> dw = new DisruptorWizard<MyEvent>(MyEvent.FACTORY, 32, Executors.newCachedThreadPool()); EventHandler<MyEvent> handler1 = new EventHandler<MyEvent>() { public void onEvent(MyEvent event, boolean endOfBatch) throws Exception { System.out.println("MyEvent=" + event.r); } }; EventHandler<MyEvent> handler2 = new EventHandler<MyEvent>() { public void onEvent(MyEvent event, boolean endOfBatch) throws Exception { System.out.println("MyEvent=" + event.getResult()); } }; dw.handleEventsWith(handler1); dw.after(handler1).handleEventsWith(handler2); RingBuffer ringBuffer = dw.start(); MyEvent event = (MyEvent) ringBuffer.nextEvent(); event.setValue(60); ringBuffer.publish(event); |
SampleExecutor executor = new SampleExecutor(); RingBuffer<MyEvent> ringBuffer = new RingBuffer<MyEvent>(MyEvent.FACTORY, 4, ClaimStrategy.Option.SINGLE_THREADED, WaitStrategy.Option.YIELDING); MyBatchHandler batchHandler = new MyBatchHandler(); DependencyBarrier dependencyBarrier = ringBuffer.newDependencyBarrier(); BatchEventProcessor<MyEvent> batchProcessorFizz = new BatchEventProcessor<MyEvent>(ringBuffer, dependencyBarrier, batchHandler); executor.execute(batchProcessorFizz); MyEvent event = ringBuffer.nextEvent(); event.setValue(60); ringBuffer.publish(event); |