io.smallrye.mutiny.helpers.spies.UniOnFailureSpy Maven / Gradle / Ivy
package io.smallrye.mutiny.helpers.spies;
import java.util.function.Predicate;
import io.smallrye.mutiny.Uni;
import io.smallrye.mutiny.groups.UniOnFailure;
import io.smallrye.mutiny.subscription.UniSubscriber;
public class UniOnFailureSpy extends UniSpyBase {
private Predicate super Throwable> predicate;
private Class extends Throwable> typeOfFailure;
private volatile Throwable lastFailure;
public Throwable lastFailure() {
return lastFailure;
}
@Override
public void reset() {
super.reset();
lastFailure = null;
}
UniOnFailureSpy(Uni upstream) {
super(upstream);
}
UniOnFailureSpy(Uni upstream, Predicate super Throwable> predicate) {
super(upstream);
this.predicate = predicate;
}
UniOnFailureSpy(Uni upstream, Class extends Throwable> typeOfFailure) {
super(upstream);
this.typeOfFailure = typeOfFailure;
}
@Override
public void subscribe(UniSubscriber super T> downstream) {
UniOnFailure extends T> group;
if (predicate != null) {
group = upstream().onFailure(predicate);
} else if (typeOfFailure != null) {
group = upstream().onFailure(typeOfFailure);
} else {
group = upstream().onFailure();
}
group.invoke(failure -> {
incrementInvocationCount();
lastFailure = failure;
}).subscribe().withSubscriber(downstream);
}
@Override
public String toString() {
return "UniOnFailureSpy{" +
"lastFailure=" + lastFailure +
"} " + super.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy