/** * <p>Set up custom event processors to handle events from the ring buffer. The Disruptor will * automatically start these processors when {@link Disruptor#start()} is called.</p> * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * @param eventProcessorFactories the event processor factories to use to create the event processors that will process events. * @return a {@link EventHandlerGroup} that can be used to chain dependencies. */ @SafeVarargs public final EventHandlerGroup<T> then(final EventProcessorFactory<T>... eventProcessorFactories) { return handleEventsWith(eventProcessorFactories); }
/** * <p>Set up batch handlers to consume events from the ring buffer. These handlers will only process events * after every {@link EventProcessor} in this group has processed the event.</p> * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * <pre><code>dw.handleEventsWith(A).then(B);</code></pre> * * @param handlers the batch handlers that will process events. * @return a {@link EventHandlerGroup} that can be used to set up a event processor barrier over the created event processors. */ @SafeVarargs public final EventHandlerGroup<T> then(final EventHandler<? super T>... handlers) { return handleEventsWith(handlers); }
@Test(expected = IllegalArgumentException.class) public void shouldThrowExceptionIfHandlerIsNotAlreadyConsuming() throws Exception { disruptor.after(createDelayedEventHandler()).handleEventsWith(createDelayedEventHandler()); }
@Test public void shouldAllowSpecifyingSpecificEventProcessorsToWaitFor() throws Exception { DelayedEventHandler handler1 = createDelayedEventHandler(); DelayedEventHandler handler2 = createDelayedEventHandler(); CountDownLatch countDownLatch = new CountDownLatch(2); EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch); disruptor.handleEventsWith(handler1, handler2); disruptor.after(handler1, handler2).handleEventsWith(handlerWithBarrier); ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2); }
@Test public void shouldWaitOnAllProducersJoinedByAnd() throws Exception { DelayedEventHandler handler1 = createDelayedEventHandler(); DelayedEventHandler handler2 = createDelayedEventHandler(); CountDownLatch countDownLatch = new CountDownLatch(2); EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch); disruptor.handleEventsWith(handler1); final EventHandlerGroup<TestEvent> handler2Group = disruptor.handleEventsWith(handler2); disruptor.after(handler1).and(handler2Group).handleEventsWith(handlerWithBarrier); ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, handler1, handler2); }
@Test public void shouldSupportCustomProcessorsAndHandlersAsDependencies() throws Exception { final DelayedEventHandler delayedEventHandler1 = createDelayedEventHandler(); final DelayedEventHandler delayedEventHandler2 = createDelayedEventHandler(); disruptor.handleEventsWith(delayedEventHandler1); RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer(); CountDownLatch countDownLatch = new CountDownLatch(2); EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch); final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler1).asSequenceBarrier(); final BatchEventProcessor<TestEvent> processor = new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, delayedEventHandler2); disruptor.after(delayedEventHandler1).and(processor).handleEventsWith(handlerWithBarrier); ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler1, delayedEventHandler2); }
/** * <p>Set up custom event processors to handle events from the ring buffer. The Disruptor will * automatically start these processors when {@link Disruptor#start()} is called.</p> * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * @param eventProcessorFactories the event processor factories to use to create the event processors that will process events. * @return a {@link EventHandlerGroup} that can be used to chain dependencies. */ @SafeVarargs public final EventHandlerGroup<T> then(final EventProcessorFactory<T>... eventProcessorFactories) { return handleEventsWith(eventProcessorFactories); }
/** * <p>Set up batch handlers to consume events from the ring buffer. These handlers will only process events * after every {@link EventProcessor} in this group has processed the event.</p> * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * <pre><code>dw.handleEventsWith(A).then(B);</code></pre> * * @param handlers the batch handlers that will process events. * @return a {@link EventHandlerGroup} that can be used to set up a event processor barrier over the created event processors. */ @SafeVarargs public final EventHandlerGroup<T> then(final EventHandler<? super T>... handlers) { return handleEventsWith(handlers); }
public Disruptor addEventMessageHandler(Disruptor dw, String topic, TreeSet<DomainEventHandler> handlers) { if (handlers.size() == 0) return null; EventHandlerGroup eh = null; for (DomainEventHandler handler : handlers) { DomainEventHandlerAdapter dea = new DomainEventHandlerAdapter(handler); if (eh == null) { eh = dw.handleEventsWith(dea); } else { eh = eh.handleEventsWith(dea); } } return dw; }
private Disruptor createDisruptorWithEventHandler(String topic) { TreeSet<DomainEventHandler> handlers = handlesMap.get(topic); if (handlers == null)// not inited { handlers = this.getTreeSet(); handlers = loadOnCommandConsumers(topic, handlers); handlesMap.put(topic, handlers); } if (handlers.isEmpty()) return null; Disruptor dw = createDw(topic); EventHandlerGroup eh = dw.handleEventsWith(new DomainCommandHandlerFirst(this)); for (DomainEventHandler handler : handlers) { DomainEventHandlerAdapter dea = new DomainEventHandlerDecorator(handler); eh = eh.handleEventsWith(dea); } return dw; }
/** * Set up batch handlers to consume events from the ring buffer. These handlers will only process events * after every {@link EventProcessor} in this group has processed the event. * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * <pre><code>dw.handleEventsWith(A).then(B);</code></pre> * * @param handlers the batch handlers that will process events. * @return a {@link EventHandlerGroup} that can be used to set up a event processor barrier over the created event processors. */ public EventHandlerGroup<T> then(final EventHandler<? super T>... handlers) { return handleEventsWith(handlers); }
/** * <p>Set up custom event processors to handle events from the ring buffer. The Disruptor will * automatically start these processors when {@link Disruptor#start()} is called.</p> * <p> * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * @param eventProcessorFactories the event processor factories to use to create the event processors that will process events. * @return a {@link EventHandlerGroup} that can be used to chain dependencies. */ public EventHandlerGroup<T> then(final EventProcessorFactory<T>... eventProcessorFactories) { return handleEventsWith(eventProcessorFactories); }
/** * <p>Set up custom event processors to handle events from the ring buffer. The Disruptor will * automatically start these processors when {@link Disruptor#start()} is called.</p> * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * @param eventProcessorFactories the event processor factories to use to create the event processors that will process events. * @return a {@link EventHandlerGroup} that can be used to chain dependencies. */ public EventHandlerGroup<T> then(final EventProcessorFactory<T>... eventProcessorFactories) { return handleEventsWith(eventProcessorFactories); }
/** * Set up batch handlers to consume events from the ring buffer. These handlers will only process events * after every {@link EventProcessor} in this group has processed the event. * <p> * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * <p> * <pre><code>dw.handleEventsWith(A).then(B);</code></pre> * * @param handlers the batch handlers that will process events. * @return a {@link EventHandlerGroup} that can be used to set up a event processor barrier over the created event processors. */ public EventHandlerGroup<T> then(final EventHandler<? super T>... handlers) { return handleEventsWith(handlers); }
/** * <p>Set up custom event processors to handle events from the ring buffer. The Disruptor will * automatically start these processors when {@link Disruptor#start()} is called.</p> * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * @param eventProcessorFactories the event processor factories to use to create the event processors that will process events. * @return a {@link EventHandlerGroup} that can be used to chain dependencies. */ @SafeVarargs public final EventHandlerGroup<T> then(final EventProcessorFactory<T>... eventProcessorFactories) { return handleEventsWith(eventProcessorFactories); }
/** * <p>Set up batch handlers to consume events from the ring buffer. These handlers will only process events * after every {@link EventProcessor} in this group has processed the event.</p> * * <p>This method is generally used as part of a chain. For example if the handler <code>A</code> must * process events before handler <code>B</code>:</p> * * <pre><code>dw.handleEventsWith(A).then(B);</code></pre> * * @param handlers the batch handlers that will process events. * @return a {@link EventHandlerGroup} that can be used to set up a event processor barrier over the created event processors. */ @SafeVarargs public final EventHandlerGroup<T> then(final EventHandler<? super T>... handlers) { return handleEventsWith(handlers); }
@SuppressWarnings("unchecked") private DOMNotificationRouter(final ExecutorService executor, final int queueDepth, final WaitStrategy strategy) { this.executor = Preconditions.checkNotNull(executor); disruptor = new Disruptor<>(DOMNotificationRouterEvent.FACTORY, queueDepth, executor, ProducerType.MULTI, strategy); disruptor.handleEventsWith(DISPATCH_NOTIFICATIONS); disruptor.after(DISPATCH_NOTIFICATIONS).handleEventsWith(NOTIFY_FUTURE); disruptor.start(); }
.handleEventsWith(journallingHandler); .handleEventsWith((rb, bs) -> { procR1 = new MasterProcessor(rb, rb.newBarrier(bs), handlerR1); return procR1; }); disruptor.after(procR1).handleEventsWith(matchingEngineHandler);