Package net.engio.mbassy.bus

Examples of net.engio.mbassy.bus.MBassador


  /*************************************************************************
   * @throws Exception
   ************************************************************************/
  @Test
  public void testSimpleStringCondition() throws Exception {
    MBassador bus = createBus(SyncAsync());
    bus.subscribe(new ConditionalMessageListener());

    TestEvent message = new TestEvent("TEST", 0);
    bus.publish(message);

    assertTrue(message.wasHandledBy("handleTypeMessage", "handleEnvelopedMessage"));
        assertFalse(message.wasHandledBy("handleInvalidEL"));
  }
View Full Code Here


  /*************************************************************************
   * @throws Exception
   ************************************************************************/
  @Test
  public void testSimpleNumberCondition() throws Exception {
    MBassador bus = new MBassador();
    bus.subscribe(new ConditionalMessageListener());

    TestEvent message = new TestEvent("", 5);
    bus.publish(message);

    assertTrue(message.wasHandledBy("handleSizeMessage"));
        assertFalse(message.wasHandledBy("handleInvalidEL"));
  }
View Full Code Here

  /*************************************************************************
   * @throws Exception
   ************************************************************************/
  @Test
  public void testHandleCombinedEL() throws Exception {
    MBassador bus = createBus(SyncAsync());
    bus.subscribe(new ConditionalMessageListener());

    TestEvent message = new TestEvent("", 3);
    bus.publish(message);

        assertTrue(message.wasHandledBy("handleCombinedEL"));
        assertFalse(message.wasHandledBy("handleInvalidEL"));
  }
View Full Code Here

  /*************************************************************************
   * @throws Exception
   ************************************************************************/
  @Test
  public void testNotMatchingAnyCondition() throws Exception {
    MBassador bus = createBus(SyncAsync());
    bus.subscribe(new ConditionalMessageListener());

    TestEvent message = new TestEvent("", 0);
    bus.publish(message);

    assertTrue(message.handledBy.isEmpty());
  }
View Full Code Here

  /*************************************************************************
   * @throws Exception
   ************************************************************************/
  @Test
  public void testHandleMethodAccessEL() throws Exception {
    MBassador bus = createBus(SyncAsync());
    bus.subscribe(new ConditionalMessageListener());

    TestEvent message = new TestEvent("XYZ", 1);
    bus.publish(message);

        assertTrue(message.wasHandledBy("handleMethodAccessEL"));
        assertFalse(message.wasHandledBy("handleInvalidEL"));

    }
View Full Code Here

    @Test
    public void testSubclassFilter() throws Exception {
        FilteredEventCounter.set(0);
        DeadEventCounter.set(0);

        MBassador bus = createBus(SyncAsync());
        ListenerFactory listenerFactory = new ListenerFactory()
                .create(100, FilteredMessageListener.class);

        List<Object> listeners = listenerFactory.getAll();

        // this will subscribe the listeners concurrently to the bus
        TestUtil.setup(bus, listeners, 10);

        TestMessage message = new TestMessage();
        TestMessage subTestMessage = new SubTestMessage();

        bus.post(message).now();
        bus.post(subTestMessage).now();

        assertEquals(100, message.counter.get());
        assertEquals(0, subTestMessage.counter.get());
        assertEquals(100, FilteredEventCounter.get());
    }
View Full Code Here

    @Test
    public void testFilteredFilteredEvent() throws Exception {
        FilteredEventCounter.set(0);
        DeadEventCounter.set(0);

        MBassador bus = createBus(SyncAsync());
        ListenerFactory listenerFactory = new ListenerFactory()
                .create(100, FilteredMessageListener.class);

        List<Object> listeners = listenerFactory.getAll();

        // this will subscribe the listeners concurrently to the bus
        TestUtil.setup(bus, listeners, 10);

        bus.post(new Object()).now();
        bus.post(new SubTestMessage()).now();

        assertEquals(100, FilteredEventCounter.get()); // the SubTestMessage should have been republished as a filtered event
        assertEquals(100, DeadEventCounter.get()); // Object.class was filtered and the fil
    }
View Full Code Here

        }
    }

    @Test
    public void testSubtypesOnly(){
        MBassador bus = createBus(SyncAsync());
        ListenerFactory listeners = new ListenerFactory()
                .create(100, TestMessageHandler.class);

        // this will subscribe the listeners concurrently to the bus
        TestUtil.setup(bus, listeners, 10);

        TestMessage supertype = new TestMessage();
        TestMessage subtype = new SubTestMessage();

        bus.publish(supertype);
        bus.publish(subtype);

        assertEquals(100, subtype.counter.get());
        assertEquals(0, supertype.counter.get());

    }
View Full Code Here

    public void testSyncPublicationSyncHandlers() throws Exception {

        ListenerFactory listeners = new ListenerFactory()
                .create(InstancesPerListener, Listeners.synchronous())
                .create(InstancesPerListener, Listeners.noHandlers());
        final MBassador bus = createBus(SyncAsync(), listeners);


        Runnable publishAndCheck = new Runnable() {
            @Override
            public void run() {
                StandardMessage standardMessage = new StandardMessage();
                MultipartMessage multipartMessage = new MultipartMessage();

                bus.post(standardMessage).now();
                bus.post(multipartMessage).now();
                bus.post(MessageTypes.Simple).now();

                assertEquals(InstancesPerListener, standardMessage.getTimesHandled(IMessageListener.DefaultListener.class));
                assertEquals(InstancesPerListener, multipartMessage.getTimesHandled(IMessageListener.DefaultListener.class));
            }
        };
View Full Code Here

    @Test
    public void testSyncPublicationAsyncHandlers() throws Exception {
        ListenerFactory listeners = new ListenerFactory()
                .create(InstancesPerListener, Listeners.asynchronous())
                .create(InstancesPerListener, Listeners.noHandlers());
        final MBassador bus = createBus(SyncAsync(), listeners);

        final MessageManager messageManager = new MessageManager();
        Runnable publishAndCheck = new Runnable() {
            @Override
            public void run() {

                StandardMessage standardMessage = messageManager.create(StandardMessage.class, InstancesPerListener, Listeners.join(Listeners.asynchronous(), Listeners.handlesStandardMessage()));
                MultipartMessage multipartMessage = messageManager.create(MultipartMessage.class, InstancesPerListener, IMessageListener.AsyncListener.class, IMultipartMessageListener.AsyncListener.class);

                bus.post(standardMessage).now();
                bus.post(multipartMessage).now();
                bus.post(MessageTypes.Simple).now();

            }
        };

        ConcurrentExecutor.runConcurrent(publishAndCheck, 1);
View Full Code Here

TOP

Related Classes of net.engio.mbassy.bus.MBassador

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.