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

pack-priv Class Http1AsyncReceiver

extends Object
Class Inheritance
Imports
java.io.EOFException, .IOException, java.nio.ByteBuffer, java.util.Arrays, .HashSet, .List, .Set, java.util.concurrent.ConcurrentLinkedDeque, .Executor, .ExecutorService, .Flow, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReference, java.util.function.Consumer, jdk.internal.net.http.common.Demand, .FlowTube.TubeSubscriber, .Log, .Logger, .MinimalFuture, .SequentialScheduler, .ConnectionExpiredException, .Utils

A helper class that will queue up incoming data until the receiving side is ready to handle it.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv static interface
Http1AsyncReceiver.Http1AsyncDelegate

A delegate that can asynchronously receive data from an upstream flow, parse, it, then possibly transform it and either store it (response headers) or possibly pass it to a downstream subscriber (response body).

private static class
Http1AsyncReceiver.Http1AsyncDelegateSubscription

A simple subclass of AbstractSubscription that ensures the SequentialScheduler will be run when request() is called and demand becomes positive again.

pack-priv class
Http1AsyncReceiver.Http1TubeSubscriber

A simple tube subscriber for reading from the connection flow.

Field Summary

Modifier and TypeField and Description
pack-priv final AtomicBoolean
private final HttpClientImpl
pack-priv volatile String
pack-priv final Logger
private volatile Http1AsyncReceiver.Http1AsyncDelegate
private volatile Throwable
private final Executor
private volatile Http1Exchange<?>
private final AtomicReference<Http1AsyncReceiver.Http1AsyncDelegate>
private final ConcurrentLinkedDeque<ByteBuffer>
private final AtomicLong
private boolean
private final SequentialScheduler
private volatile boolean
private final Http1AsyncReceiver.Http1TubeSubscriber
pack-priv final MinimalFuture<Void>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
private void
checkForErrors()

Must be called from within the scheduler main loop.

private void
checkRequestMore()

Must be called from within the scheduler main loop.

pack-priv void
pack-priv String
private String
private String
pack-priv ByteBuffer
drain(ByteBuffer initial)

private void
private boolean

Returns:

true if there was some pending delegate subscription and a new delegate was subscribed, false otherwise.
handlePendingDelegate
()

Must be called from within the scheduler main loop.

private boolean

Returns:

true if the delegate is not null and has some demand
hasDemand
(Http1AsyncReceiver.Http1AsyncDelegate
The Http1AsyncDelegate delegate
delegate
)

Must be called from within the scheduler main loop.

pack-priv void
pack-priv long
pack-priv synchronized void
setRetryOnError(boolean retry)

pack-priv void
stop()

pack-priv void
pack-priv FlowTube.TubeSubscriber

Returns:

the TubeSubscriber for reading from the connection flow.
subscriber
()

Returns the TubeSubscriber for reading from the connection flow.

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

canRequestMoreback to summary
pack-priv final AtomicBoolean canRequestMore
clientback to summary
private final HttpClientImpl client
dbgTagback to summary
pack-priv volatile String dbgTag
debugback to summary
pack-priv final Logger debug
delegateback to summary
private volatile Http1AsyncReceiver.Http1AsyncDelegate delegate
errorback to summary
private volatile Throwable error
executorback to summary
private final Executor executor
ownerback to summary
private volatile Http1Exchange<?> owner
pendingDelegateRefback to summary
private final AtomicReference<Http1AsyncReceiver.Http1AsyncDelegate> pendingDelegateRef
queueback to summary
private final ConcurrentLinkedDeque<ByteBuffer> queue
receivedback to summary
private final AtomicLong received
retryback to summary
private boolean retry
schedulerback to summary
private final SequentialScheduler scheduler
stopRequestedback to summary
private volatile boolean stopRequested
subscriberback to summary
private final Http1AsyncReceiver.Http1TubeSubscriber subscriber
whenFinishedback to summary
pack-priv final MinimalFuture<Void> whenFinished

Constructor Detail

Http1AsyncReceiverback to summary
public Http1AsyncReceiver(Executor executor, Http1Exchange<?> owner)

Method Detail

