Class HTTP2Stream

java.lang.Object
org.eclipse.jetty.http2.HTTP2Stream
All Implemented Interfaces:
Closeable, AutoCloseable, Stream, CyclicTimeouts.Expirable, Attachable, Callback, Dumpable, Invocable

public class HTTP2Stream extends Object implements Stream, Attachable, Closeable, Callback, Dumpable, CyclicTimeouts.Expirable
  • Constructor Details

  • Method Details

    • getId

      public int getId()
      Description copied from interface: Stream
      Get the stream unique id.
      Specified by:
      getId in interface Stream
      Returns:
      the stream unique id
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • getAttachment

      public Object getAttachment()
      Specified by:
      getAttachment in interface Attachable
      Returns:
      the object attached to this instance
      See Also:
    • setAttachment

      public void setAttachment(Object attachment)
      Description copied from interface: Attachable
      Attaches the given object to this stream for later retrieval.
      Specified by:
      setAttachment in interface Attachable
      Parameters:
      attachment - the object to attach to this instance
    • isLocal

      public boolean isLocal()
      Specified by:
      isLocal in interface Stream
      Returns:
      whether this stream is local or remote
    • getSession

      public HTTP2Session getSession()
      Description copied from interface: Stream
      Get the session this stream is associated to.
      Specified by:
      getSession in interface Stream
      Returns:
      the session this stream is associated to
    • headers

      public void headers(HeadersFrame frame, Callback callback)
      Description copied from interface: Stream

      Sends the given HEADERS frame.

      Typically used to send an HTTP response or to send the HTTP response trailers.

      Specified by:
      headers in interface Stream
      Parameters:
      frame - the HEADERS frame to send
      callback - the callback that gets notified when the frame has been sent
    • send

      public void send(HTTP2Stream.FrameList frameList, Callback callback)
    • push

      public void push(PushPromiseFrame frame, Promise<Stream> promise, Stream.Listener listener)
      Description copied from interface: Stream

      Sends the given PUSH_PROMISE frame.

      Specified by:
      push in interface Stream
      Parameters:
      frame - the PUSH_PROMISE frame to send
      promise - the promise that gets notified of the pushed stream creation
      listener - the listener that gets notified of stream events
    • data

      public void data(DataFrame frame, Callback callback)
      Description copied from interface: Stream

      Sends the given DATA frame.

      Specified by:
      data in interface Stream
      Parameters:
      frame - the DATA frame to send
      callback - the callback that gets notified when the frame has been sent
    • reset

      public void reset(ResetFrame frame, Callback callback)
      Description copied from interface: Stream

      Sends the given RST_STREAM frame.

      Specified by:
      reset in interface Stream
      Parameters:
      frame - the RST_STREAM frame to send
      callback - the callback that gets notified when the frame has been sent
    • getAttribute

      public Object getAttribute(String key)
      Specified by:
      getAttribute in interface Stream
      Parameters:
      key - the attribute key
      Returns:
      an arbitrary object associated with the given key to this stream or null if no object can be found for the given key.
      See Also:
    • setAttribute

      public void setAttribute(String key, Object value)
      Specified by:
      setAttribute in interface Stream
      Parameters:
      key - the attribute key
      value - an arbitrary object to associate with the given key to this stream
      See Also:
    • removeAttribute

      public Object removeAttribute(String key)
      Specified by:
      removeAttribute in interface Stream
      Parameters:
      key - the attribute key
      Returns:
      the arbitrary object associated with the given key to this stream
      See Also:
    • isReset

      public boolean isReset()
      Specified by:
      isReset in interface Stream
      Returns:
      whether this stream has been reset
    • isResetOrFailed

      public boolean isResetOrFailed()
    • isClosed

      public boolean isClosed()
      Specified by:
      isClosed in interface Stream
      Returns:
      whether this stream is closed, both locally and remotely.
    • isRemotelyClosed

      public boolean isRemotelyClosed()
      Specified by:
      isRemotelyClosed in interface Stream
      Returns:
      whether the stream is closed remotely.
      See Also:
    • isLocallyClosed

      public boolean isLocallyClosed()
    • commit

      public void commit()
    • isCommitted

      public boolean isCommitted()
    • isOpen

      public boolean isOpen()
    • notIdle

      public void notIdle()
    • getExpireNanoTime

      public long getExpireNanoTime()
      Description copied from interface: CyclicTimeouts.Expirable

      Returns the expiration time in nanoseconds.

      The value to return must be calculated taking into account the current nanoTime, for example:

      expireNanoTime = NanoTime.now() + timeoutNanos

      Returning Long.MAX_VALUE indicates that this entity does not expire.

      Specified by:
      getExpireNanoTime in interface CyclicTimeouts.Expirable
      Returns:
      the expiration time in nanoseconds, or Long.MAX_VALUE if this entity does not expire
    • getIdleTimeout

      public long getIdleTimeout()
      Specified by:
      getIdleTimeout in interface Stream
      Returns:
      the stream idle timeout
      See Also:
    • setIdleTimeout

      public void setIdleTimeout(long idleTimeout)
      Specified by:
      setIdleTimeout in interface Stream
      Parameters:
      idleTimeout - the stream idle timeout
      See Also:
    • onIdleTimeout

      protected void onIdleTimeout(TimeoutException timeout)
    • getListener

      public Stream.Listener getListener()
      Description copied from interface: Stream
      Get the Stream.Listener associated with this stream.
      Specified by:
      getListener in interface Stream
      Returns:
      the Stream.Listener associated with this stream
    • setListener

      public void setListener(Stream.Listener listener)
    • process

      public void process(Frame frame, Callback callback)
    • process

      public void process(Stream.Data data)
    • readData

      public Stream.Data readData()
      Description copied from interface: Stream

      Reads DATA frames from this stream, wrapping them in retainable Stream.Data objects.

      The returned Stream.Data object may be null, indicating that the end of the read side of the stream has not yet been reached, which may happen in these cases:

      • not all the bytes have been received so far, for example the remote peer did not send them yet, or they are in-flight
      • all the bytes have been received, but there is a trailer HEADERS frame to be received to indicate the end of the read side of the stream

      When the returned Stream.Data object is not null, the flow control window has been enlarged by the DATA frame length; applications must call, either immediately or later (even asynchronously from a different thread) Retainable.release() to notify the implementation that the bytes have been processed.

      Stream.Data objects may be stored away for later, asynchronous, processing (for example, to process them only when all of them have been received).

      Once the returned Stream.Data object indicates that the end of the read side of the stream has been reached, further calls to this method will return a Stream.Data object with the same indication, although the instance may be different.

      Specified by:
      readData in interface Stream
      Returns:
      a Stream.Data object containing the DATA frame, or null if no DATA frame is available
      See Also:
    • demand

      public void demand()
      Description copied from interface: Stream

      Demands more DATA frames for this stream.

      Calling this method causes Stream.Listener.onDataAvailable(Stream) to be invoked, possibly at a later time, when the stream has data to be read, but also when the stream has reached EOF.

      This method is idempotent: calling it when there already is an outstanding demand to invoke Stream.Listener.onDataAvailable(Stream) is a no-operation.

      The thread invoking this method may invoke directly Stream.Listener.onDataAvailable(Stream), unless another thread that must invoke Stream.Listener.onDataAvailable(Stream) notices the outstanding demand first.

      It is always guaranteed that invoking this method from within onDataAvailable(Stream) will not cause a StackOverflowError.

      Specified by:
      demand in interface Stream
      See Also:
    • processData

      public void processData()
    • getDataLength

      public long getDataLength()
    • updateClose

      public boolean updateClose(boolean update, CloseState.Event event)
    • getSendWindow

      public int getSendWindow()
    • getRecvWindow

      public int getRecvWindow()
    • updateSendWindow

      public int updateSendWindow(int delta)
    • updateRecvWindow

      public int updateRecvWindow(int delta)
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • onClose

      public void onClose()
    • succeeded

      public void succeeded()
      Description copied from interface: Callback

      Callback invoked when the operation completes.

      Specified by:
      succeeded in interface Callback
      See Also:
    • failed

      public void failed(Throwable x)
      Description copied from interface: Callback

      Callback invoked when the operation fails.

      Specified by:
      failed in interface Callback
      Parameters:
      x - the reason for the operation failure
    • getInvocationType

      public Invocable.InvocationType getInvocationType()
      Specified by:
      getInvocationType in interface Invocable
      Returns:
      The InvocationType of this object
    • notifyHeaders

      protected void notifyHeaders(Stream stream, HeadersFrame frame)
    • dump

      public String dump()
      Specified by:
      dump in interface Dumpable
    • dump

      public void dump(Appendable out, String indent) throws IOException
      Description copied from interface: Dumpable
      Dump this object (and children) into an Appendable using the provided indent after any new lines. The indent should not be applied to the first object dumped.
      Specified by:
      dump in interface Dumpable
      Parameters:
      out - The appendable to dump to
      indent - The indent to apply after any new lines.
      Throws:
      IOException - if unable to write to Appendable
    • toString

      public String toString()
      Overrides:
      toString in class Object