use of com.oath.cyclops.internal.react.async.future.PipelineBuilder in project cyclops by aol.
the class LazySimpleReactStream method onFail.
/**
* Recover for a particular class of exceptions only. Chain onFail methods from specific Exception classes
* to general, as Exceptions will be caught and handled in order.
* e.g.
* <pre>
* {@code
* onFail(IOException.class, recoveryFunction1)
* .onFail(Throwable.class,recovertyFunction2)
* }
* </pre>
* For an IOException recoveryFunction1 will be executed
*
* but with the definitions reveresed
* <pre>
* {@code
* onFail(Throwable.class,recovertyFunction2)
* .onFail(IOException.class, recoveryFunction1)
* }
* </pre>
*
* recoveryFunction1 will not be called
*
* @param exceptionClass Class of exceptions to recover from
* @param fn Recovery function
* @return recovery value
*/
@Override
default LazySimpleReactStream<U> onFail(final Class<? extends Throwable> exceptionClass, final Function<? super SimpleReactFailedStageException, ? extends U> fn) {
final Function<PipelineBuilder, PipelineBuilder> mapper = (ft) -> ft.exceptionally((t) -> {
if (t instanceof FilteredExecutionPathException)
throw (FilteredExecutionPathException) t;
Throwable throwable = t;
if (t instanceof CompletionException)
throwable = ((Exception) t).getCause();
// exceptions from initial supplier won't be wrapper in SimpleReactFailedStageException
final SimpleReactFailedStageException simpleReactException = assureSimpleReactException(throwable);
if (exceptionClass.isAssignableFrom(simpleReactException.getCause().getClass()))
return fn.apply(simpleReactException);
throw simpleReactException;
});
return this.withLastActive(getLastActive().operation(mapper));
}
use of com.oath.cyclops.internal.react.async.future.PipelineBuilder in project cyclops by aol.
the class FastFutureTest method setup.
@Before
public void setup() {
failed = null;
future = new PipelineBuilder();
sizes = new ArrayList<>();
sizes2 = new ArrayList<>();
sizes3 = new ArrayList<>();
}
Aggregations