Created
December 3, 2014 19:47
-
-
Save markpollack/bb60c6a20ac5d81a32be to your computer and use it in GitHub Desktop.
Sample app that shows infinite loop issue
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
package spring.xd.sample; | |
import reactor.core.Environment; | |
import reactor.core.Reactor; | |
import reactor.core.spec.Reactors; | |
import reactor.event.Event; | |
import reactor.event.selector.Selectors; | |
import reactor.function.Consumer; | |
public class EventSample { | |
private Environment env; | |
public EventSample(Environment env) { | |
this.env = env; | |
} | |
public void demo() { | |
Reactor reactor = Reactors.reactor() | |
.env(env) // our current Environment | |
.dispatcher(Environment.RING_BUFFER) // use one of the BlockingQueueDispatchers | |
.get(); // get the object when finished configuring | |
// Register a consumer to handle events sent with a key that matches "parse" | |
reactor.on(Selectors.object("parse"), new Consumer<Event<Integer>>() { | |
@Override | |
public void accept(Event<Integer> ev) { | |
System.out.println("In accept"); | |
Integer i = ev.getData(); | |
System.out.println(i.intValue()); | |
System.out.println("Received event with data: " + ev.getData()); | |
String header = ev.getHeaders().get("x-custom-header"); | |
System.out.print("header = " + header); | |
} | |
}); | |
// Send an event to this Reactor and trigger all actions that match the given key | |
Event<String> ev = Event.wrap("Hello World"); | |
ev.getHeaders().set("x-custom-header", "ID_TO_ANOTHER_REACTOR"); | |
reactor.notify("parse", ev); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The small driver apps is