test/jdk/java/net/httpclient/reactivestreams-tck/org/reactivestreams/Subscriber.java
changeset 55546 3ae57bbf9585
equal deleted inserted replaced
55545:8a153a932d0f 55546:3ae57bbf9585
       
     1 /*
       
     2  * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
       
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4  *
       
     5  * This code is free software; you can redistribute it and/or modify it
       
     6  * under the terms of the GNU General Public License version 2 only, as
       
     7  * published by the Free Software Foundation.
       
     8  *
       
     9  * This code is distributed in the hope that it will be useful, but WITHOUT
       
    10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    12  * version 2 for more details (a copy is included in the LICENSE file that
       
    13  * accompanied this code).
       
    14  *
       
    15  * You should have received a copy of the GNU General Public License version
       
    16  * 2 along with this work; if not, write to the Free Software Foundation,
       
    17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    18  *
       
    19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    20  * or visit www.oracle.com if you need additional information or have any
       
    21  * questions.
       
    22  */
       
    23 
       
    24 package org.reactivestreams;
       
    25 
       
    26 /**
       
    27  * Will receive call to {@link #onSubscribe(Subscription)} once after passing an instance of {@link Subscriber} to {@link Publisher#subscribe(Subscriber)}.
       
    28  * <p>
       
    29  * No further notifications will be received until {@link Subscription#request(long)} is called.
       
    30  * <p>
       
    31  * After signaling demand:
       
    32  * <ul>
       
    33  * <li>One or more invocations of {@link #onNext(Object)} up to the maximum number defined by {@link Subscription#request(long)}</li>
       
    34  * <li>Single invocation of {@link #onError(Throwable)} or {@link Subscriber#onComplete()} which signals a terminal state after which no further events will be sent.
       
    35  * </ul>
       
    36  * <p>
       
    37  * Demand can be signaled via {@link Subscription#request(long)} whenever the {@link Subscriber} instance is capable of handling more.
       
    38  *
       
    39  * @param <T> the type of element signaled.
       
    40  */
       
    41 public interface Subscriber<T> {
       
    42     /**
       
    43      * Invoked after calling {@link Publisher#subscribe(Subscriber)}.
       
    44      * <p>
       
    45      * No data will start flowing until {@link Subscription#request(long)} is invoked.
       
    46      * <p>
       
    47      * It is the responsibility of this {@link Subscriber} instance to call {@link Subscription#request(long)} whenever more data is wanted.
       
    48      * <p>
       
    49      * The {@link Publisher} will send notifications only in response to {@link Subscription#request(long)}.
       
    50      *
       
    51      * @param s
       
    52      *            {@link Subscription} that allows requesting data via {@link Subscription#request(long)}
       
    53      */
       
    54     public void onSubscribe(Subscription s);
       
    55 
       
    56     /**
       
    57      * Data notification sent by the {@link Publisher} in response to requests to {@link Subscription#request(long)}.
       
    58      *
       
    59      * @param t the element signaled
       
    60      */
       
    61     public void onNext(T t);
       
    62 
       
    63     /**
       
    64      * Failed terminal state.
       
    65      * <p>
       
    66      * No further events will be sent even if {@link Subscription#request(long)} is invoked again.
       
    67      *
       
    68      * @param t the throwable signaled
       
    69      */
       
    70     public void onError(Throwable t);
       
    71 
       
    72     /**
       
    73      * Successful terminal state.
       
    74      * <p>
       
    75      * No further events will be sent even if {@link Subscription#request(long)} is invoked again.
       
    76      */
       
    77     public void onComplete();
       
    78 }