/** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public <T> T createRingBufferProxy( final Class<T> proxyInterface, final Disruptor<ProxyMethodInvocation> disruptor, final OverflowStrategy overflowStrategy, final T implementation) { validator.validateAll(disruptor, proxyInterface); disruptor.handleEventsWith(createSingleImplementationHandlerChain(implementation)); final ArgumentHolderGenerator argumentHolderGenerator = new ArgumentHolderGenerator(classPool); argumentHolderGenerator.createArgumentHolderClass(proxyInterface); prefillArgumentHolderObjects(disruptor.getRingBuffer(), argumentHolderGenerator); final Map<Method, Invoker> methodToInvokerMap = createMethodToInvokerMap(proxyInterface, argumentHolderGenerator); return generateProxy( proxyInterface, disruptor.getRingBuffer(), methodToInvokerMap, overflowStrategy, argumentHolderGenerator); }
@SuppressWarnings("unchecked") public static void createDisruptors(DisruptorType type, DisruptorConfig disruptorConfig) { WaitStrategy inboundWaitStrategy = getWaitStrategy(disruptorConfig.getDisruptorWaitStrategy()); for (int i = 0; i < disruptorConfig.getNoDisruptors(); i++) { ExecutorService executorService = Executors.newFixedThreadPool(disruptorConfig.getNoOfEventHandlersPerDisruptor()); Disruptor disruptor = new Disruptor<>( CarbonDisruptorEvent.EVENT_FACTORY, disruptorConfig.getBufferSize(), executorService, ProducerType.MULTI, inboundWaitStrategy); ExceptionHandler exh = new GenericExceptionHandler(); EventHandler[] eventHandlers = new EventHandler[disruptorConfig.getNoOfEventHandlersPerDisruptor()]; for (int j = 0; j < disruptorConfig.getNoOfEventHandlersPerDisruptor(); j++) { EventHandler eventHandler = new CarbonDisruptorEventHandler(); eventHandlers[j] = eventHandler; } disruptor.handleEventsWith(eventHandlers); for (EventHandler eventHandler : eventHandlers) { disruptor.handleExceptionsFor(eventHandler).with(exh); } disruptorConfig.addDisruptor(disruptor.start()); } disruptorConfigHashMap.put(type, disruptorConfig); }
@SafeVarargs public ShriekingMushroom(int bufferSize, Executor exec, EventHandler<Event>... events) { disrupt = new Disruptor<Event>(EventBuilder.FACTORY, bufferSize, exec); disrupt.handleEventsWith(events); RingBuffer<Event> buffer = disrupt.start(); builder = new EventBuilder(buffer); }
@SuppressWarnings("unchecked") @Override public void init() throws ServletException { try { disruptor = new Disruptor<byte[]>( new EventFactory<byte[]>() { @Override public byte[] newInstance() { return new byte[256]; } }, 262144, executor); disruptor.handleEventsWith(new LogicHandler()); disruptor.start(); generator = new Generator(executor); MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); mBeanServer.registerMBean( new StandardMBean(generator, GeneratorMBean.class), new ObjectName("com.lmax:type=generator")); } catch (Exception e) { throw new ServletException(e); } }
private void initProcess() { SequenceBarrier sequenceBarrier = disruptor.getRingBuffer().newBarrier(); EventHandler<SmsEvent> handler = FleetGuiceInjector.getInjector().getInstance(SmsEventHandler.class); BatchEventProcessor<SmsEvent> batchEventProcessor = new BatchEventProcessor<>(disruptor.getRingBuffer(), sequenceBarrier, handler); disruptor.handleEventsWith(batchEventProcessor); }
@SuppressWarnings("unchecked") public void registerConsumer(ExchangeEventConsumer consumer) throws IllegalStateException, NullPointerException { if (disruptor == null) { throw new IllegalStateException("disruptor == null, call init"); } if (consumer == null) { throw new NullPointerException("consumer == null"); } disruptor.handleEventsWith(consumer); }
@SuppressWarnings("unchecked") public MultiplePublishersUsingDisruptorNoTranslator() { disruptor = new Disruptor<DemoEvent>( DemoEvent.FACTORY, Executors.newCachedThreadPool(), // TODO: is this the right one to use here??? new MultiThreadedClaimStrategy(RING_BUFFER_SZ), new YieldingWaitStrategy()); disruptor.handleEventsWith(new DemoEventHandler(1)); // just one consumer for this demo for (int i = 1; i <= NUM_PUBLISHERS; i++) { pubs.add( new DisruptorDemoPublisher( i, NUM_MSGS_TO_PUBLISH_PER_PUBLISHER, disruptor.getRingBuffer(), cycBarrier) .shouldPause(true)); } }
static { initInfoForExecutorThread(); LOGGER.debug("AsyncLogger.ThreadNameStrategy={}", THREAD_NAME_STRATEGY); final int ringBufferSize = calculateRingBufferSize(); final WaitStrategy waitStrategy = createWaitStrategy(); disruptor = new Disruptor<>( RingBufferLogEvent.FACTORY, ringBufferSize, EXECUTOR, ProducerType.MULTI, waitStrategy); disruptor.handleExceptionsWith(getExceptionHandler()); disruptor.handleEventsWith(new RingBufferLogEventHandler()); LOGGER.debug( "Starting AsyncLogger disruptor with ringbuffer size {}...", disruptor.getRingBuffer().getBufferSize()); disruptor.start(); }
@SuppressWarnings("unchecked") private RingBuffer<RecordsHolder> getRingBuffer(Object member) { Disruptor<RecordsHolder> disruptor = this.disruptorMap.get(member); if (disruptor == null) { synchronized (this) { disruptor = this.disruptorMap.get(member); if (disruptor == null) { disruptor = new Disruptor<>( new RecordsEventFactory(), REMOTE_INDEX_COMMUNICATOR_BUFFER_SIZE, this.executor); disruptor.handleEventsWith(new RecordsEventHandler(member)); this.disruptorMap.put(member, disruptor); disruptor.start(); } } } return disruptor.getRingBuffer(); }
/** {@inheritDoc} */ @Override @SuppressWarnings("unchecked") public <T> T createRingBufferProxy( final Class<T> proxyInterface, final Disruptor<ProxyMethodInvocation> disruptor, final OverflowStrategy overflowStrategy, final T... implementations) { validator.validateAll(disruptor, proxyInterface); if (implementations.length < 1) { throw new IllegalArgumentException("Must have at least one implementation"); } else if (implementations.length == 1) { return createRingBufferProxy(proxyInterface, disruptor, overflowStrategy, implementations[0]); } final EventHandler<ProxyMethodInvocation>[] handlers = new EventHandler[implementations.length]; for (int i = 0; i < implementations.length; i++) { handlers[i] = createMultipleImplementationHandlerChain(implementations[i]); disruptor.handleEventsWith(handlers[i]); } disruptor.after(handlers).then(new ResetHandler()); final ArgumentHolderGenerator argumentHolderGenerator = new ArgumentHolderGenerator(classPool); argumentHolderGenerator.createArgumentHolderClass(proxyInterface); prefillArgumentHolderObjects(disruptor.getRingBuffer(), argumentHolderGenerator); final Map<Method, Invoker> methodToInvokerMap = createMethodToInvokerMap(proxyInterface, argumentHolderGenerator); return generateProxy( proxyInterface, disruptor.getRingBuffer(), methodToInvokerMap, overflowStrategy, argumentHolderGenerator); }