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);
}
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);
}
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);
}
Aggregations