Disruptor<LongEvent> disruptor = new Disruptor<>(factory, bufferSize, executor, ProducerType.SINGLE, new YieldingWaitStrategy());
final Disruptor<MessageEvent> disruptor = new Disruptor<>( MessageEvent.EVENT_FACTORY, this.ringBufferSize,
final Disruptor<MessageEvent> disruptor = new Disruptor<>( MessageEvent.EVENT_FACTORY, ringBufferSize,
private void createDisruptor(final ThreadFactory threadFactory) { disruptor = new Disruptor<TestEvent>( TestEvent.EVENT_FACTORY, 4, threadFactory, ProducerType.SINGLE, new BlockingWaitStrategy()); }
/** * 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(); }
Provider<RawMessageEncoderHandler> rawMessageEncoderHandlerProvider, Provider<JournallingMessageHandler> spoolingMessageHandlerProvider) { final Disruptor<RawMessageEvent> disruptor = new Disruptor<>( RawMessageEvent.FACTORY, configuration.getInputBufferRingSize(),
/** * 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(); }
public static void main(String[] args) { Disruptor<MyEvent> disruptor = new Disruptor<MyEvent>(factory, 1024, DaemonThreadFactory.INSTANCE); disruptor.handleEventsWith(handler1).then(handler2).then(handler3); disruptor.start(); } }
public static void main(String[] args) throws InterruptedException Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(LongEvent.FACTORY, 1024, DaemonThreadFactory.INSTANCE);
@Test public void shouldHandleLotsOfThreads() throws Exception Disruptor<TestEvent> disruptor = new Disruptor<TestEvent>( TestEvent.FACTORY, 1 << 16, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new BusySpinWaitStrategy());
@Test public void shouldHandleLotsOfThreads() throws Exception Disruptor<TestEvent> disruptor = new Disruptor<TestEvent>( TestEvent.FACTORY, 1 << 16, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new SleepingWaitStrategy());
public static void main(String[] args) { Executor executor = Executors.newFixedThreadPool(4); Disruptor<DataEvent> disruptor = new Disruptor<DataEvent>( DataEvent.FACTORY, 1024, DaemonThreadFactory.INSTANCE); TransformingHandler handler1 = new TransformingHandler(0); TransformingHandler handler2 = new TransformingHandler(1); TransformingHandler handler3 = new TransformingHandler(2); CollatingHandler collator = new CollatingHandler(); disruptor.handleEventsWith(handler1, handler2, handler3).then(collator); disruptor.start(); } }
public static void main(String[] args) { Disruptor<Event> disruptor = new Disruptor<>(Event.FACTORY, 1024, new DefaultThreadFactory()); AtomicBoolean running = new AtomicBoolean(true); ErrorHandler errorHandler = new ErrorHandler(running); final Handler handler = new Handler(); disruptor.handleEventsWith(handler); disruptor.handleExceptionsFor(handler).with(errorHandler); simplePublish(disruptor, running); }
public static void main(String[] args) throws InterruptedException { Disruptor<ObjectBox> disruptor = new Disruptor<ObjectBox>( ObjectBox.FACTORY, RING_SIZE, DaemonThreadFactory.INSTANCE, ProducerType.MULTI, new BlockingWaitStrategy()); disruptor.handleEventsWith(new Consumer()).then(new Consumer()); final RingBuffer<ObjectBox> ringBuffer = disruptor.getRingBuffer(); Publisher p = new Publisher(); IMessage message = new IMessage(); ITransportable transportable = new ITransportable(); String streamName = "com.lmax.wibble"; System.out.println("publishing " + RING_SIZE + " messages"); for (int i = 0; i < RING_SIZE; i++) { ringBuffer.publishEvent(p, message, transportable, streamName); Thread.sleep(10); } System.out.println("start disruptor"); disruptor.start(); System.out.println("continue publishing"); while (true) { ringBuffer.publishEvent(p, message, transportable, streamName); Thread.sleep(10); } } }
public static void main(String[] args) throws TimeoutException, InterruptedException { Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>( LongEvent.FACTORY, 16, DaemonThreadFactory.INSTANCE ); CountDownLatch shutdownLatch = new CountDownLatch(2); disruptor.handleEventsWith(new Handler(shutdownLatch)).then(new Handler(shutdownLatch)); disruptor.start(); long next = disruptor.getRingBuffer().next(); disruptor.getRingBuffer().get(next).set(next); disruptor.getRingBuffer().publish(next); disruptor.shutdown(10, TimeUnit.SECONDS); shutdownLatch.await(); System.out.println(value); } }
public void shouldBatch() throws Exception Disruptor<LongEvent> d = new Disruptor<LongEvent>( LongEvent.FACTORY, 2048, DaemonThreadFactory.INSTANCE, producerType, new SleepingWaitStrategy());
@SuppressWarnings("unchecked") @Before public void setUp() { disruptor = new Disruptor<byte[]>( new ByteArrayFactory(256), 1024, DaemonThreadFactory.INSTANCE, ProducerType.SINGLE, new BlockingWaitStrategy()); disruptor.handleEventsWith(eventHandler); disruptor.setDefaultExceptionHandler(new FatalExceptionHandler()); }
Disruptor<StubEvent> disruptor = new Disruptor<StubEvent>( StubEvent.EVENT_FACTORY, 1024, DaemonThreadFactory.INSTANCE); RingBuffer<StubEvent> ringBuffer = disruptor.start();
public static void main(String[] args) { Disruptor<PipelinerEvent> disruptor = new Disruptor<PipelinerEvent>( PipelinerEvent.FACTORY, 1024, DaemonThreadFactory.INSTANCE); disruptor.handleEventsWith( new ParallelHandler(0, 3), new ParallelHandler(1, 3), new ParallelHandler(2, 3) ).then(new JoiningHandler()); RingBuffer<PipelinerEvent> ringBuffer = disruptor.start(); for (int i = 0; i < 1000; i++) { long next = ringBuffer.next(); try { PipelinerEvent pipelinerEvent = ringBuffer.get(next); pipelinerEvent.input = i; } finally { ringBuffer.publish(next); } } }