Debian Codegraph @

src/main/java/io/reactivex/rxjava3/processors/FlowableProcessor.java

raw
1 /*
2 * Copyright (c) 2016-present, RxJava Contributors.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
5 * compliance with the License. You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software distributed under the License is
10 * distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See
11 * the License for the specific language governing permissions and limitations under the License.
12 */
13
14 package io.reactivex.rxjava3.processors;
15
16 import org.reactivestreams.Processor;
17
18 import io.reactivex.rxjava3.annotations.*;
19 import io.reactivex.rxjava3.core.*;
20
21 /**
22 * Represents a Subscriber and a Flowable (Publisher) at the same time, allowing
23 * multicasting events from a single source to multiple child Subscribers.
24 * <p>All methods except the onSubscribe, onNext, onError and onComplete are thread-safe.
25 * Use {@link #toSerialized()} to make these methods thread-safe as well.
26 *
27 * @param <T> the item value type
28 */
29 public abstract class FlowableProcessor<@NonNull T> extends Flowable<T> implements Processor<T, T>, FlowableSubscriber<T> {
30
31 /**
32 * Returns true if the FlowableProcessor has subscribers.
33 * <p>The method is thread-safe.
34 * @return true if the FlowableProcessor has subscribers
35 */
36 @CheckReturnValue
37 public abstract boolean hasSubscribers();
38
39 /**
40 * Returns true if the FlowableProcessor has reached a terminal state through an error event.
41 * <p>The method is thread-safe.
42 * @return true if the FlowableProcessor has reached a terminal state through an error event
43 * @see #getThrowable()
44 * @see #hasComplete()
45 */
46 @CheckReturnValue
47 public abstract boolean hasThrowable();
48
49 /**
50 * Returns true if the FlowableProcessor has reached a terminal state through a complete event.
51 * <p>The method is thread-safe.
52 * @return true if the FlowableProcessor has reached a terminal state through a complete event
53 * @see #hasThrowable()
54 */
55 @CheckReturnValue
56 public abstract boolean hasComplete();
57
58 /**
59 * Returns the error that caused the FlowableProcessor to terminate or null if the FlowableProcessor
60 * hasn't terminated yet.
61 * <p>The method is thread-safe.
62 * @return the error that caused the FlowableProcessor to terminate or null if the FlowableProcessor
63 * hasn't terminated yet
64 */
65 @Nullable
66 @CheckReturnValue
67 public abstract Throwable getThrowable();
68
69 /**
70 * Wraps this FlowableProcessor and serializes the calls to the onSubscribe, onNext, onError and
71 * onComplete methods, making them thread-safe.
72 * <p>The method is thread-safe.
73 * @return the wrapped and serialized FlowableProcessor
74 */
75 @NonNull
76 @CheckReturnValue
77 public final FlowableProcessor<T> toSerialized() {
78 if (this instanceof SerializedProcessor) {
79 return this;
80 }
81 return new SerializedProcessor<>(this);
82 }
83 }