reactivefeign.jetty.utils.ProxyPostProcessor Maven / Gradle / Ivy
package reactivefeign.jetty.utils;
import org.eclipse.jetty.reactive.client.internal.AbstractSingleProcessor;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import java.util.function.BiConsumer;
public class ProxyPostProcessor extends AbstractSingleProcessor{
private final Publisher publisher;
private final BiConsumer postProcessor;
private ProxyPostProcessor(Publisher publisher, BiConsumer postProcessor) {
this.publisher = publisher;
this.postProcessor = postProcessor;
}
@Override
public void onNext(I i) {
try {
downStreamOnNext(i);
postProcessor.accept(i, null);
} catch (Throwable err) {
postProcessor.accept(i, err);
}
}
@Override
public void subscribe(Subscriber super I> s) {
publisher.subscribe(this);
super.subscribe(s);
}
public static Publisher postProcess(Publisher publisher, BiConsumer postProcessor){
return new ProxyPostProcessor<>(publisher, postProcessor);
}
}