asyncReceiveback to summary
private void asyncReceive(ByteBuffer buf)
checkForErrorsback to summary
private void checkForErrors()

Must be called from within the scheduler main loop. Handles any pending errors by calling delegate.onReadError(). If the error can be forwarded to the delegate, stops the scheduler.

checkRequestMoreback to summary
private void checkRequestMore()

Must be called from within the scheduler main loop. Figure out whether more data should be requested from the Http1TubeSubscriber.

clearback to summary
pack-priv void clear()
dbgStringback to summary
pack-priv String dbgString()
debugQBBback to summary
private String debugQBB(ByteBuffer[] qbb)
describeback to summary
private String describe()
drainback to summary
pack-priv ByteBuffer drain(ByteBuffer initial)
flushback to summary
private void flush()
handlePendingDelegateback to summary
private boolean handlePendingDelegate()

Must be called from within the scheduler main loop. Handles pending delegate subscription. Return true if there was some pending delegate subscription and a new delegate was subscribed, false otherwise.

Returns:boolean

true if there was some pending delegate subscription and a new delegate was subscribed, false otherwise.

hasDemandback to summary
private boolean hasDemand(Http1AsyncReceiver.Http1AsyncDelegate delegate)

Must be called from within the scheduler main loop. Return true if the delegate is not null and has some demand.

Parameters
delegate:Http1AsyncReceiver.Http1AsyncDelegate

The Http1AsyncDelegate delegate

Returns:boolean

true if the delegate is not null and has some demand

onReadErrorback to summary
pack-priv void onReadError(Throwable ex)
remainingback to summary
pack-priv long remaining()
setRetryOnErrorback to summary
pack-priv synchronized void setRetryOnError(boolean retry)
stopback to summary
pack-priv void stop()
subscribeback to summary
pack-priv void subscribe(Http1AsyncReceiver.Http1AsyncDelegate delegate)
subscriberback to summary
pack-priv FlowTube.TubeSubscriber subscriber()

Returns the TubeSubscriber for reading from the connection flow.

Returns:FlowTube.TubeSubscriber

the TubeSubscriber for reading from the connection flow.

unsubscribeback to summary
pack-priv void unsubscribe(Http1AsyncReceiver.Http1AsyncDelegate delegate)
jdk.internal.net.http back to summary

pack-priv Interface Http1AsyncReceiver.Http1AsyncDelegate

Known Direct Implementers
jdk.internal.net.http.Http1Response.Receiver

A delegate that can asynchronously receive data from an upstream flow, parse, it, then possibly transform it and either store it (response headers) or possibly pass it to a downstream subscriber (response body). Usually, there will be one Http1AsyncDelegate in charge of receiving and parsing headers, and another one in charge of receiving, parsing, and forwarding body. Each will sequentially subscribe with the Http1AsyncReceiver in turn. There may be additional delegates which subscribe to the Http1AsyncReceiver, mainly for the purpose of handling errors while the connection is busy transmitting the request body and the Http1Exchange::readBody method hasn't been called yet, and response delegates haven't subscribed yet.

Method Summary

Modifier and TypeMethod and Description
public void
close(Throwable
The Http1AsyncReceiver pending error ref, if any.
error
)

Called to make sure resources are released when the Http1AsyncReceiver is stopped.

public void
onReadError(Throwable
The raised Throwable.
ex
)

Called when an exception is raised.

public void
onSubscribe(AbstractSubscription
A subscription that allows the delegate to control the data flow.
s
)

Must be called before any other method on the delegate.

public AbstractSubscription

Returns:

the subscription that was passed to onSubscribe..
subscription
()

Returns the subscription that was passed to onSubscribe

public boolean

Returns:

false, if the byte buffer reference should be kept in the queue. Usually, this means that either the byte buffer reference was handled and parsing is finished, or that the receiver didn't handle the byte reference at all. There may or may not be any remaining data in the byte buffer, and the byte buffer reference must not have been cleared. true, if the byte buffer reference was fully read and more data can be received.
tryAsyncReceive
(ByteBuffer
A byte buffer reference coming from upstream.
ref
)

Receives and handles a byte buffer reference.

Method Detail

closeback to summary
public void close(Throwable error)

