use of com.oath.cyclops.react.SimpleReactFailedStageException 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.react.SimpleReactFailedStageException in project cyclops by aol.
the class CaptureTest method capture.
@Test
public void capture() throws InterruptedException {
t = null;
new SimpleReact().of("hello", "world").capture(e -> t = e).peek(System.out::println).then(this::exception).peek(System.out::println).then(s -> "hello" + s).run();
Thread.sleep(500);
assertNotNull(t);
assertFalse(t.toString(), t instanceof SimpleReactFailedStageException);
assertTrue(t.toString(), t instanceof InternalException);
}
use of com.oath.cyclops.react.SimpleReactFailedStageException in project cyclops by aol.
the class CaptureTest method captureLazy.
@Test
public void captureLazy() {
t = null;
new LazyReact().of("hello", "world").capture(e -> t = e).peek(System.out::println).then(this::exception).forEach(System.out::println);
assertNotNull(t);
assertFalse(t.toString(), t instanceof SimpleReactFailedStageException);
assertTrue(t.toString(), t instanceof InternalException);
}
use of com.oath.cyclops.react.SimpleReactFailedStageException in project cyclops by aol.
the class CaptureTest method captureLast.
@Test
public void captureLast() throws InterruptedException {
t = null;
new SimpleReact().of("hello", "world").capture(e -> t = e).peek(System.out::println).peek(System.out::println).then(s -> "hello" + s).then(this::exception).run();
Thread.sleep(500);
assertNotNull(t);
assertFalse(t.toString(), t instanceof SimpleReactFailedStageException);
assertTrue(t.toString(), t instanceof InternalException);
}
Aggregations