| /* |
| * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved. |
| * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| * |
| * This code is free software; you can redistribute it and/or modify it |
| * under the terms of the GNU General Public License version 2 only, as |
| * published by the Free Software Foundation. |
| * |
| * This code is distributed in the hope that it will be useful, but WITHOUT |
| * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| * version 2 for more details (a copy is included in the LICENSE file that |
| * accompanied this code). |
| * |
| * You should have received a copy of the GNU General Public License version |
| * 2 along with this work; if not, write to the Free Software Foundation, |
| * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| * |
| * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
| * or visit www.oracle.com if you need additional information or have any |
| * questions. |
| */ |
| |
| package org.reactivestreams; |
| |
| /** |
| * Will receive call to {@link #onSubscribe(Subscription)} once after passing an instance of {@link Subscriber} to {@link Publisher#subscribe(Subscriber)}. |
| * <p> |
| * No further notifications will be received until {@link Subscription#request(long)} is called. |
| * <p> |
| * After signaling demand: |
| * <ul> |
| * <li>One or more invocations of {@link #onNext(Object)} up to the maximum number defined by {@link Subscription#request(long)}</li> |
| * <li>Single invocation of {@link #onError(Throwable)} or {@link Subscriber#onComplete()} which signals a terminal state after which no further events will be sent. |
| * </ul> |
| * <p> |
| * Demand can be signaled via {@link Subscription#request(long)} whenever the {@link Subscriber} instance is capable of handling more. |
| * |
| * @param <T> the type of element signaled. |
| */ |
| public interface Subscriber<T> { |
| /** |
| * Invoked after calling {@link Publisher#subscribe(Subscriber)}. |
| * <p> |
| * No data will start flowing until {@link Subscription#request(long)} is invoked. |
| * <p> |
| * It is the responsibility of this {@link Subscriber} instance to call {@link Subscription#request(long)} whenever more data is wanted. |
| * <p> |
| * The {@link Publisher} will send notifications only in response to {@link Subscription#request(long)}. |
| * |
| * @param s |
| * {@link Subscription} that allows requesting data via {@link Subscription#request(long)} |
| */ |
| public void onSubscribe(Subscription s); |
| |
| /** |
| * Data notification sent by the {@link Publisher} in response to requests to {@link Subscription#request(long)}. |
| * |
| * @param t the element signaled |
| */ |
| public void onNext(T t); |
| |
| /** |
| * Failed terminal state. |
| * <p> |
| * No further events will be sent even if {@link Subscription#request(long)} is invoked again. |
| * |
| * @param t the throwable signaled |
| */ |
| public void onError(Throwable t); |
| |
| /** |
| * Successful terminal state. |
| * <p> |
| * No further events will be sent even if {@link Subscription#request(long)} is invoked again. |
| */ |
| public void onComplete(); |
| } |