APIdia Launch Partner
Top Description Inners Fields Constructors Methods
jdk.internal.net.http

public Class BufferingSubscriber<T>

extends Object
implements ResponseSubscribers.TrustedSubscriber<T>
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber, java.net.http.HttpResponse.BodySubscriber, java.util.concurrent.Flow.Subscriber
Imports
java.nio.ByteBuffer, java.util.ArrayList, .Collections, .List, .ListIterator, .Objects, java.util.concurrent.CompletionStage, .Flow, java.util.concurrent.atomic.AtomicBoolean, java.net.http.HttpResponse.BodySubscriber, jdk.internal.net.http.common.Demand, .SequentialScheduler, jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber

A buffering BodySubscriber. When subscribed, accumulates ( buffers ) a given amount ( in bytes ) of a publisher's data before pushing it to a downstream subscriber.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class
BufferingSubscriber.DownstreamSubscription

Subscription that is passed to the downstream subscriber.

Field Summary

Modifier and TypeField and Description
private long
accumulatedBytes

The actual accumulated remaining bytes in internalBuffers.

pack-priv static final int
private final int
bufferSize

The amount of data to be accumulate before pushing downstream.

private final Object
buffersLock

Must be held when accessing the internal buffers.

pack-priv static final int
pack-priv static final int
private final HttpResponse.BodySubscriber<T>
downstreamSubscriber

The downstream consumer of the data.

private volatile BufferingSubscriber<T>.DownstreamSubscription
downstreamSubscription

The downstream subscription, created lazily.

pack-priv static final int
private ArrayList<ByteBuffer>
internalBuffers

The internal buffers holding the buffered data.

private volatile int
private volatile Flow.Subscription
subscription

The subscription, created lazily.

private volatile Throwable
throwable

Holds the Throwable from upstream's onError.

pack-priv static final int
UNSUBSCRIBED

State of the buffering subscriber: 1) [UNSUBSCRIBED] when initially created 2) [ACTIVE] when subscribed and can receive data 3) [ERROR | CANCELLED | COMPLETE] (terminal state)

Constructor Summary

AccessConstructor and Description
public
BufferingSubscriber(HttpResponse.BodySubscriber<T> downstreamSubscriber, int bufferSize)

Method Summary

Modifier and TypeMethod and Description
private List<ByteBuffer>
fromInternalBuffers()

Returns a new, unmodifiable, List<ByteBuffer> containing exactly the amount of data as required before pushing downstream.

public CompletionStage<T>
getBody()

Implements java.net.http.HttpResponse.BodySubscriber.getBody.

Returns a CompletionStage which when completed will return the response body object.

private final boolean
hasEnoughAccumulatedBytes()

Tells whether, or not, there is at least a sufficient number of bytes accumulated in the internal buffers.

public boolean
needsExecutor()

Overrides default jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber.needsExecutor.

Returns true if getBody() should be called asynchronously.

public void
onComplete()

Implements java.util.concurrent.Flow.Subscriber.onComplete.

Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription.

public void
onError(Throwable incomingThrowable)

Implements java.util.concurrent.Flow.Subscriber.onError.

Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription.

public void
onNext(List<ByteBuffer> item)

Implements java.util.concurrent.Flow.Subscriber.onNext.

Method invoked with a Subscription's next item.

public void
onSubscribe(Flow.Subscription subscription)

Implements java.util.concurrent.Flow.Subscriber.onSubscribe.

Method invoked prior to invoking any other Subscriber methods for the given Subscription.

private static final long
remaining(List<ByteBuffer> buffers)

Returns the number of bytes remaining in the given buffers.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

accumulatedBytesback to summary
private long accumulatedBytes

The actual accumulated remaining bytes in internalBuffers.

ACTIVEback to summary
pack-priv static final int ACTIVE
bufferSizeback to summary
private final int bufferSize

The amount of data to be accumulate before pushing downstream.

buffersLockback to summary
private final Object buffersLock

Must be held when accessing the internal buffers.

CANCELLEDback to summary
pack-priv static final int CANCELLED
COMPLETEback to summary
pack-priv static final int COMPLETE
downstreamSubscriberback to summary
private final HttpResponse.BodySubscriber<T> downstreamSubscriber

The downstream consumer of the data.

downstreamSubscriptionback to summary
private volatile BufferingSubscriber<T>.DownstreamSubscription downstreamSubscription

The downstream subscription, created lazily.

ERRORback to summary
pack-priv static final int ERROR
internalBuffersback to summary
private ArrayList<ByteBuffer> internalBuffers

The internal buffers holding the buffered data.

stateback to summary
private volatile int state
subscriptionback to summary
private volatile Flow.Subscription subscription

The subscription, created lazily.

throwableback to summary
private volatile Throwable throwable

Holds the Throwable from upstream's onError.

UNSUBSCRIBEDback to summary
pack-priv static final int UNSUBSCRIBED

State of the buffering subscriber: 1) [UNSUBSCRIBED] when initially created 2) [ACTIVE] when subscribed and can receive data 3) [ERROR | CANCELLED | COMPLETE] (terminal state)

Constructor Detail

BufferingSubscriberback to summary
public BufferingSubscriber(HttpResponse.BodySubscriber<T> downstreamSubscriber, int bufferSize)

