|
| 1 | +/** |
| 2 | + * Copyright 2013 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 | +package rx; |
| 17 | + |
| 18 | + |
| 19 | +/** |
| 20 | + * The Observable interface that implements the Reactive Pattern. |
| 21 | + * <p> |
| 22 | + * The documentation for this interface and its implementations makes use of |
| 23 | + * marble diagrams. The following legend explains these diagrams: |
| 24 | + * <p> |
| 25 | + * <img width="640" src="https://raw.github.com/wiki/Netflix/RxJava/images/rx-operators/legend.png"> |
| 26 | + * <p> |
| 27 | + * For more information see the |
| 28 | + * <a href="https://github.com/Netflix/RxJava/wiki/Observable">RxJava Wiki</a> |
| 29 | + * |
| 30 | + * @param <T> the type of the item emitted by the Observable. |
| 31 | + */ |
| 32 | +public interface IObservable<T> { |
| 33 | + |
| 34 | + /** |
| 35 | + * An {@link Observer} must call an Observable's {@code subscribe} method in |
| 36 | + * order to receive items and notifications from the Observable. |
| 37 | + * <p> |
| 38 | + * A typical implementation of {@code subscribe} does the following: |
| 39 | + * <ol> |
| 40 | + * <li>It stores a reference to the Observer in a collection object, such as |
| 41 | + * a {@code List<T>} object.</li> |
| 42 | + * <li>It returns a reference to the {@link Subscription} interface. This |
| 43 | + * enables Observers to unsubscribe, that is, to stop receiving items |
| 44 | + * and notifications before the Observable stops sending them, which |
| 45 | + * also invokes the Observer's {@link Observer#onCompleted onCompleted} |
| 46 | + * method.</li> |
| 47 | + * </ol><p> |
| 48 | + * An <code>IObservable<T></code> instance is responsible for accepting |
| 49 | + * all subscriptions and notifying all Observers. Unless the documentation |
| 50 | + * for a particular <code>IObservable<T></code> implementation |
| 51 | + * indicates otherwise, Observers should make no assumptions about the order |
| 52 | + * in which multiple Observers will receive their notifications. |
| 53 | + * <p> |
| 54 | + * For more information see the |
| 55 | + * <a href="https://github.com/Netflix/RxJava/wiki/Observable">RxJava Wiki</a> |
| 56 | + * |
| 57 | + * @param observer the Observer |
| 58 | + * @return a {@link Subscription} reference with which the {@link Observer} |
| 59 | + * can stop receiving items before the Observable has finished |
| 60 | + * sending them |
| 61 | + * @throws IllegalArgumentException if the {@link Observer} provided as the |
| 62 | + * argument to {@code subscribe()} is |
| 63 | + * {@code null}. |
| 64 | + */ |
| 65 | + public abstract Subscription subscribe(Observer<? super T> observer); |
| 66 | + |
| 67 | +} |
0 commit comments