Package net.engio.mbassy.bus.common

Examples of net.engio.mbassy.bus.common.IMessageBus


    public void testSynchronizedWithSynchronousInvocation(){
        List<SynchronizedWithSynchronousDelivery> handlers = new LinkedList<SynchronizedWithSynchronousDelivery>();
        IBusConfiguration config = SyncAsync();
        config.getFeature(Feature.AsynchronousMessageDispatch.class)
                .setNumberOfMessageDispatchers(6);
        IMessageBus bus = createBus(config);
        for(int i = 0; i < numberOfListeners; i++){
            SynchronizedWithSynchronousDelivery handler = new SynchronizedWithSynchronousDelivery();
            handlers.add(handler);
            bus.subscribe(handler);
        }

        MessagePublication publication = null;
        for(int i = 0; i < numberOfMessages; i++){
           publication =  bus.post(new Object()).asynchronously();
        }
        // wait for last publication
        while (!publication.isFinished()){
            pause(100);
        }
View Full Code Here


    public void testSynchronizedWithAsSynchronousInvocation(){
        List<SynchronizedWithAsynchronousDelivery> handlers = new LinkedList<SynchronizedWithAsynchronousDelivery>();
        IBusConfiguration config = SyncAsync();
        config.getFeature(Feature.AsynchronousMessageDispatch.class)
                .setNumberOfMessageDispatchers(6);
        IMessageBus bus = createBus(config);
        for(int i = 0; i < numberOfListeners; i++){
            SynchronizedWithAsynchronousDelivery handler = new SynchronizedWithAsynchronousDelivery();
            handlers.add(handler);
            bus.subscribe(handler);
        }

        for(int i = 0; i < numberOfMessages; i++){
            track(bus.post(new Object()).asynchronously());
        }

        pause(10000);

        for(SynchronizedWithAsynchronousDelivery handler : handlers){
View Full Code Here

public class AsyncFIFOBusTest extends MessageBusTest {

    @Test
    public void testSingleThreadedSyncFIFO(){
        // create a fifo bus with 1000 concurrently subscribed listeners
        IMessageBus fifoBUs = BusFactory.AsynchronousSequentialFIFO();

        List<SyncListener> listeners = new LinkedList<SyncListener>();
        for(int i = 0; i < 1000 ; i++){
            SyncListener listener = new SyncListener();
            listeners.add(listener);
            fifoBUs.subscribe(listener);
        }

        // prepare set of messages in increasing order
        int[] messages = new int[1000];
        for(int i = 0; i < messages.length ; i++){
             messages[i] = i;
        }
        // publish in ascending order
        for(Integer message : messages)
            fifoBUs.post(message).asynchronously();

        while(fifoBUs.hasPendingMessages())
            pause(1000);

        for(SyncListener listener : listeners){
            assertEquals(messages.length, listener.receivedSync.size());
            for(int i=0; i < messages.length; i++){
View Full Code Here

    // NOTE: Can fail due to timing issues.
    @Test
    public void testSingleThreadedSyncAsyncFIFO(){
        // create a fifo bus with 1000 concurrently subscribed listeners
        IMessageBus fifoBUs = BusFactory.AsynchronousSequentialFIFO();

        List<SyncAsyncListener> listeners = new LinkedList<SyncAsyncListener>();
        for(int i = 0; i < 1000 ; i++){
            SyncAsyncListener listener = new SyncAsyncListener();
            listeners.add(listener);
            fifoBUs.subscribe(listener);
        }

        // prepare set of messages in increasing order
        int[] messages = new int[1000];
        for(int i = 0; i < messages.length ; i++){
            messages[i] = i;
        }
        // publish in ascending order
        for(Integer message : messages)
            fifoBUs.post(message).asynchronously();

        while(fifoBUs.hasPendingMessages())
            pause(2000);

        for(SyncAsyncListener listener : listeners){
            assertEquals(messages.length, listener.receivedSync.size());
            assertEquals(listener.receivedSync.size(), listener.receivedAsync.size());
View Full Code Here

    }

    @Test
    public void testDispatch1(){
        IMessageBus bus = createBus(SyncAsync());
        EventListener2 listener2 = new EventListener2();
        bus.subscribe(listener2);
        bus.post("jfndf").now();
        assertTrue(listener2Called);
        assertFalse(listener1Called);

        EventListener1 listener1 = new EventListener1();
        bus.subscribe(listener1);
        bus.post("jfndf").now();
        assertTrue(listener1Called);
    }
View Full Code Here

TOP

Related Classes of net.engio.mbassy.bus.common.IMessageBus

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.