|
| 1 | +/** |
| 2 | + * Copyright 2016 Netflix, Inc. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package rx; |
| 18 | + |
| 19 | +import rx.annotations.Experimental; |
| 20 | +import rx.functions.Cancellable; |
| 21 | + |
| 22 | +/** |
| 23 | + * Abstraction over a RxJava Subscriber that allows associating |
| 24 | + * a resource with it and exposes the current number of downstream |
| 25 | + * requested amount. |
| 26 | + * <p> |
| 27 | + * The onNext, onError and onCompleted methods should be called |
| 28 | + * in a sequential manner, just like the Observer's methods. The |
| 29 | + * other methods are thread-safe. |
| 30 | + * |
| 31 | + * @param <T> the value type to emit |
| 32 | + * @since (if this graduates from Experimental/Beta to supported, replace this parenthetical with the release number) |
| 33 | + */ |
| 34 | +@Experimental |
| 35 | +public interface Emitter<T> extends Observer<T> { |
| 36 | + |
| 37 | + /** |
| 38 | + * Sets a Subscription on this emitter; any previous Subscription |
| 39 | + * or Cancellation will be unsubscribed/cancelled. |
| 40 | + * @param s the subscription, null is allowed |
| 41 | + */ |
| 42 | + void setSubscription(Subscription s); |
| 43 | + |
| 44 | + /** |
| 45 | + * Sets a Cancellable on this emitter; any previous Subscription |
| 46 | + * or Cancellation will be unsubscribed/cancelled. |
| 47 | + * @param c the cancellable resource, null is allowed |
| 48 | + */ |
| 49 | + void setCancellation(Cancellable c); |
| 50 | + /** |
| 51 | + * The current outstanding request amount. |
| 52 | + * <p>This method it thread-safe. |
| 53 | + * @return the current outstanding request amount |
| 54 | + */ |
| 55 | + long requested(); |
| 56 | + |
| 57 | + /** |
| 58 | + * Options to handle backpressure in the emitter. |
| 59 | + */ |
| 60 | + enum BackpressureMode { |
| 61 | + /** |
| 62 | + * No backpressure is applied as the onNext calls pass through the Emitter; |
| 63 | + * note that this may cause {@link rx.exceptions.MissingBackpressureException} or {@link IllegalStateException} |
| 64 | + * somewhere downstream. |
| 65 | + */ |
| 66 | + NONE, |
| 67 | + /** |
| 68 | + * Signals a {@link rx.exceptions.MissingBackpressureException} if the downstream can't keep up. |
| 69 | + */ |
| 70 | + ERROR, |
| 71 | + /** |
| 72 | + * Buffers (unbounded) all onNext calls until the downstream can consume them. |
| 73 | + */ |
| 74 | + BUFFER, |
| 75 | + /** |
| 76 | + * Drops the incoming onNext value if the downstream can't keep up. |
| 77 | + */ |
| 78 | + DROP, |
| 79 | + /** |
| 80 | + * Keeps the latest onNext value and overwrites it with newer ones until the downstream |
| 81 | + * can consume it. |
| 82 | + */ |
| 83 | + LATEST |
| 84 | + } |
| 85 | +} |
0 commit comments