-
-
Save jbrisbin/96b4479a1f64f7a94975 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@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