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

public abstract sealed Class OrderedFlow<T extends QuicFrame>

extends Object
permits CryptoDataFlow, StreamDataFlow
Class Inheritance
Known Direct Subclasses
jdk.internal.net.http.quic.OrderedFlow.CryptoDataFlow, jdk.internal.net.http.quic.OrderedFlow.StreamDataFlow
Type Parameters
<T>
A frame type that defines an offset and a length. The offset of the frame indicates its position in the ordered flow.
Imports
java.util.Comparator, .NoSuchElementException, java.util.concurrent.ConcurrentSkipListSet, java.util.function.ToIntFunction, .ToLongFunction, jdk.internal.net.http.quic.frames.CryptoFrame, .QuicFrame, .StreamFrame

A class to take care of frames reordering in an ordered flow. Frames that are received out of order will be either buffered or dropped, depending on their position with respect to the current ordered flow offset. The buffered frames are returned by later calls to poll() when the flow offset matches the frame offset. Frames that are received in order are immediately returned. This class is not thread-safe and concurrent access needs to be synchronized externally.

Nested and Inner Type Summary

Modifier and TypeClass and Description
public static class
OrderedFlow.CryptoDataFlow

A subclass of OrderedFlow used to reorder instances of CryptoFrame.

public static class
OrderedFlow.StreamDataFlow

A subclass of OrderedFlow used to reorder instances of StreamFrame.

Field Summary

Modifier and TypeField and Description
pack-priv long
private final ToIntFunction<T>
pack-priv long
private final ToLongFunction<T>
private final ConcurrentSkipListSet<T>

Constructor Summary

AccessConstructor and Description
public
OrderedFlow(Comparator<T>
A comparator to order the frames according to their position in the ordered flow. Typically, this will compare the frame's offset: the frame with the smaller offset will be sorted before the frame with the greater offset
comparator
,
ToLongFunction<T>
A method reference that returns the position of the frame in the flow. For instance, this would be CryptoFrame::offset if <T> is CryptoFrame, or StreamFrame::offset if <T> is StreamFrame
position
,
ToIntFunction<T>
A method reference that returns the number of bytes in the frame data. This is used to compute the expected position of the next frame in the flow. For instance, this would be CryptoFrame::length if <T> is CryptoFrame, or StreamFrame::dataLength if <T> is StreamFrame
length
)

Constructs a new instance of ordered flow to reorder frames in a given flow.

Method Summary

Modifier and TypeMethod and Description
public long

Returns:

the number of bytes buffered
buffered
()

Returns the number of bytes buffered.

public void
clear()

Drops all buffered frames

private long

Returns:

the amount of dropped data
dropuntil
(long
the offset below which frames should be dropped
offset
)

Drop all frames in the buffer whose position is strictly below offset.

private void
enqueue(T frame, long pos, int length, long after)

public boolean

Returns:

true if there are no buffered frames
isEmpty
()

Returns true if there are no buffered frames.

public long

Returns:

the current offset of this buffer
offset
()

Returns the current offset of this buffer.

private T
public T

Returns:

the head of the queue if it is at the current offset, or null
poll
()

Removes and return the head of the queue if it is at the current offset.

private T

Returns:

a received frame at the current flow offset, or null
poll
(long
the minimal offset
offset
)

Pretends to receive the head of the queue, if it is at the provided offset

public T

Returns:

the next frame in the flow, or null if it is not available yet.
receive
(T
a frame that was received
frame
)

Receives a new frame.

public int

Returns:

the number of buffered frames
size
()

Returns the number of buffered frames.

protected abstract T

Returns:

a slice of the given frame
slice
(T
the frame to slice
frame
,
long
the new frame offset
offset
,
int
the new frame length
length
)

Returns a slice of the given frame.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

bufferedback to summary
pack-priv long buffered
lengthback to summary
private final ToIntFunction<T> length
offsetback to summary
pack-priv long offset
positionback to summary
private final ToLongFunction<T> position
queueback to summary
private final ConcurrentSkipListSet<T> queue

Constructor Detail

OrderedFlowback to summary
public OrderedFlow(Comparator<T> comparator, ToLongFunction<T> position, ToIntFunction<T> length)

Constructs a new instance of ordered flow to reorder frames in a given flow.

Parameters
comparator:Comparator<T>

A comparator to order the frames according to their position in the ordered flow. Typically, this will compare the frame's offset: the frame with the smaller offset will be sorted before the frame with the greater offset

position:ToLongFunction<T>

A method reference that returns the position of the frame in the flow. For instance, this would be CryptoFrame::offset if <T> is CryptoFrame, or StreamFrame::offset if <T> is StreamFrame

length:ToIntFunction<T>

