當前位置: 首頁>>代碼示例>>Java>>正文


Java EventHandler類代碼示例

本文整理匯總了Java中com.lmax.disruptor.EventHandler的典型用法代碼示例。如果您正苦於以下問題:Java EventHandler類的具體用法?Java EventHandler怎麽用?Java EventHandler使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


EventHandler類屬於com.lmax.disruptor包,在下文中一共展示了EventHandler類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: SharedMessageStore

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@SuppressWarnings("unchecked")
public SharedMessageStore(MessageDao messageDao, int bufferSize, int maxDbBatchSize) {

    pendingMessages = new ConcurrentHashMap<>();
    ThreadFactory namedThreadFactory = new ThreadFactoryBuilder()
            .setNameFormat("DisruptorMessageStoreThread-%d").build();

    disruptor = new Disruptor<>(DbOperation.getFactory(),
            bufferSize, namedThreadFactory, ProducerType.MULTI, new SleepingWaitStrategy());

    disruptor.setDefaultExceptionHandler(new LogExceptionHandler());

    disruptor.handleEventsWith(new DbEventMatcher(bufferSize))
            .then(new DbWriter(messageDao, maxDbBatchSize))
            .then((EventHandler<DbOperation>) (event, sequence, endOfBatch) -> event.clear());
    disruptor.start();
    this.messageDao = messageDao;
}
 
開發者ID:wso2,項目名稱:message-broker,代碼行數:19,代碼來源:SharedMessageStore.java

示例2: MultiBufferBatchEventProcessor

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
public MultiBufferBatchEventProcessor(
    DataProvider<T>[] providers,
    SequenceBarrier[] barriers,
    EventHandler<T> handler)
{
    if (providers.length != barriers.length)
    {
        throw new IllegalArgumentException();
    }

    this.providers = providers;
    this.barriers = barriers;
    this.handler = handler;

    this.sequences = new Sequence[providers.length];
    for (int i = 0; i < sequences.length; i++)
    {
        sequences[i] = new Sequence(-1);
    }
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:21,代碼來源:MultiBufferBatchEventProcessor.java

示例3: shouldWaitOnAllProducersJoinedByAnd

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@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);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:17,代碼來源:DisruptorTest.java

示例4: shouldSupportCustomProcessorsAsDependencies

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@Test
public void shouldSupportCustomProcessorsAsDependencies()
    throws Exception
{
    RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();

    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();

    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);

    final BatchEventProcessor<TestEvent> processor =
        new BatchEventProcessor<TestEvent>(ringBuffer, ringBuffer.newBarrier(), delayedEventHandler);
    disruptor.handleEventsWith(processor);
    disruptor.after(processor).handleEventsWith(handlerWithBarrier);

    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:19,代碼來源:DisruptorTest.java

示例5: shouldSupportHandlersAsDependenciesToCustomProcessors

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@Test
public void shouldSupportHandlersAsDependenciesToCustomProcessors()
    throws Exception
{
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();
    disruptor.handleEventsWith(delayedEventHandler);


    RingBuffer<TestEvent> ringBuffer = disruptor.getRingBuffer();
    CountDownLatch countDownLatch = new CountDownLatch(2);
    EventHandler<TestEvent> handlerWithBarrier = new EventHandlerStub<TestEvent>(countDownLatch);

    final SequenceBarrier sequenceBarrier = disruptor.after(delayedEventHandler).asSequenceBarrier();
    final BatchEventProcessor<TestEvent> processor =
        new BatchEventProcessor<TestEvent>(ringBuffer, sequenceBarrier, handlerWithBarrier);
    disruptor.handleEventsWith(processor);

    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:20,代碼來源:DisruptorTest.java

示例6: shouldSupportCustomProcessorsAndHandlersAsDependencies

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@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);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:21,代碼來源:DisruptorTest.java

示例7: shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@Test
public void shouldMakeEntriesAvailableToFirstCustomProcessorsImmediately() throws Exception
{
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);

    disruptor.handleEventsWith(
                               new EventProcessorFactory<TestEvent>()
                               {
                                   @Override
                                   public EventProcessor createEventProcessor(
                                                                              final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences)
                                   {
                                       assertEquals("Should not have had any barrier sequences", 0, barrierSequences.length);
                                       return new BatchEventProcessor<TestEvent>(
                                                                                 disruptor.getRingBuffer(), ringBuffer.newBarrier(
                                                                                                                                  barrierSequences), eventHandler);
                                   }
                               });

    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:23,代碼來源:DisruptorTest.java

