processors[i] = bufferProcessorFactory.create(decodingProcessorFactory.create(decodeTime, parseTime)); disruptor.handleEventsWithWorkerPool(processors);
disruptor.handleEventsWithWorkerPool(processors);
handlers[i] = rawMessageEncoderHandlerProvider.get(); disruptor.handleEventsWithWorkerPool(handlers).then(spoolingMessageHandlerProvider.get()); } else { LOG.info("Message journal is disabled."); handlers[i] = directMessageHandlerProvider.get(); disruptor.handleEventsWithWorkerPool(handlers);
/** * disruptor start. * * @param bufferSize this is disruptor buffer size. * @param threadSize this is disruptor consumer thread size. */ private void start(final int bufferSize, final int threadSize) { disruptor = new Disruptor<>(new HmilyTransactionEventFactory(), bufferSize, runnable -> { return new Thread(new ThreadGroup("hmily-disruptor"), runnable, "disruptor-thread-" + INDEX.getAndIncrement()); }, ProducerType.MULTI, new BlockingWaitStrategy()); HmilyConsumerDataHandler[] consumers = new HmilyConsumerDataHandler[1]; List<SingletonExecutor> selects = new ArrayList<>(); for (int i = 0; i < threadSize; i++) { selects.add(new SingletonExecutor("hmily-log-disruptor" + i)); } ConsistentHashSelector selector = new ConsistentHashSelector(selects); consumers[0] = new HmilyConsumerDataHandler(selector, coordinatorService); disruptor.handleEventsWithWorkerPool(consumers); disruptor.setDefaultExceptionHandler(new IgnoreExceptionHandler()); disruptor.start(); }
/** * start disruptor. * * @param bufferSize bufferSize */ private void start(final int bufferSize, final int threadSize) { disruptor = new Disruptor<>(new MythTransactionEventFactory(), bufferSize, runnable -> { return new Thread(new ThreadGroup("hmily-disruptor"), runnable, "disruptor-thread-" + INDEX.getAndIncrement()); }, ProducerType.MULTI, new BlockingWaitStrategy()); final Executor executor = new ThreadPoolExecutor(MAX_THREAD, MAX_THREAD, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), MythTransactionThreadFactory.create("myth-log-disruptor", false), new ThreadPoolExecutor.AbortPolicy()); MythTransactionEventHandler[] consumers = new MythTransactionEventHandler[MAX_THREAD]; for (int i = 0; i < threadSize; i++) { consumers[i] = new MythTransactionEventHandler(coordinatorService, executor); } disruptor.handleEventsWithWorkerPool(consumers); disruptor.setDefaultExceptionHandler(new IgnoreExceptionHandler()); disruptor.start(); }
/** * disruptor start. * * @param bufferSize this is disruptor buffer size. * @param threads this is disruptor consumer thread size. */ private void start(final int bufferSize, final int threads) { disruptor = new Disruptor<>(new TxTransactionEventFactory(), bufferSize, r -> { return new Thread(null, r, "disruptor-thread-" + INDEX.getAndIncrement()); }, ProducerType.MULTI, new BlockingWaitStrategy()); final Executor executor = new ThreadPoolExecutor(threads, threads, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), TxTransactionThreadFactory.create("raincat-log-disruptor", false), new ThreadPoolExecutor.AbortPolicy()); TxTransactionEventHandler[] consumers = new TxTransactionEventHandler[threads]; for (int i = 0; i < threads; i++) { consumers[i] = new TxTransactionEventHandler(executor, txCompensationService); } disruptor.handleEventsWithWorkerPool(consumers); disruptor.setDefaultExceptionHandler(new IgnoreExceptionHandler()); disruptor.start(); }
Publisher[] publishers = initialise(new Publisher[publisherCount], ringBuffer, iterations, barrier, latch); disruptor.handleEventsWithWorkerPool(handlers);
@Test public void shouldProvideEventsMultipleWorkHandlers() throws Exception { final TestWorkHandler workHandler1 = createTestWorkHandler(); final TestWorkHandler workHandler2 = createTestWorkHandler(); final TestWorkHandler workHandler3 = createTestWorkHandler(); final TestWorkHandler workHandler4 = createTestWorkHandler(); final TestWorkHandler workHandler5 = createTestWorkHandler(); final TestWorkHandler workHandler6 = createTestWorkHandler(); final TestWorkHandler workHandler7 = createTestWorkHandler(); final TestWorkHandler workHandler8 = createTestWorkHandler(); disruptor .handleEventsWithWorkerPool(workHandler1, workHandler2) .thenHandleEventsWithWorkerPool(workHandler3, workHandler4); disruptor .handleEventsWithWorkerPool(workHandler5, workHandler6) .thenHandleEventsWithWorkerPool(workHandler7, workHandler8); }
@Test public void shouldProvideEventsToWorkHandlers() throws Exception { final TestWorkHandler workHandler1 = createTestWorkHandler(); final TestWorkHandler workHandler2 = createTestWorkHandler(); disruptor.handleEventsWithWorkerPool(workHandler1, workHandler2); publishEvent(); publishEvent(); workHandler1.processEvent(); workHandler2.processEvent(); }
@Test public void shouldSupportUsingWorkerPoolAsDependency() throws Exception { final TestWorkHandler workHandler1 = createTestWorkHandler(); final TestWorkHandler workHandler2 = createTestWorkHandler(); final DelayedEventHandler delayedEventHandler = createDelayedEventHandler(); disruptor.handleEventsWithWorkerPool(workHandler1, workHandler2).then(delayedEventHandler); publishEvent(); publishEvent(); assertThat(disruptor.getBarrierFor(delayedEventHandler).getCursor(), equalTo(-1L)); workHandler2.processEvent(); workHandler1.processEvent(); delayedEventHandler.processEvent(); }
handlers[i] = new TaskHandler(); dr.handleEventsWithWorkerPool(handlers);
handlers[i] = new TaskHandler(); dr.handleEventsWithWorkerPool(handlers);
@Test public void shouldSupportUsingWorkerPoolAsDependencyAndProcessFirstEventAsSoonAsItIsAvailable() throws Exception { final TestWorkHandler workHandler1 = createTestWorkHandler(); final TestWorkHandler workHandler2 = createTestWorkHandler(); final DelayedEventHandler delayedEventHandler = createDelayedEventHandler(); disruptor.handleEventsWithWorkerPool(workHandler1, workHandler2).then(delayedEventHandler); publishEvent(); publishEvent(); workHandler1.processEvent(); delayedEventHandler.processEvent(); workHandler2.processEvent(); delayedEventHandler.processEvent(); }
@Test public void shouldSetSequenceForWorkProcessorIfAddedAfterPublish() throws Exception { RingBuffer<TestEvent> rb = disruptor.getRingBuffer(); TestWorkHandler wh1 = createTestWorkHandler(); TestWorkHandler wh2 = createTestWorkHandler(); TestWorkHandler wh3 = createTestWorkHandler(); rb.publish(rb.next()); rb.publish(rb.next()); rb.publish(rb.next()); rb.publish(rb.next()); rb.publish(rb.next()); rb.publish(rb.next()); disruptor.handleEventsWithWorkerPool(wh1, wh2, wh3); assertThat(disruptor.getRingBuffer().getMinimumGatingSequence(), is(5L)); }
@Test public void shouldSupportCombiningWorkerPoolWithEventHandlerAsDependencyWhenNotPreviouslyRegistered() throws Exception { final TestWorkHandler workHandler1 = createTestWorkHandler(); final DelayedEventHandler delayedEventHandler1 = createDelayedEventHandler(); final DelayedEventHandler delayedEventHandler2 = createDelayedEventHandler(); disruptor .handleEventsWith(delayedEventHandler1) .and(disruptor.handleEventsWithWorkerPool(workHandler1)) .then(delayedEventHandler2); publishEvent(); publishEvent(); delayedEventHandler1.processEvent(); delayedEventHandler1.processEvent(); workHandler1.processEvent(); delayedEventHandler2.processEvent(); workHandler1.processEvent(); delayedEventHandler2.processEvent(); }
/** * disruptor start with bufferSize. */ private void start() { disruptor = new Disruptor<>(new SoulEventFactory(), bufferSize, r -> { AtomicInteger index = new AtomicInteger(1); return new Thread(null, r, "disruptor-thread-" + index.getAndIncrement()); }, ProducerType.MULTI, new BlockingWaitStrategy()); final Executor executor = new ThreadPoolExecutor(threadSize, threadSize, 0, TimeUnit.MILLISECONDS, new LinkedBlockingQueue<>(), SoulThreadFactory.create("soul-log-disruptor", false), new ThreadPoolExecutor.AbortPolicy()); SoulDataHandler[] consumers = new SoulDataHandler[threadSize]; for (int i = 0; i < threadSize; i++) { consumers[i] = new SoulDataHandler(executor, influxDbService); } disruptor.handleEventsWithWorkerPool(consumers); disruptor.setDefaultExceptionHandler(new IgnoreExceptionHandler()); disruptor.start(); }
public EventHandlerGroup<T> handleEventsWithWorkerPool(String name, WorkHandler<DisruptorData>... handler) { Disruptor disruptor = DISRUPTOR_MAP.get(name); AssertUtil.canNotEmpty(disruptor, "the disruptor is not exist!name:" + name); return disruptor.handleEventsWithWorkerPool(handler); }
public DisruptorCommandQueue(int ringBufferSize, WaitStrategy waitStrategy, Executor executor, BucketCommandProcessor commandProcessor) { disruptor = new Disruptor<DisruptorCommandQueue.BucketCommandEvent>(new BucketCommandEventFactory(), ringBufferSize, executor, ProducerType.MULTI, waitStrategy); disruptor.handleEventsWithWorkerPool(new BucketCommandWorkHandler[]{new BucketCommandWorkHandler(commandProcessor)}); this.closed = new AtomicBoolean(); }
@SuppressWarnings("deprecation") @PostConstruct private void start() { // Executor that will be used to construct new threads for consumers Executor executor = Executors.newCachedThreadPool(); // The factory for the event SmsEventFactory factory = new SmsEventFactory(); // Specify the size of the ring buffer, must be power of 2. // Construct the Disruptor // 单线程模式,获取额外的性能 disruptor = new Disruptor<SmsEvent>(factory, bufferSize, executor); List<SmsHandler> smsHandlers = new ArrayList<SmsHandler>(); for (int i = 0; i < handlerCount; i++) { smsHandlers.add(new SmsHandler(smsSender, smsDao)); } // 多个消费者,每个消费者竞争消费不同数据 disruptor.handleEventsWithWorkerPool(smsHandlers.toArray(new SmsHandler[smsHandlers.size()])); // Start the Disruptor, starts all threads running disruptor.start(); // Get the ring buffer from the Disruptor to be used for publishing. RingBuffer<SmsEvent> ringBuffer = disruptor.getRingBuffer(); smsEventProducer = new SmsEventProducer(ringBuffer, smsDao); if (smsDao != null) { smsDao.doStart(); } }
@SuppressWarnings("deprecation") @PostConstruct private void start() { // Executor that will be used to construct new threads for consumers Executor executor = Executors.newCachedThreadPool(); // The factory for the event TaskEventFactory factory = new TaskEventFactory(); // Specify the size of the ring buffer, must be power of 2. // Construct the Disruptor // 单线程模式,获取额外的性能 disruptor = new Disruptor<TaskEvent>(factory, bufferSize, executor, ProducerType.SINGLE, new YieldingWaitStrategy()); List<TaskHandler> TaskHandlers = new ArrayList<>(); for (int i = 0; i < handlerCount; i++) { TaskHandlers.add(new TaskHandler()); } disruptor.handleExceptionsWith(new IgnoreExceptionHandler()); // 多个消费者,每个消费者竞争消费不同数据 disruptor.handleEventsWithWorkerPool(TaskHandlers.toArray(new TaskHandler[TaskHandlers.size()])); // Start the Disruptor, starts all threads running disruptor.start(); // Get the ring buffer from the Disruptor to be used for publishing. RingBuffer<TaskEvent> ringBuffer = disruptor.getRingBuffer(); taskEventProducer = new TaskEventProducer(ringBuffer); }