/* * Copyright (c) 2011-2017 Pivotal Software Inc, All Rights Reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package reactor.core.publisher; import java.util.function.Consumer; import java.util.function.LongConsumer; import org.reactivestreams.Subscriber; import org.reactivestreams.Subscription; import reactor.core.Fuseable.ConditionalSubscriber; import reactor.core.publisher.FluxPeekFuseable.PeekConditionalSubscriber; /** * Peeks out values that make a filter function return false. * * @param <T> the value type * @see <a href="https://github.com/reactor/reactive-streams-commons">Reactive-Streams-Commons</a> */ final class MonoPeek<T> extends MonoSource<T, T> implements SignalPeek<T> { final Consumer<? super Subscription> onSubscribeCall; final Consumer<? super T> onNextCall; final Consumer<? super Throwable> onErrorCall; final Runnable onCompleteCall; final Runnable onAfterTerminateCall; final LongConsumer onRequestCall; final Runnable onCancelCall; MonoPeek(Mono<? extends T> source, Consumer<? super Subscription> onSubscribeCall, Consumer<? super T> onNextCall, Consumer<? super Throwable> onErrorCall, Runnable onCompleteCall, Runnable onAfterTerminateCall, LongConsumer onRequestCall, Runnable onCancelCall) { super(source); this.onSubscribeCall = onSubscribeCall; this.onNextCall = onNextCall; this.onErrorCall = onErrorCall; this.onCompleteCall = onCompleteCall; this.onAfterTerminateCall = onAfterTerminateCall; this.onRequestCall = onRequestCall; this.onCancelCall = onCancelCall; } @Override @SuppressWarnings("unchecked") public void subscribe(Subscriber<? super T> s) { if (s instanceof ConditionalSubscriber) { source.subscribe(new PeekConditionalSubscriber<>( (ConditionalSubscriber<? super T>)s, this)); return; } source.subscribe(new FluxPeek.PeekSubscriber<>(s, this)); } @Override public Consumer<? super Subscription> onSubscribeCall() { return onSubscribeCall; } @Override public Consumer<? super T> onNextCall() { return onNextCall; } @Override public Consumer<? super Throwable> onErrorCall() { return onErrorCall; } @Override public Runnable onCompleteCall() { return onCompleteCall; } @Override public Runnable onAfterTerminateCall() { return onAfterTerminateCall; } @Override public LongConsumer onRequestCall() { return onRequestCall; } @Override public Runnable onCancelCall() { return onCancelCall; } }