A method reference that returns the number of bytes in the frame data. This is used to compute the expected position of the next frame in the flow. For instance, this would be CryptoFrame::length if <T> is CryptoFrame, or StreamFrame::dataLength if <T> is StreamFrame

Method Detail

bufferedback to summary
public long buffered()

Returns the number of bytes buffered.

Returns:long

the number of bytes buffered

clearback to summary
public void clear()

Drops all buffered frames

dropuntilback to summary
private long dropuntil(long offset)

Drop all frames in the buffer whose position is strictly below offset.

Parameters
offset:long

the offset below which frames should be dropped

Returns:long

the amount of dropped data

enqueueback to summary
private void enqueue(T frame, long pos, int length, long after)
isEmptyback to summary
public boolean isEmpty()

Returns true if there are no buffered frames.

Returns:boolean

true if there are no buffered frames

offsetback to summary
public long offset()

Returns the current offset of this buffer.

Returns:long

the current offset of this buffer

peekFirstback to summary
private T peekFirst()
pollback to summary
public T poll()

Removes and return the head of the queue if it is at the current offset. Otherwise, returns null.

Returns:T

the head of the queue if it is at the current offset, or null

pollback to summary
private T poll(long offset)

Pretends to receive the head of the queue, if it is at the provided offset

Parameters
offset:long

the minimal offset

Returns:T

a received frame at the current flow offset, or null

receiveback to summary
public T receive(T frame)

Receives a new frame. If the frame is below the current offset the frame is dropped. If it is above the current offset, it is queued. If the frame is exactly at the current offset, it is returned.

Parameters
frame:T

a frame that was received

Returns:T

the next frame in the flow, or null if it is not available yet.

sizeback to summary
public int size()

Returns the number of buffered frames.

Returns:int

the number of buffered frames

sliceback to summary
protected abstract T slice(T frame, long offset, int length)

Returns a slice of the given frame.

Parameters
frame:T

the frame to slice

offset:long

the new frame offset

length:int

the new frame length

Returns:T

a slice of the given frame

Exceptions
IndexOutOfBoundsException:
if the new offset or length fall outside of the frame's bounds
jdk.internal.net.http.quic back to summary

public final Class OrderedFlow.CryptoDataFlow

extends OrderedFlow<CryptoFrame>
Class Inheritance

A subclass of OrderedFlow used to reorder instances of CryptoFrame.

Field Summary

Inherited from jdk.internal.net.http.quic.OrderedFlow:
bufferedoffset

Constructor Summary

AccessConstructor and Description
public
CryptoDataFlow()

Constructs a new instance of CryptoDataFlow to reorder a flow of CryptoFrame instances.

Method Summary

Modifier and TypeMethod and Description
protected CryptoFrame
slice(CryptoFrame frame, long offset, int length)

Implements abstract jdk.internal.net.http.quic.OrderedFlow.slice.

Returns a slice of the given frame.

Inherited from jdk.internal.net.http.quic.OrderedFlow:
bufferedclearisEmptyoffsetpollreceivesize

Constructor Detail

CryptoDataFlowback to summary
public CryptoDataFlow()

Constructs a new instance of CryptoDataFlow to reorder a flow of CryptoFrame instances.

Method Detail

sliceback to summary
protected CryptoFrame slice(CryptoFrame frame, long offset, int length)

Implements abstract jdk.internal.net.http.quic.OrderedFlow.slice.

Doc from jdk.internal.net.http.quic.OrderedFlow.slice.

Returns a slice of the given frame.

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

public final Class OrderedFlow.StreamDataFlow

extends OrderedFlow<StreamFrame>
Class Inheritance

A subclass of OrderedFlow used to reorder instances of StreamFrame.

Field Summary

Inherited from jdk.internal.net.http.quic.OrderedFlow:
bufferedoffset

Constructor Summary

AccessConstructor and Description
public
StreamDataFlow()

Constructs a new instance of StreamDataFlow to reorder a flow of StreamFrame instances.

Method Summary

Modifier and TypeMethod and Description
protected StreamFrame
slice(StreamFrame frame, long offset, int length)

Implements abstract jdk.internal.net.http.quic.OrderedFlow.slice.

Returns a slice of the given frame.

Inherited from jdk.internal.net.http.quic.OrderedFlow:
bufferedclearisEmptyoffsetpollreceivesize

Constructor Detail

StreamDataFlowback to summary
public StreamDataFlow()

Constructs a new instance of StreamDataFlow to reorder a flow of StreamFrame instances.

Method Detail

sliceback to summary
protected StreamFrame slice(StreamFrame frame, long offset, int length)

Implements abstract jdk.internal.net.http.quic.OrderedFlow.slice.

Doc from jdk.internal.net.http.quic.OrderedFlow.slice.

Returns a slice of the given frame.

Annotations
@Override