Skip to content

Execution Listeners

Ben Fagin edited this page Mar 1, 2016 · 3 revisions

When executing a builder, you can provide zero or more ExecutionListener instances. So what do these do? Looking at the interface there is exactly one method, void next(Method method, Object[] args). Whenever a method is called in the builder, it is called in the execution listeners. The current interface method and arguments to it are provided as parameters.

The simplest use of this is for logging. One of the downsides of using method chaining in Java involves the mangling of line numbers in stack traces at runtime. The elegant spacing of your method invocations generally translates to a single line internally. This can really suck, and make debugging difficult.

To address this, Flapi ships with a class called MethodLoggger which is an implementation of ExecutionListener. Use MethodLogger.from(PrintStream stream) to create a new instance which will print out the method names and step number to the stream as the builder is invoked.