Class Http2Stream

java.lang.Object
org.glassfish.grizzly.http2.Http2Stream
All Implemented Interfaces:
AttributeStorage, Closeable, OutputSink

public class Http2Stream extends Object implements AttributeStorage, OutputSink, Closeable
The abstraction representing HTTP2 stream.
Author:
Grizzly team
  • Field Details

    • HTTP2_STREAM_ATTRIBUTE

      public static final String HTTP2_STREAM_ATTRIBUTE
    • HTTP2_PARENT_STREAM_ATTRIBUTE

      public static final String HTTP2_PARENT_STREAM_ATTRIBUTE
  • Constructor Details

    • Http2Stream

      protected Http2Stream(Http2Session http2Session, HttpRequestPacket request, int streamId, int parentStreamId, boolean exclusive, int priority)
      Create HTTP2 stream.
      Parameters:
      http2Session - the Http2Session for this Http2Stream.
      request - the HttpRequestPacket initiating the stream.
      streamId - this stream's ID.
      parentStreamId - the parent stream, if any.
      priority - the priority of this stream.
    • Http2Stream

      protected Http2Stream(Http2Session http2Session, HttpRequestPacket request, int priority)
      Construct upgrade stream, which is half HTTP, half HTTP2
      Parameters:
      http2Session - the Http2Session for this Http2Stream.
      request - the HttpRequestPacket initiating the stream.
      priority - the priority of this stream.
  • Method Details

    • getStreamFor

      public static Http2Stream getStreamFor(HttpHeader httpHeader)
    • getPeerWindowSize

      public int getPeerWindowSize()
    • getLocalWindowSize

      public int getLocalWindowSize()
    • getUnflushedWritesCount

      public int getUnflushedWritesCount()
      Returns:
      the number of writes (not bytes), that haven't reached network layer
    • getRequest

      public HttpRequestPacket getRequest()
    • getResponse

      public HttpResponsePacket getResponse()
    • isPushEnabled

      public boolean isPushEnabled()
    • getId

      public int getId()
    • getParentStreamId

      public int getParentStreamId()
    • getPriority

      public int getPriority()
    • isPushStream

      public boolean isPushStream()
    • isLocallyInitiatedStream

      public boolean isLocallyInitiatedStream()
    • isOpen

      public boolean isOpen()
      Description copied from interface: Closeable
      Is Closeable open and ready. Returns true, if the Closeable is open and ready, or false otherwise.
      Specified by:
      isOpen in interface Closeable
      Returns:
      true, if Closeable is open and ready, or false otherwise.
    • assertOpen

      public void assertOpen() throws IOException
      Description copied from interface: Closeable
      Checks if this Closeable is open and ready to be used. If this Closeable is closed then an IOException will be thrown
      Specified by:
      assertOpen in interface Closeable
      Throws:
      IOException - giving the reason why this Closeable was closed.
    • getAttributes

      public AttributeHolder getAttributes()
      Description copied from interface: AttributeStorage
      Get associated AttributeHolder. Implementation may return null if AttributeHolder wasn't initialized yet.
      Specified by:
      getAttributes in interface AttributeStorage
      Returns:
      associated AttributeHolder. Implementation may return null if AttributeHolder wasn't initialized yet.
    • canWrite

      @Deprecated public boolean canWrite(int length)
      Deprecated.
      Specified by:
      canWrite in interface OutputSink
      Parameters:
      length - specifies the number of bytes (or characters) that require writing
      Returns:
      true if a write to this OutputSink will succeed, otherwise returns false.
    • canWrite

      public boolean canWrite()
      Specified by:
      canWrite in interface OutputSink
      Returns:
      true if a write to this OutputSink will succeed, otherwise returns false.
    • notifyCanWrite

      @Deprecated public void notifyCanWrite(WriteHandler handler, int length)
      Deprecated.
      Description copied from interface: OutputSink
      Instructs the OutputSink to invoke the provided WriteHandler when it is possible to write length bytes (or characters). Note that once the WriteHandler has been notified, it will not be considered for notification again at a later point in time.
      Specified by:
      notifyCanWrite in interface OutputSink
      Parameters:
      handler - the WriteHandler that should be notified when it's possible to write length bytes.
      length - the number of bytes or characters that require writing.
    • notifyCanWrite

      public void notifyCanWrite(WriteHandler writeHandler)
      Description copied from interface: OutputSink
      Instructs the OutputSink to invoke the provided WriteHandler when it is possible to write more bytes (or characters). Note that once the WriteHandler has been notified, it will not be considered for notification again at a later point in time.
      Specified by:
      notifyCanWrite in interface OutputSink
      Parameters:
      writeHandler - the WriteHandler that should be notified when it's possible to write more data.
    • terminate

      public GrizzlyFuture<Closeable> terminate()
      Description copied from interface: Closeable
      Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
      Specified by:
      terminate in interface Closeable
      Returns:
      Future, which could be checked in case, if close operation will be run asynchronously
    • terminateSilently

      public void terminateSilently()
      Description copied from interface: Closeable
      Closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. Use this method, when no completion notification is needed.
      Specified by:
      terminateSilently in interface Closeable
    • terminateWithReason

      public void terminateWithReason(IOException cause)
      Description copied from interface: Closeable
      Closes the Closeable and provides the reason description. This method is similar to Closeable.terminateSilently(), but additionally provides the reason why the Closeable will be closed.
      Specified by:
      terminateWithReason in interface Closeable
      Parameters:
      cause - reason why terminated. This will be thrown is Closeable.isOpen() is called subsequently
    • close

      public GrizzlyFuture<Closeable> close()
      Description copied from interface: Closeable
      Gracefully (if supported by the implementation) closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect.
      Specified by:
      close in interface Closeable
      Returns:
      Future, which could be checked in case, if close operation will be run asynchronously
      See Also:
    • closeSilently

      public void closeSilently()
      Description copied from interface: Closeable
      Gracefully (if supported by the implementation) closes this stream and releases any system resources associated with it. If the stream is already closed then invoking this method has no effect. Use this method, when no completion notification is needed.
      Specified by:
      closeSilently in interface Closeable
    • close

      @Deprecated public void close(CompletionHandler<Closeable> completionHandler)
      Gracefully closes this stream and releases any system resources associated with it. This operation waits for all pending output data to be flushed before closing the stream. If the stream is already closed then invoking this method has no effect.
      Specified by:
      close in interface Closeable
      Parameters:
      completionHandler - CompletionHandler to be called, when the stream is closed
    • closeWithReason

      public void closeWithReason(IOException cause)
      Description copied from interface: Closeable
      Gracefully closes the Closeable and provides the reason description. This method is similar to Closeable.closeSilently(), but additionally provides the reason why the Closeable will be closed.
      Specified by:
      closeWithReason in interface Closeable
      Parameters:
      cause - reason why closed, this will be thrown by Closeable.isOpen() if called subsequently
    • addCloseListener

      public void addCloseListener(CloseListener closeListener)
      Description copied from interface: Closeable
      Add the CloseListener, which will be notified once the stream will be closed.
      Specified by:
      addCloseListener in interface Closeable
      Parameters:
      closeListener - CloseListener.
    • removeCloseListener

      public boolean removeCloseListener(CloseListener closeListener)
      Description copied from interface: Closeable
      Remove the CloseListener.
      Specified by:
      removeCloseListener in interface Closeable
      Parameters:
      closeListener - CloseListener.
      Returns:
      true if the listener was successfully removed, or false otherwise.
    • closeFuture

      public GrizzlyFuture<CloseReason> closeFuture()
      Specified by:
      closeFuture in interface Closeable
      Returns:
      the Future, that will be notified once this Closeable is closed