Skip to content

Instantly share code, notes, and snippets.

@markpollack
Created December 3, 2014 19:47
Show Gist options
  • Save markpollack/bb60c6a20ac5d81a32be to your computer and use it in GitHub Desktop.
Save markpollack/bb60c6a20ac5d81a32be to your computer and use it in GitHub Desktop.
Sample app that shows infinite loop issue
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);
}
}
@markpollack
Copy link
Author

The small driver apps is

public class Main {

    public static void main(String[] args) throws InterruptedException {
        final Environment env = new Environment();

        EventSample sample = new EventSample(env);
        sample.demo();

        System.out.println("\nSleeping for 10 seconds");
        Thread.sleep(10000);
        System.out.println("\ndone");
        System.exit(1);
    }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment