We've talked from early on about having a succinct and powerful Graph API that would allow you to create DAG-like [1] processing chains based on Predicates. A bit like Stream but more open, with the ability to specify Dispatchers, error handlers, and alternative paths.
I've been playing a little with some psuedo-code to see what that would look like. I wondered if anyone had any comments on this:
GraphSpec<T> graph = Graphs.compose()
.env(env)
.dispatcher(dispatcher)
.create("bad arg handler", new Consumer<State<Throwable>>(){})
.create("global err handler", new Consumer<State<Throwable>>(){});
// Provide a state object that passes through the graph.
NodeSpec<T> start = graph.first(new Function<T, State<T>>(){});
// Create a path of execution using the default Dispatcher.
// when() is basically a filter
start.when("condition name", new Predicate<State<T>>(){})
// if condition is true...
.then()
// ...follow this chain...
.swap(new Function<State<T>, State<V>>(){})
// ...and terminate.
.end(new Consumer<State<V>>(){}, "threadPool")
// if condition is false...
.otherwise()
// ...terminate here instead.
.end(new Consumer<State<T>>(){});
graph.get().accept(value);
If this was dumped to log or stdout, it would provide a pretty-printed map of the execution flow, printing out the user-defined names of nodes and describing the paths and how they're connected.
The API would also throw an Exception if a path was begun but never terminated, or if you specified a condition without an "otherwise", which would lead to items that don't pass the predicate being dropped (but you could explicitly configure things to be ignored).
Any thoughts, criticisms, etc…? :)
Thanks!
Jon Brisbin | Reactor Project Lead