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

public abstract Class SubscriberWrapper

extends Object
implements TubeSubscriber, Closeable, Flow.Processor<List<ByteBuffer>, List<ByteBuffer>>
Class Inheritance
All Implemented Interfaces
java.util.concurrent.Flow.Processor, java.util.concurrent.Flow.Publisher, java.util.concurrent.Flow.Subscriber, java.io.Closeable, java.lang.AutoCloseable, jdk.internal.net.http.common.FlowTube.TubeSubscriber
Known Direct Subclasses
jdk.internal.net.http.common.SSLFlowDelegate.Reader, jdk.internal.net.http.common.SSLFlowDelegate.Writer
Imports
java.io.Closeable, java.nio.ByteBuffer, java.util.List, .Objects, java.util.concurrent.CompletableFuture, .ConcurrentLinkedQueue, .Flow, .Flow.Subscriber, java.util.concurrent.atomic.AtomicLong, .AtomicReference

A wrapper for a Flow.Subscriber. This wrapper delivers data to the wrapped Subscriber which is supplied to the constructor. This class takes care of downstream flow control automatically and upstream flow control automatically by default.

Processing is done by implementing the incoming(List, boolean) method which supplies buffers from upstream. This method (or any other method) can then call the outgoing() method to deliver processed buffers downstream.

Upstream error signals are delivered downstream directly. Cancellation from downstream is also propagated upstream immediately.

Each SubscriberWrapper has a java.util.concurrent.CompletableFuture<Void> which propagates completion/errors from downstream to upstream. Normal completion can only occur after onComplete() is called, but errors can be propagated upwards at any time.

Nested and Inner Type Summary

Modifier and TypeClass and Description
pack-priv class
SubscriberWrapper.DownstreamPusher

Invoked whenever it 'may' be possible to push buffers downstream.

public static enum

Field Summary

Modifier and TypeField and Description
private final CompletableFuture<Void>
pack-priv volatile boolean
pack-priv final Logger
pack-priv volatile boolean
private volatile Flow.Subscriber<? super List<ByteBuffer>>
pack-priv final SubscriptionBase
private final AtomicReference<Throwable>
private final ConcurrentLinkedQueue<List<ByteBuffer>>
private final SequentialScheduler
pack-priv volatile boolean
pack-priv volatile Flow.Subscription
pack-priv final AtomicLong

Constructor Summary

AccessConstructor and Description
public
SubscriberWrapper()

Wraps the given downstream subscriber.

public
SubscriberWrapper(Flow.Subscriber<? super List<ByteBuffer>>
downstream destination
downstreamWrapper
)

Wraps the given downstream wrapper in this.

Method Summary

Modifier and TypeMethod and Description
public void
addData(ByteBuffer l)

Adds the given data to the input queue.

pack-priv void
public void
close()

Implements java.io.Closeable.close.

Closes this stream and releases any system resources associated with it.

public void
public boolean

Returns:

true, may be overridden by subclasses.
closing
()

Sometime it might be necessary to complete the downstream subscriber before the upstream completes.

public CompletableFuture<Void>
completion()

Returns a CompletableFuture which completes when this wrapper completes.

public String
pack-priv void
protected SubscriberWrapper.SchedulingAction
enterScheduling()

Override this if anything needs to be done before checking for error and processing the input queue.

protected boolean
pack-priv final boolean
protected abstract void
incoming(List<ByteBuffer>
a List of ByteBuffers.
buffers
,
boolean
if true then no more data will be added to the list
complete
)

Delivers data to be processed by this wrapper.

private void
incomingCaller(List<ByteBuffer> l, boolean complete)

protected long

Returns:

The initial demand to request from upstream.
initialUpstreamDemand
()

