/** * Construct {@link PhasedBackoffWaitStrategy} with fallback to {@link BlockingWaitStrategy} * * @param spinTimeout The maximum time in to busy spin for. * @param yieldTimeout The maximum time in to yield for. * @param units Time units used for the timeout values. * @return The constructed wait strategy. */ public static PhasedBackoffWaitStrategy withLock( long spinTimeout, long yieldTimeout, TimeUnit units) { return new PhasedBackoffWaitStrategy( spinTimeout, yieldTimeout, units, new BlockingWaitStrategy()); }
@Override public long tryWaitFor(long sequence, Sequence cursor, Sequence dependentSequence, SequenceBarrier barrier, long spin) throws AlertException, InterruptedException, TimeoutException { return waitFor(sequence, cursor, dependentSequence, barrier); }
/** * Create a new single producer RingBuffer using the default wait strategy {@link BlockingWaitStrategy}. * * @param <E> Class of the event stored in the ring buffer. * @param factory used to create the events within the ring buffer. * @param bufferSize number of elements to create within the ring buffer. * @return a constructed ring buffer. * @throws IllegalArgumentException if <code>bufferSize</code> is less than 1 or not a power of 2 * @see MultiProducerSequencer */ public static <E> RingBuffer<E> createSingleProducer(EventFactory<E> factory, int bufferSize) { return createSingleProducer(factory, bufferSize, new BlockingWaitStrategy()); }
/** * Create a new multiple producer RingBuffer using the default wait strategy {@link BlockingWaitStrategy}. * * @param <E> Class of the event stored in the ring buffer. * @param factory used to create the events within the ring buffer. * @param bufferSize number of elements to create within the ring buffer. * @return a constructed ring buffer. * @throws IllegalArgumentException if <code>bufferSize</code> is less than 1 or not a power of 2 * @see MultiProducerSequencer */ public static <E> RingBuffer<E> createMultiProducer(EventFactory<E> factory, int bufferSize) { return createMultiProducer(factory, bufferSize, new BlockingWaitStrategy()); }
/** * Create a new single producer RingBuffer using the default wait strategy {@link BlockingWaitStrategy}. * * @see MultiProducerSequencer * @param factory used to create the events within the ring buffer. * @param bufferSize number of elements to create within the ring buffer. * @throws IllegalArgumentException if <tt>bufferSize</tt> is less than 1 or not a power of 2 */ public static <E> RingBuffer<E> createSingleProducer(EventFactory<E> factory, int bufferSize) { return createSingleProducer(factory, bufferSize, new BlockingWaitStrategy()); }
/** * Create a new multiple producer RingBuffer using the default wait strategy {@link BlockingWaitStrategy}. * * @see MultiProducerSequencer * @param factory used to create the events within the ring buffer. * @param bufferSize number of elements to create within the ring buffer. * @throws IllegalArgumentException if <tt>bufferSize</tt> is less than 1 or not a power of 2 */ public static <E> RingBuffer<E> createMultiProducer(EventFactory<E> factory, int bufferSize) { return createMultiProducer(factory, bufferSize, new BlockingWaitStrategy()); }
private void createDisruptor(final ThreadFactory threadFactory) { disruptor = new Disruptor<TestEvent>( TestEvent.EVENT_FACTORY, 4, threadFactory, ProducerType.SINGLE, new BlockingWaitStrategy()); }
@Parameters public static Collection<Object[]> generateData() { Object[][] allocators = { {ProducerType.SINGLE, new BlockingWaitStrategy()}, {ProducerType.MULTI, new BlockingWaitStrategy()}, }; return Arrays.asList(allocators); }
private WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) { switch (waitStrategyName) { case "sleeping": return new SleepingWaitStrategy(); case "yielding": return new YieldingWaitStrategy(); case "blocking": return new BlockingWaitStrategy(); case "busy_spinning": return new BusySpinWaitStrategy(); default: LOG.warn("Invalid setting for [{}]:" + " Falling back to default: BlockingWaitStrategy.", configOptionName); return new BlockingWaitStrategy(); } }
protected WaitStrategy getWaitStrategy(String waitStrategyName, String configOptionName) { switch (waitStrategyName) { case "sleeping": return new SleepingWaitStrategy(); case "yielding": return new YieldingWaitStrategy(); case "blocking": return new BlockingWaitStrategy(); case "busy_spinning": return new BusySpinWaitStrategy(); default: log.warn("Invalid setting for [{}]:" + " Falling back to default: BlockingWaitStrategy.", configOptionName); return 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(); }
/** * 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(); }
/** * Construct a work pool with an internal {@link RingBuffer} for convenience. * <p> * This option does not require {@link RingBuffer#addGatingSequences(Sequence...)} to be called before the work pool is started. * * @param eventFactory for filling the {@link RingBuffer} * @param exceptionHandler to callback when an error occurs which is not handled by the {@link WorkHandler}s. * @param workHandlers to distribute the work load across. */ @SafeVarargs public WorkerPool( final EventFactory<T> eventFactory, final ExceptionHandler<? super T> exceptionHandler, final WorkHandler<? super T>... workHandlers) { ringBuffer = RingBuffer.createMultiProducer(eventFactory, 1024, new BlockingWaitStrategy()); final SequenceBarrier barrier = ringBuffer.newBarrier(); final int numWorkers = workHandlers.length; workProcessors = new WorkProcessor[numWorkers]; for (int i = 0; i < numWorkers; i++) { workProcessors[i] = new WorkProcessor<>( ringBuffer, barrier, workHandlers[i], exceptionHandler, workSequence); } ringBuffer.addGatingSequences(getWorkerSequences()); }
ProducerType.MULTI, new BlockingWaitStrategy());
@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()); }
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); } } }
this.disruptorMsgBuffer = RingBuffer.createSingleProducer(new MessageEventFactory(), ringBufferSize, new BlockingWaitStrategy()); int tc = parserThreadCount > 0 ? parserThreadCount : 1; this.parserExecutor = Executors.newFixedThreadPool(tc, new NamedThreadFactory("MultiStageCoprocessor-Parser-"
switch (waitStrategyType) { case BLOCKING_WAIT: waitStrategy = new BlockingWaitStrategy(); break; case LITE_BLOCKING_WAIT:
switch (waitStrategyType) { case BLOCKING_WAIT: waitStrategy = new BlockingWaitStrategy(); break; case LITE_BLOCKING_WAIT: