use of com.oath.cyclops.internal.react.exceptions.FilteredExecutionPathException 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.exceptions.FilteredExecutionPathException in project cyclops by aol.
the class Runner method handleFilter.
private <T> void handleFilter(final Continuation[] cont, final FastFuture<T> f) {
final AtomicInteger called = new AtomicInteger(0);
f.essential(event -> {
if (event.exception != null && event.exception.getCause() instanceof FilteredExecutionPathException) {
if (called.compareAndSet(0, 1))
cont[0].proceed();
}
});
}
Aggregations