示例8: shouldHonourDependenciesForCustomProcessors

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@Test
public void shouldHonourDependenciesForCustomProcessors() throws Exception
{
    final CountDownLatch countDownLatch = new CountDownLatch(2);
    final EventHandler<TestEvent> eventHandler = new EventHandlerStub<TestEvent>(countDownLatch);
    final DelayedEventHandler delayedEventHandler = createDelayedEventHandler();

    disruptor.handleEventsWith(delayedEventHandler).then(
        new EventProcessorFactory<TestEvent>()
        {
            @Override
            public EventProcessor createEventProcessor(
                final RingBuffer<TestEvent> ringBuffer, final Sequence[] barrierSequences)
            {
                assertSame("Should have had a barrier sequence", 1, barrierSequences.length);
                return new BatchEventProcessor<TestEvent>(
                    disruptor.getRingBuffer(), ringBuffer.newBarrier(
                    barrierSequences), eventHandler);
            }
        });

    ensureTwoEventsProcessedAccordingToDependencies(countDownLatch, delayedEventHandler);
}
 
開發者ID:winwill2012,項目名稱:disruptor-code-analysis,代碼行數:24,代碼來源:DisruptorTest.java

示例9: Source

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
/**
 * Create a new source.
 * <p>This method will prepare the instance with some needed variables
 * in order to be started later with the start method (implemented by children).
 *
 * @param parsersManager Instance of ParserManager that will serve parsers to this source instance
 * @param eventHandler Instance of EventHandler that will receive the events generated by this source instance
 * @param properties Map of properties associated with this source
 */

public Source(ParsersManager parsersManager, EventHandler eventHandler, Map<String, Object> properties) {
    // Save the references for later use
    this.parsersManager = parsersManager;
    this.properties = properties;

    // Create the ring buffer for this topic and start it
    Disruptor<MapEvent> disruptor = new Disruptor<>(new MapEventFactory(), ConfigData.getRingBufferSize(), Executors.newCachedThreadPool());
    disruptor.handleEventsWith(eventHandler);
    disruptor.start();

    // Create the event producer that will receive the events produced by
    // this source instance
    eventProducer = new EventProducer(disruptor.getRingBuffer());
    prepare();
}
 
開發者ID:redBorder,項目名稱:cep,代碼行數:26,代碼來源:Source.java

