Class HTTP2Session.StreamsState
- java.lang.Object
-
- org.eclipse.jetty.http2.HTTP2Session.StreamsState
-
- Enclosing class:
- HTTP2Session
private class HTTP2Session.StreamsState extends java.lang.Object
The HTTP/2 specification requires that stream ids are monotonically increasing, see RFC 7540, 5.1.1.
This implementation uses a queue to atomically reserve a stream id and claim a slot in the queue; the slot is then assigned the entries to write.
Concurrent threads push slots in the queue but only one thread flushes the slots, up to the slot that has a non-null entries to write, therefore guaranteeing that frames are sent strictly in their stream id order.
This class also coordinates the creation of streams with the close of the session, see RFC 7540, 6.8.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private class
HTTP2Session.StreamsState.Slot
-
Field Summary
Fields Modifier and Type Field Description private CloseState
closed
private java.lang.Throwable
failure
private java.lang.Thread
flushing
private GoAwayFrame
goAwayRecv
private GoAwayFrame
goAwaySent
private long
idleTime
private org.eclipse.jetty.util.thread.Locker
lock
private java.util.Queue<HTTP2Session.StreamsState.Slot>
slots
private java.util.concurrent.atomic.AtomicLong
streamCount
private java.lang.Runnable
zeroStreamsAction
-
Constructor Summary
Constructors Modifier Constructor Description private
StreamsState()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private boolean
createLocalStream(HTTP2Session.StreamsState.Slot slot, java.util.List<StreamFrame> frames, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener, int streamId)
private void
flush()
Iterates over the entries of the slot queue to flush them.private void
freeSlot(HTTP2Session.StreamsState.Slot slot, int streamId)
private CloseState
getCloseState()
private boolean
goAway(GoAwayFrame frame, org.eclipse.jetty.util.Callback callback)
private void
halt(java.lang.String reason)
private void
newLocalStream(IStream.FrameList frameList, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)
private boolean
newRemoteStream(int streamId)
private void
onGoAway(GoAwayFrame frame)
private boolean
onIdleTimeout()
private void
onSessionFailure(int error, java.lang.String reason, org.eclipse.jetty.util.Callback callback)
private void
onShutdown()
private void
onStreamCreated()
private void
onStreamDestroyed()
private void
onWriteFailure(java.lang.Throwable x)
private int
priority(PriorityFrame frame, org.eclipse.jetty.util.Callback callback)
private void
push(PushPromiseFrame frame, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)
private int
reserveSlot(HTTP2Session.StreamsState.Slot slot, int streamId, java.util.function.Consumer<java.lang.Throwable> fail)
private void
sendGoAway(GoAwayFrame frame, org.eclipse.jetty.util.Callback callback)
private void
sendGoAwayAndTerminate(GoAwayFrame frame, GoAwayFrame eventFrame)
private void
terminate(GoAwayFrame frame)
java.lang.String
toString()
private void
tryRunZeroStreamsAction()
-
-
-
Field Detail
-
lock
private final org.eclipse.jetty.util.thread.Locker lock
-
slots
private final java.util.Queue<HTTP2Session.StreamsState.Slot> slots
-
streamCount
private final java.util.concurrent.atomic.AtomicLong streamCount
-
idleTime
private long idleTime
-
closed
private CloseState closed
-
zeroStreamsAction
private java.lang.Runnable zeroStreamsAction
-
goAwayRecv
private GoAwayFrame goAwayRecv
-
goAwaySent
private GoAwayFrame goAwaySent
-
failure
private java.lang.Throwable failure
-
flushing
private java.lang.Thread flushing
-
-
Method Detail
-
getCloseState
private CloseState getCloseState()
-
goAway
private boolean goAway(GoAwayFrame frame, org.eclipse.jetty.util.Callback callback)
-
halt
private void halt(java.lang.String reason)
-
onGoAway
private void onGoAway(GoAwayFrame frame)
-
onShutdown
private void onShutdown()
-
onIdleTimeout
private boolean onIdleTimeout()
-
onSessionFailure
private void onSessionFailure(int error, java.lang.String reason, org.eclipse.jetty.util.Callback callback)
-
onWriteFailure
private void onWriteFailure(java.lang.Throwable x)
-
sendGoAwayAndTerminate
private void sendGoAwayAndTerminate(GoAwayFrame frame, GoAwayFrame eventFrame)
-
sendGoAway
private void sendGoAway(GoAwayFrame frame, org.eclipse.jetty.util.Callback callback)
-
onStreamCreated
private void onStreamCreated()
-
onStreamDestroyed
private void onStreamDestroyed()
-
tryRunZeroStreamsAction
private void tryRunZeroStreamsAction()
-
terminate
private void terminate(GoAwayFrame frame)
-
priority
private int priority(PriorityFrame frame, org.eclipse.jetty.util.Callback callback)
-
newLocalStream
private void newLocalStream(IStream.FrameList frameList, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)
-
newRemoteStream
private boolean newRemoteStream(int streamId)
-
push
private void push(PushPromiseFrame frame, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener)
-
createLocalStream
private boolean createLocalStream(HTTP2Session.StreamsState.Slot slot, java.util.List<StreamFrame> frames, org.eclipse.jetty.util.Promise<Stream> promise, Stream.Listener listener, int streamId)
-
reserveSlot
private int reserveSlot(HTTP2Session.StreamsState.Slot slot, int streamId, java.util.function.Consumer<java.lang.Throwable> fail)
-
freeSlot
private void freeSlot(HTTP2Session.StreamsState.Slot slot, int streamId)
-
flush
private void flush()
Iterates over the entries of the slot queue to flush them.
The flush proceeds until either one of the following two conditions is true:
- the queue is empty
- a slot with a no entries is encountered
When a slot with a no entries is encountered, then it means that a concurrent thread reserved a slot but hasn't set its entries yet. Since slots must be flushed in order, the thread encountering the slot with no entries must bail out and it is up to the concurrent thread to finish up flushing.
Note that only one thread can flush at any time; if two threads happen to call this method concurrently, one will do the work while the other will bail out, so it is safe that all threads call this method after they are done reserving a slot and setting the entries.
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-