Package org.menacheri.jetserver.event

Examples of org.menacheri.jetserver.event.EventDispatcher


public class JetlangEventDispatcherTest {
  @Test
  public void specificEventReceiptOnSpecificEventHandler()
      throws InterruptedException {
    EventDispatcher dispatcher = EventDispatchers
        .newJetlangEventDispatcher(null, null);
    final CountDownLatch latch = new CountDownLatch(1);
    dispatcher.addHandler(new EventHandler() {

      @Override
      public void onEvent(Event event) {
        latch.countDown();
      }

      @Override
      public int getEventType() {
        return Events.SESSION_MESSAGE;
      }
    });

    Event event = Events.event(null, Events.SESSION_MESSAGE);
    dispatcher.fireEvent(event);
    assertTrue(latch.await(1, TimeUnit.SECONDS));
  }
View Full Code Here


    assertTrue(latch.await(1, TimeUnit.SECONDS));
  }

  @Test
  public void eventReceiptOnANYTypeEventHandler() throws InterruptedException {
    EventDispatcher dispatcher = EventDispatchers
        .newJetlangEventDispatcher(null, null);
    final CountDownLatch latch = new CountDownLatch(5);
    dispatcher.addHandler(new EventHandler() {

      @Override
      public void onEvent(Event event) {
        latch.countDown();
      }

      @Override
      public int getEventType() {
        return Events.ANY;
      }
    });

    Event event = Events.event(null, Events.SESSION_MESSAGE);
    dispatcher.fireEvent(event);
    event = Events.event(null, Events.NETWORK_MESSAGE);
    dispatcher.fireEvent(event);
    event = Events.event(null, Events.EXCEPTION);
    dispatcher.fireEvent(event);
    event = Events.event(null, Events.LOG_IN);
    dispatcher.fireEvent(event);
    event = Events.event(null, Events.CONNECT);
    dispatcher.fireEvent(event);

    assertTrue(latch.await(1, TimeUnit.SECONDS));
  }
View Full Code Here

  }

  @Test
  public void nonReceiptOfWrongEventOnSpecificEventHandler()
      throws InterruptedException {
    EventDispatcher dispatcher = EventDispatchers
        .newJetlangEventDispatcher(null, null);
    final CountDownLatch latch = new CountDownLatch(1);
    dispatcher.addHandler(new EventHandler() {

      @Override
      public void onEvent(Event event) {
        latch.countDown();
      }

      @Override
      public int getEventType() {
        return Events.SESSION_MESSAGE;
      }
    });

    Event event = Events.event(null, Events.NETWORK_MESSAGE);
    dispatcher.fireEvent(event);
    assertFalse(latch.await(1, TimeUnit.SECONDS));
  }
View Full Code Here

    assertFalse(latch.await(1, TimeUnit.SECONDS));
  }

  @Test
  public void eventPublishingPerformance() throws InterruptedException {
    EventDispatcher dispatcher = EventDispatchers
        .newJetlangEventDispatcher(null, null);
    int countOfEvents = 5000000;
    final CountDownLatch latch = new CountDownLatch(countOfEvents);
    dispatcher.addHandler(new EventHandler() {

      @Override
      public void onEvent(Event event) {
        latch.countDown();
      }

      @Override
      public int getEventType() {
        return 0;
      }
    });
    long startTime = System.nanoTime();
    for (int i = 1; i <= countOfEvents; i++) {
      Event event = Events.event(null, Events.SESSION_MESSAGE);
      dispatcher.fireEvent(event);
    }
    long time = System.nanoTime() - startTime;
    latch.await(10, TimeUnit.SECONDS);
    System.out.printf("Took  %.3f seconds to send %d int events",
        time / 1e9, countOfEvents);
View Full Code Here

TOP

Related Classes of org.menacheri.jetserver.event.EventDispatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.