Initial demand that should be requested from upstream when we get the upstream subscription from onSubscribe(Flow.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.

protected void
onSubscribe()

Override this if anything needs to be done after the upstream subscriber has subscribed

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.

public void
outgoing(ByteBuffer buffer, boolean complete)

Delivers buffers of data downstream.

public void
outgoing(List<ByteBuffer> buffers, boolean complete)

pack-priv final int
protected void
public void
protected boolean
public final void
subscribe(Flow.Subscriber<? super List<ByteBuffer>> downstreamSubscriber)

Implements java.util.concurrent.Flow.Publisher.subscribe.

Adds the given Subscriber if possible.

public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.

private void
public long
protected long

Returns:

value to add to currentWindow
upstreamWindowUpdate
(long
the current upstream subscription window
currentWindow
,
long
the current number of buffers waiting to be sent downstream
downstreamQsize
)

This method is called to determine the window size to use at any time.

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

Field Detail

cfback to summary
private final CompletableFuture<Void> cf
completionAcknowledgedback to summary
pack-priv volatile boolean completionAcknowledged
debugback to summary
pack-priv final Logger debug
downstreamCompletedback to summary
pack-priv volatile boolean downstreamCompleted
downstreamSubscriberback to summary
private volatile Flow.Subscriber<? super List<ByteBuffer>> downstreamSubscriber
downstreamSubscriptionback to summary
pack-priv final SubscriptionBase downstreamSubscription
errorRefback to summary
private final AtomicReference<Throwable> errorRef
outputQback to summary
private final ConcurrentLinkedQueue<List<ByteBuffer>> outputQ
pushSchedulerback to summary
private final SequentialScheduler pushScheduler
upstreamCompletedback to summary
pack-priv volatile boolean upstreamCompleted
upstreamSubscriptionback to summary
pack-priv volatile Flow.Subscription upstreamSubscription
upstreamWindowback to summary
pack-priv final AtomicLong upstreamWindow

Constructor Detail

SubscriberWrapperback to summary
public SubscriberWrapper()

Wraps the given downstream subscriber. For each call to onNext(List<ByteBuffer>) the given filter function is invoked and the list (if not empty) returned is passed downstream. A CompletableFuture is supplied which can be used to signal an error from downstream and which terminates the wrapper or which signals completion of downstream activity which can be propagated upstream. Error completion can be signaled at any time, but normal completion must not be signaled before onComplete() is called.

SubscriberWrapperback to summary
public SubscriberWrapper(Flow.Subscriber<? super List<ByteBuffer>> downstreamWrapper)

Wraps the given downstream wrapper in this. For each call to onNext(List<ByteBuffer>) the incoming() method is called. The downstreamCF from the downstream wrapper is linked to this wrappers notifier.

Parameters
downstreamWrapper:Flow.Subscriber<? super List<ByteBuffer>>

downstream destination

Method Detail

addDataback to summary
public void addData(ByteBuffer l)

Adds the given data to the input queue.

checkCompletionback to summary
pack-priv void checkCompletion()
closeback to summary
public void close()

Implements java.io.Closeable.close.

Doc from java.io.Closeable.close.

Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.

As noted in AutoCloseable#close(), cases where the close may fail require careful attention. It is strongly advised to relinquish the underlying resources and to internally mark the Closeable as closed, prior to throwing the IOException.

Annotations
@Override
closeback to summary
public void close(Throwable t)
closingback to summary
public boolean closing()

Sometime it might be necessary to complete the downstream subscriber before the upstream completes. For instance, when an SSL server sends a notify_close. In that case we should let the outgoing complete before upstream is completed.

Returns:boolean

true, may be overridden by subclasses.

completionback to summary
public CompletableFuture<Void> completion()

Returns a CompletableFuture which completes when this wrapper completes. Normal completion happens with the following steps (in order): 1. onComplete() is called 2. incoming() called with complete = true 3. outgoing() may continue to be called normally 4. outgoing called with complete = true 5. downstream subscriber is called onComplete() If the subscription is canceled or onComplete() is invoked the CompletableFuture completes exceptionally. Exceptional completion also occurs if downstreamCF completes exceptionally.

dbgStringback to summary
public String dbgString()
downstreamCompletionback to summary
pack-priv void downstreamCompletion()
enterSchedulingback to summary
protected SubscriberWrapper.SchedulingAction enterScheduling()

Override this if anything needs to be done before checking for error and processing the input queue.

errorCommonback to summary
protected boolean errorCommon(Throwable throwable)
hasNoOutputDataback to summary
pack-priv final boolean hasNoOutputData()
incomingback to summary
protected abstract void incoming(List<ByteBuffer> buffers, boolean complete)

Delivers data to be processed by this wrapper. Generated data to be sent downstream, must be provided to the outgoing(List, boolean)} method.

Parameters
buffers:List<ByteBuffer>

a List of ByteBuffers.

complete:boolean

if true then no more data will be added to the list

incomingCallerback to summary
private void incomingCaller(List<ByteBuffer> l, boolean complete)
initialUpstreamDemandback to summary
protected long initialUpstreamDemand()

