Package net.engio.mbassy.bus

Examples of net.engio.mbassy.bus.MBassador


    public void testAsynchronousMessagePublication() 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, IMessageListener.AsyncListener.class);
                MultipartMessage multipartMessage = messageManager.create(MultipartMessage.class, InstancesPerListener, IMessageListener.AsyncListener.class);

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

            }
        };

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


            public void handleError(PublicationError error) {
                exceptionCount.incrementAndGet();
            }
        };

        final MBassador bus = new MBassador(SyncAsync());
        bus.addErrorHandler(ExceptionCounter);
        ListenerFactory listeners = new ListenerFactory()
                .create(InstancesPerListener, ExceptionThrowingListener.class);
        ConcurrentExecutor.runConcurrent(TestUtil.subscriber(bus, listeners), ConcurrentUnits);

        Runnable publishAndCheck = new Runnable() {
            @Override
            public void run() {
                bus.post(new StandardMessage()).asynchronously();

            }
        };

        // single threaded
View Full Code Here

            .addFeature(Feature.AsynchronousHandlerInvocation.Default())
            .addFeature(Feature.AsynchronousMessageDispatch.Default());
    }

    public MBassador createBus(IBusConfiguration configuration) {
        MBassador bus = new MBassador(configuration);
        bus.addErrorHandler(TestFailingHandler);
        return bus;
    }
View Full Code Here

        bus.addErrorHandler(TestFailingHandler);
        return bus;
    }

    public MBassador createBus(IBusConfiguration configuration, ListenerFactory listeners) {
        MBassador bus = new MBassador(configuration);
        bus.addErrorHandler(TestFailingHandler);
        ConcurrentExecutor.runConcurrent(TestUtil.subscriber(bus, listeners), ConcurrentUnits);
        return bus;
    }
View Full Code Here

    }
  }

  @Test
  public void testMetaHandlerFiltering() {
    MBassador bus = createBus(SyncAsync());

    NamedMessageListener listener = new NamedMessageListener();
    bus.subscribe( listener );

    NamedMessage messageOne = new NamedMessage( "messageOne" );
    NamedMessage messageTwo = new NamedMessage( "messageTwo" );
    NamedMessage messageThree = new NamedMessage( "messageThree" );

    bus.publish( messageOne );
    bus.publish( messageTwo );
    bus.publish( messageThree );

        assertEquals(2, listener.handledByOne.size());
    assertTrue( listener.handledByOne.contains( messageOne ) );
    assertTrue(listener.handledByOne.contains(messageTwo));
View Full Code Here

    }


    @Test
    public void testDeadMessage(){
        final MBassador bus = createBus(SyncAsync());
        ListenerFactory listeners = new ListenerFactory()
                .create(InstancesPerListener, IMessageListener.DefaultListener.class)
                .create(InstancesPerListener, IMessageListener.AsyncListener.class)
                .create(InstancesPerListener, IMessageListener.DisabledListener.class)
                .create(InstancesPerListener, MessagesListener.DefaultListener.class)
                .create(InstancesPerListener, MessagesListener.AsyncListener.class)
                .create(InstancesPerListener, MessagesListener.DisabledListener.class)
                .create(InstancesPerListener, DeadMessagHandler.class)
                .create(InstancesPerListener, Object.class);


        ConcurrentExecutor.runConcurrent(TestUtil.subscriber(bus, listeners), ConcurrentUnits);

        Runnable publishUnhandledMessage = new Runnable() {
            @Override
            public void run() {
                for(int i=0; i < IterationsPerThread; i++){
                    int variation = i % 3;
                    switch (variation){
                        case 0:bus.publish(new Object());break;
                        case 1:bus.publish(i);break;
                        case 2:bus.publish(String.valueOf(i));break;
                    }
                }

            }
        };
View Full Code Here



    @Test
    public void testUnsubscribingAllListeners() {
        final MBassador bus = createBus(SyncAsync());
        ListenerFactory deadMessageListener = new ListenerFactory()
                .create(InstancesPerListener, DeadMessagHandler.class)
                .create(InstancesPerListener, Object.class);
        ListenerFactory objectListener = new ListenerFactory()
                .create(InstancesPerListener, ObjectListener.class);
        ConcurrentExecutor.runConcurrent(TestUtil.subscriber(bus, deadMessageListener), ConcurrentUnits);

        // Only dead message handlers available
        bus.post(new Object()).now();

        // The message should be caught as dead message since there are no subscribed listeners
        assertEquals(InstancesPerListener, DeadMessagHandler.deadMessages.get());

        // Clear deadmessage for future tests
        DeadMessagHandler.deadMessages.set(0);

        // Add object listeners and publish again
        ConcurrentExecutor.runConcurrent(TestUtil.subscriber(bus, objectListener), ConcurrentUnits);
        bus.post(new Object()).now();

        // verify that no dead message events were produced
        assertEquals(0, DeadMessagHandler.deadMessages.get());

        // Unsubscribe all object listeners
        ConcurrentExecutor.runConcurrent(TestUtil.unsubscriber(bus, objectListener), ConcurrentUnits);

        // Only dead message handlers available
        bus.post(new Object()).now();

        // The message should be caught, as it's the only listener
        assertEquals(InstancesPerListener, DeadMessagHandler.deadMessages.get());
    }
View Full Code Here

    public static class MBassadorTest extends SyncBusTest {


        @Override
        protected GenericMessagePublicationSupport getSyncMessageBus() {
            return new MBassador();
        }
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.