示例10: testLaterStartConsumer

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@Test
public void testLaterStartConsumer() throws InterruptedException {
    System.out.println("!!!!!!!!!!!!!!!Begin testLaterStartConsumer!!!!!!!!!!");
    final AtomicBoolean messageConsumed = new AtomicBoolean(false);

    // Set queue length to 1, so that the RingBuffer can be easily full
    // to trigger consumer blocking
    DisruptorQueue queue = createQueue("consumerHang", ProducerType.MULTI, 2);
    push(queue, 1);
    Runnable producer = new Producer(queue);
    Runnable consumer = new Consumer(queue, new EventHandler<Object>() {
        long count = 0;

        @Override
        public void onEvent(Object obj, long sequence, boolean endOfBatch) throws Exception {

            messageConsumed.set(true);
            System.out.println("Consume " + count++);
        }
    });

    run(producer, 0, 0, consumer, 50);
    Assert.assertTrue("disruptor message is never consumed due to consumer thread hangs", messageConsumed.get());

    System.out.println("!!!!!!!!!!!!!!!!End testLaterStartConsumer!!!!!!!!!!");
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:27,代碼來源:DisruptorTest.java

示例11: testSingleProducer

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
@Test
public void testSingleProducer() throws InterruptedException {
    System.out.println("!!!!!!!!!!!!!!Begin testSingleProducer!!!!!!!!!!!!!!");
    final AtomicBoolean messageConsumed = new AtomicBoolean(false);

    // Set queue length to 1, so that the RingBuffer can be easily full
    // to trigger consumer blocking
    DisruptorQueue queue = createQueue("consumerHang", ProducerType.SINGLE, 1);
    push(queue, 1);
    Runnable producer = new Producer(queue);
    Runnable consumer = new Consumer(queue, new EventHandler<Object>() {
        long count = 0;

        @Override
        public void onEvent(Object obj, long sequence, boolean endOfBatch) throws Exception {

            messageConsumed.set(true);
            System.out.println("Consume " + count++);
        }
    });

    run(producer, 0, 0, consumer, 50);
    Assert.assertTrue("disruptor message is never consumed due to consumer thread hangs", messageConsumed.get());

    System.out.println("!!!!!!!!!!!!!!End testSingleProducer!!!!!!!!!!!!!!");
}
 
開發者ID:kkllwww007,項目名稱:jstrom,代碼行數:27,代碼來源:DisruptorTest.java

示例12: test_publish_single_eventprocessor_topology

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
/**
 * Publisher -> Ring buffer ---> Consumer A 
 * Look at the graph that gets printed by log4j.
 */
@Test
public void test_publish_single_eventprocessor_topology() {
	ConsumerA consumerA = new ConsumerA();
	
	EventHandlerChain<String> eventHandlerChain1 = new EventHandlerChain<String>(new EventHandler[]{consumerA});
	
	disruptorConfig.setEventHandlerChain(new EventHandlerChain[]{eventHandlerChain1});
	disruptorConfig.init();
	
	disruptorConfig.publish(new EventTranslator<String>() {

		@Override
		public void translateTo(String event, long sequence) {
			event = "hi there";
		}
	});
}
 
開發者ID:anair-it,項目名稱:disruptor-spring-manager,代碼行數:22,代碼來源:DefaultDisruptorConfigTest.java

示例13: test_publish_simple_eventprocessor_topology

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
/**
 * Publisher -> Ring buffer ---> Consumer A -> Consumer B1 -> Consumer D 
 * Look at the graph that gets printed by log4j.
 */
@Test
public void test_publish_simple_eventprocessor_topology() {
	ConsumerA consumerA = new ConsumerA();
	ConsumerB1 consumerB1 = new ConsumerB1();
	ConsumerD consumerD = new ConsumerD();
	
	EventHandlerChain<String> eventHandlerChain1 = new EventHandlerChain<String>(new EventHandler[]{consumerA}, new EventHandler[]{consumerB1});
	EventHandlerChain<String> eventHandlerChain2 = new EventHandlerChain<String>(new EventHandler[]{consumerB1}, new EventHandler[]{consumerD});
	
	disruptorConfig.setEventHandlerChain(new EventHandlerChain[]{eventHandlerChain1, eventHandlerChain2});
	disruptorConfig.init();
	
	disruptorConfig.publish(new EventTranslator<String>() {

		@Override
		public void translateTo(String event, long sequence) {
			event = "hi there";
		}
	});
}
 
開發者ID:anair-it,項目名稱:disruptor-spring-manager,代碼行數:25,代碼來源:DefaultDisruptorConfigTest.java

示例14: test_publish_diamond_eventprocessor_topology

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
/** 
 *                                            Consumer B1  
 *                                           /           \
 * Publisher -> Ring buffer ---> Consumer A -             -> Consumer D 
 *                                           \           /
 *                                            Consumer B2
 * 
 * Look at the graph that gets printed by log4j.
 */
@Test
public void test_publish_diamond_eventprocessor_topology() {
	ConsumerA consumerA = new ConsumerA();
	ConsumerB1 consumerB1 = new ConsumerB1();
	ConsumerB2 consumerB2 = new ConsumerB2();
	ConsumerD consumerD = new ConsumerD();
	
	EventHandlerChain<String> eventHandlerChain1 = new EventHandlerChain<String>(new EventHandler[]{consumerA}, new EventHandler[]{consumerB1, consumerB2});
	EventHandlerChain<String> eventHandlerChain2 = new EventHandlerChain<String>(new EventHandler[]{consumerB1, consumerB2}, new EventHandler[]{consumerD});
	
	disruptorConfig.setEventHandlerChain(new EventHandlerChain[]{eventHandlerChain1, eventHandlerChain2});
	disruptorConfig.init();
	
	disruptorConfig.publish(new EventTranslator<String>() {

		@Override
		public void translateTo(String event, long sequence) {
			event = "hi there";
		}
	});
}
 
開發者ID:anair-it,項目名稱:disruptor-spring-manager,代碼行數:31,代碼來源:DefaultDisruptorConfigTest.java

示例15: test_publish_complicated_diamond_eventprocessor_topology

import com.lmax.disruptor.EventHandler; //導入依賴的package包/類
/** 
 *                                            Consumer B1 -> Consumer C1
 *                                           /                          \
 * Publisher -> Ring buffer ---> Consumer A -                            -> Consumer D 
 *                                           \                          /
 *                                            Consumer B2 -> Consumer C2
 * 
 * Look at the graph that gets printed by log4j.
 */
@Test
public void test_publish_complicated_diamond_eventprocessor_topology() {
	ConsumerA consumerA = new ConsumerA();
	ConsumerB1 consumerB1 = new ConsumerB1();
	ConsumerB2 consumerB2 = new ConsumerB2();
	ConsumerC1 consumerC1 = new ConsumerC1();
	ConsumerC2 consumerC2 = new ConsumerC2();
	ConsumerD consumerD = new ConsumerD();
	
	EventHandlerChain<String> eventHandlerChain1 = new EventHandlerChain<String>(new EventHandler[]{consumerA}, new EventHandler[]{consumerB1, consumerB2});
	EventHandlerChain<String> eventHandlerChain2 = new EventHandlerChain<String>(new EventHandler[]{consumerB1}, new EventHandler[]{consumerC1});
	EventHandlerChain<String> eventHandlerChain3 = new EventHandlerChain<String>(new EventHandler[]{consumerB2}, new EventHandler[]{consumerC2});
	EventHandlerChain<String> eventHandlerChain4 = new EventHandlerChain<String>(new EventHandler[]{consumerC1, consumerC2}, new EventHandler[]{consumerD});
	
	disruptorConfig.setEventHandlerChain(new EventHandlerChain[]{eventHandlerChain1, eventHandlerChain2, eventHandlerChain3, eventHandlerChain4});
	disruptorConfig.init();
	
	disruptorConfig.publish(new EventTranslator<String>() {

		@Override
		public void translateTo(String event, long sequence) {
			event = "hi there";
		}
	});
}
 
開發者ID:anair-it,項目名稱:disruptor-spring-manager,代碼行數:35,代碼來源:DefaultDisruptorConfigTest.java


注:本文中的com.lmax.disruptor.EventHandler類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。