With reactor-core 1.1.4-RELEASE
i tried below but nothing printed out. What should I have missed?
Reactor reactor = Reactors.reactor(new Environment());
reactor.on(
$("hello"),
(Event<String> ev) -> System.out.println("hello "
+ ev.getData()));
reactor.notify("hello", Event.wrap("world"));
@EDIT
Test below confirms that the receiver daemon thread could quit before processing the event.
Reactor reactor = Reactors.reactor(new Environment());
reactor.on($("hello"), (Event<String> ev) -> {
System.out.println(Thread.currentThread().getName());
System.out.println(Thread.currentThread().isDaemon());
System.out.println("hello " + ev.getData());
});
reactor.notify("hello", Event.wrap("world"));
try {
Thread.sleep(1000);
} catch (Exception e) {
}
If this is the extent of your program and there is nothing to prevent the system from exiting until the event is handled then your notify won't have had time to complete before the system will simply exit.
You need a CountDownLatch
or a Thread.sleep(1000)
to allow the system time to propagate the event from one Thread to the other.