Search in sources :

Example 1 with Pipe

use of com.b2international.snowowl.eventbus.Pipe in project snow-owl by b2ihealthcare.

the class PipeTest method pipeSourceToTargetWithReply.

@Test
public void pipeSourceToTargetWithReply() throws Exception {
    final CountDownLatch sourceLatch = new CountDownLatch(1);
    final CountDownLatch targetLatch = new CountDownLatch(1);
    target.registerHandler(ADDRESS, new CountDownHandler(SEND_MESSAGE, targetLatch) {

        @Override
        public void handle(IMessage message) {
            super.handle(message);
            message.reply(REPLY_MESSAGE);
        }
    });
    bus.registerHandler(ADDRESS, new Pipe(target, ADDRESS));
    bus.send(ADDRESS, SEND_MESSAGE, null, new CountDownHandler(REPLY_MESSAGE, sourceLatch));
    wait(targetLatch);
    wait(sourceLatch);
}
Also used : IMessage(com.b2international.snowowl.eventbus.IMessage) Pipe(com.b2international.snowowl.eventbus.Pipe) CountDownLatch(java.util.concurrent.CountDownLatch) CountDownHandler(com.b2international.snowowl.eventbus.util.CountDownHandler) Test(org.junit.Test)

Example 2 with Pipe

use of com.b2international.snowowl.eventbus.Pipe in project snow-owl by b2ihealthcare.

the class PipeTest method pipeToWorker.

@Test
public void pipeToWorker() throws Exception {
    IEventBus target = EventBusUtil.getWorkerBus("worker", 2);
    LifecycleUtil.activate(target);
    final CountDownLatch sourceLatch = new CountDownLatch(1);
    final CountDownLatch targetLatch = new CountDownLatch(1);
    bus.registerHandler(ADDRESS, new Pipe(target, ADDRESS));
    target.registerHandler("work-address", new IHandler<IMessage>() {

        @Override
        public void handle(IMessage message) {
            try {
                Thread.sleep(30_000L);
            } catch (InterruptedException ignored) {
            }
        }
    });
    target.registerHandler(ADDRESS, new CountDownHandler(SEND_MESSAGE, targetLatch) {

        @Override
        public void handle(IMessage message) {
            super.handle(message);
            message.reply(REPLY_MESSAGE);
        }
    });
    /* 
		 * XXX: In a regular event bus, the third (reply) registered message handler would be queued after the 
		 * long-running "work-address" handler, and would block.
		 */
    setWaitTime(1);
    target.send("work-address", new Object(), null);
    bus.send(ADDRESS, SEND_MESSAGE, null, new CountDownHandler(REPLY_MESSAGE, sourceLatch));
    wait(targetLatch);
    wait(sourceLatch);
}
Also used : IMessage(com.b2international.snowowl.eventbus.IMessage) Pipe(com.b2international.snowowl.eventbus.Pipe) CountDownLatch(java.util.concurrent.CountDownLatch) CountDownHandler(com.b2international.snowowl.eventbus.util.CountDownHandler) IEventBus(com.b2international.snowowl.eventbus.IEventBus) Test(org.junit.Test)

Example 3 with Pipe

use of com.b2international.snowowl.eventbus.Pipe in project snow-owl by b2ihealthcare.

the class PipeTest method pipeSourceToTarget.

@Test
public void pipeSourceToTarget() throws Exception {
    final CountDownLatch targetLatch = new CountDownLatch(1);
    target.registerHandler(ADDRESS, new CountDownHandler(SEND_MESSAGE, targetLatch));
    bus.registerHandler(ADDRESS, new Pipe(target, ADDRESS));
    bus.send(ADDRESS, SEND_MESSAGE, null);
    wait(targetLatch);
}
Also used : Pipe(com.b2international.snowowl.eventbus.Pipe) CountDownLatch(java.util.concurrent.CountDownLatch) CountDownHandler(com.b2international.snowowl.eventbus.util.CountDownHandler) Test(org.junit.Test)

Aggregations

Pipe (com.b2international.snowowl.eventbus.Pipe)3 CountDownHandler (com.b2international.snowowl.eventbus.util.CountDownHandler)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 Test (org.junit.Test)3 IMessage (com.b2international.snowowl.eventbus.IMessage)2 IEventBus (com.b2international.snowowl.eventbus.IEventBus)1