Method Detail

fromInternalBuffersback to summary
private List<ByteBuffer> fromInternalBuffers()

Returns a new, unmodifiable, List<ByteBuffer> containing exactly the amount of data as required before pushing downstream. The amount of data may be less than required ( bufferSize ), in the case where the subscriber is COMPLETE.

getBodyback to summary
public CompletionStage<T> getBody()

Implements java.net.http.HttpResponse.BodySubscriber.getBody.

Doc from java.net.http.HttpResponse.BodySubscriber.getBody.

Returns a CompletionStage which when completed will return the response body object. This method can be called at any time relative to the other Flow.Subscriber methods and is invoked using the client's executor.

Annotations
@Override
hasEnoughAccumulatedBytesback to summary
private final boolean hasEnoughAccumulatedBytes()

Tells whether, or not, there is at least a sufficient number of bytes accumulated in the internal buffers. If the subscriber is COMPLETE, and has some buffered data, then there is always enough ( to pass downstream ).

needsExecutorback to summary
public boolean needsExecutor()

Overrides default jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber.needsExecutor.

Doc from jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber.needsExecutor.

Returns true if getBody() should be called asynchronously.

Annotations
@Override
onCompleteback to summary
public void onComplete()

Implements java.util.concurrent.Flow.Subscriber.onComplete.

Doc from java.util.concurrent.Flow.Subscriber.onComplete.

Method invoked when it is known that no additional Subscriber method invocations will occur for a Subscription that is not already terminated by error, after which no other Subscriber methods are invoked by the Subscription. If this method throws an exception, resulting behavior is undefined.

Annotations
@Override
onErrorback to summary
public void onError(Throwable incomingThrowable)

Implements java.util.concurrent.Flow.Subscriber.onError.

Doc from java.util.concurrent.Flow.Subscriber.onError.

Method invoked upon an unrecoverable error encountered by a Publisher or Subscription, after which no other Subscriber methods are invoked by the Subscription. If this method itself throws an exception, resulting behavior is undefined.

Annotations
@Override
onNextback to summary
public void onNext(List<ByteBuffer> item)

Implements java.util.concurrent.Flow.Subscriber.onNext.

Doc from java.util.concurrent.Flow.Subscriber.onNext.

Method invoked with a Subscription's next item. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription to be cancelled.

Annotations
@Override
onSubscribeback to summary
public void onSubscribe(Flow.Subscription subscription)

Implements java.util.concurrent.Flow.Subscriber.onSubscribe.

Doc from java.util.concurrent.Flow.Subscriber.onSubscribe.

Method invoked prior to invoking any other Subscriber methods for the given Subscription. If this method throws an exception, resulting behavior is not guaranteed, but may cause the Subscription not to be established or to be cancelled.

Typically, implementations of this method invoke subscription.request to enable receiving items.

Annotations
@Override
remainingback to summary
private static final long remaining(List<ByteBuffer> buffers)

Returns the number of bytes remaining in the given buffers.

jdk.internal.net.http back to summary

private Class BufferingSubscriber.DownstreamSubscription

extends Object
implements Subscription
Class Inheritance
  • java.lang.Object
  • jdk.internal.net.http.BufferingSubscriber.DownstreamSubscription
All Implemented Interfaces
java.util.concurrent.Flow.Subscription

Subscription that is passed to the downstream subscriber.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class

Field Summary

Modifier and TypeField and Description
private final AtomicBoolean
private final Demand
private volatile boolean
private final SequentialScheduler

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public void
cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages.

pack-priv void
public void
request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

cancelledback to summary
private final AtomicBoolean cancelled
demandback to summary
private final Demand demand
illegalArgback to summary
private volatile boolean illegalArg
pushDemandedSchedulerback to summary
private final SequentialScheduler pushDemandedScheduler

Constructor Detail

DownstreamSubscriptionback to summary
private DownstreamSubscription()

Method Detail

cancelback to summary
public void cancel()

Implements java.util.concurrent.Flow.Subscription.cancel.

Doc from java.util.concurrent.Flow.Subscription.cancel.

Causes the Subscriber to (eventually) stop receiving messages. Implementation is best-effort -- additional messages may be received after invoking this method. A cancelled subscription need not ever receive an onComplete or onError signal.

Annotations
@Override
pushDemandedback to summary
pack-priv void pushDemanded()
requestback to summary
public void request(long n)

Implements java.util.concurrent.Flow.Subscription.request.

Doc from java.util.concurrent.Flow.Subscription.request.

Adds the given number n of items to the current unfulfilled demand for this subscription. If n is less than or equal to zero, the Subscriber will receive an onError signal with an IllegalArgumentException argument. Otherwise, the Subscriber will receive up to n additional onNext invocations (or fewer if terminated).

Annotations
@Override
jdk.internal.net.http back to summary

pack-priv Class BufferingSubscriber.DownstreamSubscription.PushDemandedTask

extends CompleteRestartableTask
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
Inherited from jdk.internal.net.http.common.SequentialScheduler.CompleteRestartableTask:
run

Constructor Detail

PushDemandedTaskback to summary
pack-priv PushDemandedTask()