Skip to content

Instantly share code, notes, and snippets.

@jbrisbin
Forked from nithril/gist:1deb881ddaa88576b107
Created September 13, 2014 16:51
Show Gist options
  • Save jbrisbin/96b4479a1f64f7a94975 to your computer and use it in GitHub Desktop.
Save jbrisbin/96b4479a1f64f7a94975 to your computer and use it in GitHub Desktop.
@Test
public void workerOrchestrator() throws InterruptedException {
Environment env = new Environment();
Reactor reactor = Reactors.reactor(env, Environment.THREAD_POOL);
CountDownLatch latch = new CountDownLatch(2);
reactor.on(Selectors.$("worker"), new Consumer() {
@Override
public void accept(Object o) {
System.out.println(Thread.currentThread().getName() + " worker " + o);
reactor.notify("orchestrator", Event.wrap("ok"));
latch.countDown();
System.out.println(Thread.currentThread().getName() + " ok");
}
});
reactor.on(Selectors.$("orchestrator"), new Consumer<Event<Integer>>() {
@Override
public void accept(Event<Integer> event) {
sendTask();
}
void sendTask() {
System.out.println(Thread.currentThread().getName() + " sendTask ");
reactor.notify("worker", Event.wrap(latch.getCount()));
latch.countDown();
}
});
reactor.notify("orchestrator", Event.wrap(1000));
latch.await(5, TimeUnit.SECONDS);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment