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

public Class HttpBodySubscriberWrapper<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
Known Direct Subclasses
jdk.internal.net.http.Http1Exchange.Http1ResponseBodySubscriber, jdk.internal.net.http.Http3ExchangeImpl.Http3StreamResponseSubscriber, jdk.internal.net.http.Http3PushPromiseStream.Http3PushStreamResponseSubscriber, jdk.internal.net.http.Stream.Http2StreamResponseSubscriber
Type Parameters
<T>
the type of the response body
Imports
java.net.http.HttpResponse.BodySubscriber, java.nio.ByteBuffer, java.util.Comparator, .List, .Objects, java.util.concurrent.CompletionStage, .Flow, .Flow.Subscription, java.util.concurrent.atomic.AtomicLong, java.util.concurrent.locks.ReentrantLock, jdk.internal.net.http.ResponseSubscribers.TrustedSubscriber

A class that wraps a user supplied BodySubscriber, but on which onError(Throwable) can be invoked at any time, even before onSubscribe(Subscription) has not been called yet.

Nested and Inner Type Summary

Modifier and TypeClass and Description
private class

Field Summary

Modifier and TypeField and Description
pack-priv static final int
public static final Comparator<HttpBodySubscriberWrapper<?>>
pack-priv static final int
pack-priv final long
pack-priv static final AtomicLong
public static final Flow.Subscription
pack-priv static final int
private volatile int
pack-priv static final int
pack-priv volatile HttpBodySubscriberWrapper<T>.SubscriptionWrapper
pack-priv final ReentrantLock
pack-priv static final int
pack-priv final HttpResponse.BodySubscriber<T>
pack-priv volatile Throwable

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final boolean

Returns:

true if this subscriber's subscription has already been cancelled
cancelled
()

Returns true if this subscriber's subscription has already been cancelled.

public final void
complete(Throwable
a throwable, or null
t
)

Complete the subscriber, either normally or exceptionally ensure that the subscriber is completed only once.

public final boolean

Returns:

true if this subscriber has already completed, either normally or abnormally
completed
()

Returns true if this subscriber has already completed, either normally or abnormally.

public CompletionStage<T>
getBody()

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

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

pack-priv final long
id()

protected void
private boolean
private boolean
private boolean
private final boolean
markState(final int flag)

private boolean
private boolean
public boolean
needsExecutor()

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

Returns true if getBody() should be called asynchronously.

protected void
onCancel()

Called when the subscriber cancels its subscription.

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.

protected void
onTermination()

A callback to be invoked before termination, whether due to the completion or failure of the subscriber, or cancellation of the subscription.

private void
protected void
register()

This method can be implemented by subclasses to perform registration actions.

public final boolean

Returns:

true if this subscriber has already been registered
registered
()

Returns true if this subscriber has already been registered.

public final boolean

Returns:

true if this subscriber has already subscribed
subscribed
()

Returns true if this subscriber has already subscribed.

protected final boolean

Returns:

true if register() was called, false otherwise.
tryRegister
()

This method attempts to mark the state of this object as registered, and then call the register() method.

protected final boolean

Returns:

true if unregister() was called, false otherwise.
tryUnregister
()

This method attempts to mark the state of this object as unregistered, and then call the unregister() method.

protected void
unregister()

This method can be implemented by subclasses to perform unregistration actions.

public final boolean

Returns:

true if this subscriber has already been unregistered
unregistered
()

Returns true if this subscriber has already been unregistered.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

CANCELLEDback to summary
pack-priv static final int CANCELLED
COMPARE_BY_IDback to summary
public static final Comparator<HttpBodySubscriberWrapper<?>> COMPARE_BY_ID
COMPLETEDback to summary
pack-priv static final int COMPLETED
idback to summary
pack-priv final long id
IDSback to summary
pack-priv static final AtomicLong IDS
NOPback to summary
public static final Flow.Subscription NOP
REGISTEREDback to summary
pack-priv static final int REGISTERED
stateback to summary
private volatile int state
SUBSCRIBEDback to summary
pack-priv static final int SUBSCRIBED
subscriptionback to summary
pack-priv volatile HttpBodySubscriberWrapper<T>.SubscriptionWrapper subscription
subscriptionLockback to summary
pack-priv final ReentrantLock subscriptionLock
UNREGISTEREDback to summary
pack-priv static final int UNREGISTERED
userSubscriberback to summary
pack-priv final HttpResponse.BodySubscriber<T> userSubscriber
withErrorback to summary
pack-priv volatile Throwable withError

Constructor Detail

HttpBodySubscriberWrapperback to summary
public HttpBodySubscriberWrapper(HttpResponse.BodySubscriber<T> userSubscriber)

Method Detail

cancelledback to summary
public final boolean cancelled()

Returns true if this subscriber's subscription has already been cancelled.

Returns:boolean

true if this subscriber's subscription has already been cancelled

completeback to summary
public final void complete(Throwable t)

Complete the subscriber, either normally or exceptionally ensure that the subscriber is completed only once.

Implementation Specification

If not completed() yet, this method calls tryUnregister()

Parameters
t:Throwable

a throwable, or null

completedback to summary
public final boolean completed()

Returns true if this subscriber has already completed, either normally or abnormally.

Returns:boolean

true if this subscriber has already completed, either normally or abnormally

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
idback to summary
pack-priv final long id()
logCompleteback to summary
protected void logComplete(Throwable error)
markCancelledback to summary
private boolean markCancelled()
markCompletedback to summary
private boolean markCompleted()
markRegisteredback to summary
private boolean markRegistered()
markStateback to summary
private final boolean markState(final int flag)
markSubscribedback to summary
private boolean markSubscribed()
markUnregisteredback to summary
private boolean markUnregistered()
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
onCancelback to summary
protected void onCancel()

Called when the subscriber cancels its subscription.

API Note

This method may be used by subclasses to perform cleanup actions after a subscription has been cancelled.

Implementation Specification

This method calls tryUnregister()

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.

Annotations
@Override
onTerminationback to summary
protected void onTermination()

A callback to be invoked before termination, whether due to the completion or failure of the subscriber, or cancellation of the subscription. To be precise, this method is called before onComplete(), onError(), or onCancel().

propagateErrorback to summary
private void propagateError(Throwable t)
registerback to summary
protected void register()

This method can be implemented by subclasses to perform registration actions. It will not be called if already registered or unregistered.

API Note

This method is called while holding a subscription lock.

See Also
tryRegister()
registeredback to summary
public final boolean registered()

Returns true if this subscriber has already been registered.

Returns:boolean

true if this subscriber has already been registered

subscribedback to summary
public final boolean subscribed()

Returns true if this subscriber has already subscribed.

Returns:boolean

true if this subscriber has already subscribed

tryRegisterback to summary
protected final boolean tryRegister()

This method attempts to mark the state of this object as registered, and then call the register() method.

The state will be marked as registered, and the register() method will be called only if not already registered or unregistered, or cancelled, or completed.

Returns:boolean

true if register() was called, false otherwise.

tryUnregisterback to summary
protected final boolean tryUnregister()

This method attempts to mark the state of this object as unregistered, and then call the unregister() method.

The unregister() method will be called only if already registered and not yet unregistered. Whether unregister() is called or not, the state is marked as unregistered, to prevent tryRegister() from calling register() after tryUnregister() has been called.

Returns:boolean

true if unregister() was called, false otherwise.

unregisterback to summary
protected void unregister()

This method can be implemented by subclasses to perform unregistration actions. It will not be called if not already registered, or already unregistered.

API Note

This method is called while holding a subscription lock.

See Also
tryUnregister()
unregisteredback to summary
public final boolean unregistered()

Returns true if this subscriber has already been unregistered.

Returns:boolean

true if this subscriber has already been unregistered

jdk.internal.net.http.common back to summary

private final Class HttpBodySubscriberWrapper.SubscriptionWrapper

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

Field Summary

Modifier and TypeField and Description
pack-priv final Flow.Subscription

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 java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

subscriptionback to summary
pack-priv final Flow.Subscription subscription

Constructor Detail

SubscriptionWrapperback to summary
pack-priv SubscriptionWrapper(Flow.Subscription s)

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