src/jdk.incubator.httpclient/share/classes/jdk/incubator/http/internal/common/FlowTube.java
branchhttp-client-branch
changeset 55909 583695a0ed6a
parent 55763 634d8e14c172
child 55973 4d9b002587db
equal deleted inserted replaced
55908:a36a236e55d8 55909:583695a0ed6a
    38  * <p>
    38  * <p>
    39  * The {@code connectFlows} method should be called to connect the bidirectional
    39  * The {@code connectFlows} method should be called to connect the bidirectional
    40  * flow. A FlowTube supports handing over the same read subscription to different
    40  * flow. A FlowTube supports handing over the same read subscription to different
    41  * sequential read subscribers over time. When {@code connectFlows(writePublisher,
    41  * sequential read subscribers over time. When {@code connectFlows(writePublisher,
    42  * readSubscriber} is called, the FlowTube will call {@code dropSubscription} on
    42  * readSubscriber} is called, the FlowTube will call {@code dropSubscription} on
    43  * its former readSubscriber, and {@code onConnection} on its new readSubscriber.
    43  * its former readSubscriber, and {@code onSubscribe} on its new readSubscriber.
    44  * By default, the implementation of {@code onConnection} is to call
       
    45  * {@code onSubscribe}, but a subscriber that needs to subscribe sequentially
       
    46  * several times to the same FlowTube may override the default implementation
       
    47  * to ensure that {@code onSubscribe} is called only once.
       
    48  *
       
    49  */
    44  */
    50 public interface FlowTube extends
    45 public interface FlowTube extends
    51        Flow.Publisher<List<ByteBuffer>>,
    46        Flow.Publisher<List<ByteBuffer>>,
    52        Flow.Subscriber<List<ByteBuffer>> {
    47        Flow.Subscriber<List<ByteBuffer>> {
    53 
    48 
    57      * by calling {@code dropSubscription()}.
    52      * by calling {@code dropSubscription()}.
    58      * Once {@code dropSubscription()} is called, the {@code TubeSubscriber}
    53      * Once {@code dropSubscription()} is called, the {@code TubeSubscriber}
    59      * should stop calling any method on its subscription.
    54      * should stop calling any method on its subscription.
    60      */
    55      */
    61     static interface TubeSubscriber extends Flow.Subscriber<List<ByteBuffer>> {
    56     static interface TubeSubscriber extends Flow.Subscriber<List<ByteBuffer>> {
    62         /**
       
    63          * Called by {@code FlowTube.connectFlows}.
       
    64          * @param subscription the subscription.
       
    65          * @implSpec By default this method call {@code this.onSubscribe()}.
       
    66          */
       
    67         default void onConnection(Flow.Subscription subscription) {
       
    68             onSubscribe(subscription);
       
    69         }
       
    70 
    57 
    71         /**
    58         /**
    72          * Called when the flow is connected again, and the subscription
    59          * Called when the flow is connected again, and the subscription
    73          * is handed over to a new subscriber.
    60          * is handed over to a new subscriber.
    74          * Once {@code dropSubscription()} is called, the {@code TubeSubscriber}
    61          * Once {@code dropSubscription()} is called, the {@code TubeSubscriber}
   174                 this.delegate = delegate;
   161                 this.delegate = delegate;
   175             }
   162             }
   176             @Override
   163             @Override
   177             public void dropSubscription() {}
   164             public void dropSubscription() {}
   178             @Override
   165             @Override
   179             public void onConnection(Flow.Subscription subscription) {
       
   180                 delegate.onSubscribe(subscription);
       
   181             }
       
   182             @Override
       
   183             public void onSubscribe(Flow.Subscription subscription) {
   166             public void onSubscribe(Flow.Subscription subscription) {
   184                 delegate.onSubscribe(subscription);
   167                 delegate.onSubscribe(subscription);
   185             }
   168             }
   186             @Override
   169             @Override
   187             public void onNext(List<ByteBuffer> item) {
   170             public void onNext(List<ByteBuffer> item) {