Initial demand that should be requested from upstream when we get the upstream subscription from onSubscribe(Flow.Subscription).

Returns:long

The initial demand to request from upstream.

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
protected void onSubscribe()

Override this if anything needs to be done after the upstream subscriber has subscribed

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
outgoingback to summary
public void outgoing(ByteBuffer buffer, boolean complete)

Delivers buffers of data downstream. After incoming() has been called complete == true signifying completion of the upstream subscription, data may continue to be delivered, up to when outgoing() is called complete == true, after which, the downstream subscription is completed. It's an error to call outgoing() with complete = true if incoming() has not previously been called with it.

outgoingback to summary
public void outgoing(List<ByteBuffer> buffers, boolean complete)
outputQueueSizeback to summary
pack-priv final int outputQueueSize()
requestMoreback to summary
protected void requestMore()
resetDownstreamDemandback to summary
public void resetDownstreamDemand()
signalSchedulingback to summary
protected boolean signalScheduling()
subscribeback to summary
public final void subscribe(Flow.Subscriber<? super List<ByteBuffer>> downstreamSubscriber)

Implements java.util.concurrent.Flow.Publisher.subscribe.

Doc from java.util.concurrent.Flow.Publisher.subscribe.

Adds the given Subscriber if possible. If already subscribed, or the attempt to subscribe fails due to policy violations or errors, the Subscriber's onError method is invoked with an IllegalStateException. Otherwise, the Subscriber's onSubscribe method is invoked with a new Subscription. Subscribers may enable receiving items by invoking the request method of this Subscription, and may unsubscribe by invoking its cancel method.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object. Satisfying this method's contract implies a non-null result must be returned.

Annotations
@Override
upstreamRequestback to summary
private void upstreamRequest(long n)
upstreamWindowback to summary
public long upstreamWindow()
upstreamWindowUpdateback to summary
protected long upstreamWindowUpdate(long currentWindow, long downstreamQsize)

This method is called to determine the window size to use at any time. The current window is supplied together with the current downstream queue size. 0 should be returned if no change is required or a positive integer which will be added to the current window. The default implementation maintains a downstream queue size of no greater than 5. The method can be overridden if required.

Parameters
currentWindow:long

the current upstream subscription window

downstreamQsize:long

the current number of buffers waiting to be sent downstream

Returns:long

value to add to currentWindow

upstreamWindowUpdateback to summary
pack-priv void upstreamWindowUpdate()
jdk.internal.net.http.common back to summary

pack-priv Class SubscriberWrapper.DownstreamPusher

extends Object
implements Runnable
Class Inheritance
  • java.lang.Object
  • jdk.internal.net.http.common.SubscriberWrapper.DownstreamPusher
All Implemented Interfaces
java.lang.Runnable

Invoked whenever it 'may' be possible to push buffers downstream.

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public void
run()

Implements java.lang.Runnable.run.

Runs this operation.

private void
run1()

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Constructor Detail

DownstreamPusherback to summary
pack-priv DownstreamPusher()

Method Detail

runback to summary
public void run()

Implements java.lang.Runnable.run.

Doc from java.lang.Runnable.run.

Runs this operation.

Annotations
@Override
run1back to summary
private void run1()
jdk.internal.net.http.common back to summary

public final Enum SubscriberWrapper.SchedulingAction

extends Enum<SubscriberWrapper.SchedulingAction>
Class Inheritance

Field Summary

Modifier and TypeField and Description
public static final SubscriberWrapper.SchedulingAction
public static final SubscriberWrapper.SchedulingAction
public static final SubscriberWrapper.SchedulingAction

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public static SubscriberWrapper.SchedulingAction
public static SubscriberWrapper.SchedulingAction[]
Inherited from java.lang.Enum:
clonecompareTodescribeConstableequalsfinalizegetDeclaringClasshashCodenameordinaltoStringvalueOf

Field Detail

CONTINUEback to summary
public static final SubscriberWrapper.SchedulingAction CONTINUE
RESCHEDULEback to summary
public static final SubscriberWrapper.SchedulingAction RESCHEDULE
RETURNback to summary
public static final SubscriberWrapper.SchedulingAction RETURN

Constructor Detail

SchedulingActionback to summary
private SchedulingAction()

Method Detail

valueOfback to summary
public static SubscriberWrapper.SchedulingAction valueOf(String name)
valuesback to summary
public static SubscriberWrapper.SchedulingAction[] values()