Called to make sure resources are released when the Http1AsyncReceiver is stopped.

Parameters
error:Throwable

The Http1AsyncReceiver pending error ref, if any.

onReadErrorback to summary
public void onReadError(Throwable ex)

Called when an exception is raised.

Parameters
ex:Throwable

The raised Throwable.

onSubscribeback to summary
public void onSubscribe(AbstractSubscription s)

Must be called before any other method on the delegate. The subscription can be either used directly by the delegate to request more data (e.g. if the delegate is a header parser), or can be forwarded to a downstream subscriber (if the delegate is a body parser that wraps a response BodySubscriber). In all cases, it is the responsibility of the delegate to ensure that request(n) and demand.tryDecrement() are called appropriately. No data will be sent to tryAsyncReceive unless the subscription has some demand.

Parameters
s:AbstractSubscription

A subscription that allows the delegate to control the data flow.

subscriptionback to summary
public AbstractSubscription subscription()

Returns the subscription that was passed to onSubscribe

Returns:AbstractSubscription

the subscription that was passed to onSubscribe..

tryAsyncReceiveback to summary
public boolean tryAsyncReceive(ByteBuffer ref)

Receives and handles a byte buffer reference.

Parameters
ref:ByteBuffer

A byte buffer reference coming from upstream.

Returns:boolean

false, if the byte buffer reference should be kept in the queue. Usually, this means that either the byte buffer reference was handled and parsing is finished, or that the receiver didn't handle the byte reference at all. There may or may not be any remaining data in the byte buffer, and the byte buffer reference must not have been cleared. true, if the byte buffer reference was fully read and more data can be received.

jdk.internal.net.http back to summary

private final Class Http1AsyncReceiver.Http1AsyncDelegateSubscription

extends AbstractSubscription
Class Inheritance

A simple subclass of AbstractSubscription that ensures the SequentialScheduler will be run when request() is called and demand becomes positive again.

Field Summary

Modifier and TypeField and Description
private volatile boolean
private final Runnable
private final Consumer<Throwable>
private final SequentialScheduler

Constructor Summary

AccessConstructor and Description
pack-priv

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.

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 jdk.internal.net.http.AbstractSubscription:
demand

Field Detail

cancelledback to summary
private volatile boolean cancelled
onCancelback to summary
private final Runnable onCancel
onErrorback to summary
private final Consumer<Throwable> onError
schedulerback to summary
private final SequentialScheduler scheduler

Constructor Detail

Http1AsyncDelegateSubscriptionback to summary
pack-priv Http1AsyncDelegateSubscription(SequentialScheduler scheduler, Runnable onCancel, Consumer<Throwable> onError)

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
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 final Class Http1AsyncReceiver.Http1TubeSubscriber

extends Object
implements TubeSubscriber
Class Inheritance
All Implemented Interfaces
jdk.internal.net.http.common.FlowTube.TubeSubscriber, java.util.concurrent.Flow.Subscriber

A simple tube subscriber for reading from the connection flow.

Field Summary

Modifier and TypeField and Description
pack-priv volatile boolean
pack-priv volatile boolean
pack-priv volatile Flow.Subscription

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
dropSubscription()

Overrides default jdk.internal.net.http.common.FlowTube.TubeSubscriber.dropSubscription.

Called when the flow is connected again, and the subscription is handed over to a new subscriber.

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 throwable)

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.

pack-priv void
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

completedback to summary
pack-priv volatile boolean completed
droppedback to summary
pack-priv volatile boolean dropped
subscriptionback to summary
pack-priv volatile Flow.Subscription subscription

Constructor Detail

Http1TubeSubscriberback to summary
pack-priv Http1TubeSubscriber()

Method Detail

dropSubscriptionback to summary
public void dropSubscription()

Overrides default jdk.internal.net.http.common.FlowTube.TubeSubscriber.dropSubscription.

Doc from jdk.internal.net.http.common.FlowTube.TubeSubscriber.dropSubscription.

Called when the flow is connected again, and the subscription is handed over to a new subscriber. Once dropSubscription() is called, the TubeSubscriber should stop calling any method on its subscription.

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 throwable)

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.

requestMoreback to summary
pack-priv void requestMore()