Class StreamEndPoint

java.lang.Object
org.eclipse.jetty.quic.common.StreamEndPoint
All Implemented Interfaces:
Closeable, AutoCloseable, Content.Sink, EndPoint

public class StreamEndPoint extends Object implements EndPoint

An EndPoint implementation on top of a QUIC stream.

The correspondent Connection associated to this StreamEndPoint parses and generates the protocol specific bytes transported by QUIC.

  • Constructor Details

  • Method Details

    • getProtocolSession

      public ProtocolSession getProtocolSession()
    • getStream

      public Stream getStream()
    • getLocalSocketAddress

      public SocketAddress getLocalSocketAddress()
      Specified by:
      getLocalSocketAddress in interface EndPoint
      Returns:
      the local SocketAddress to which this EndPoint is bound or null if this EndPoint is not bound to a Socket address.
    • getRemoteSocketAddress

      public SocketAddress getRemoteSocketAddress()
      Specified by:
      getRemoteSocketAddress in interface EndPoint
      Returns:
      The remote SocketAddress to which this EndPoint is connected, or null if this EndPoint is not connected to a Socket address.
    • isOpen

      public boolean isOpen()
      Specified by:
      isOpen in interface EndPoint
      Returns:
      whether this EndPoint is open
    • getCreatedTimeStamp

      public long getCreatedTimeStamp()
      Specified by:
      getCreatedTimeStamp in interface EndPoint
      Returns:
      the epoch time in milliseconds when this EndPoint was created
    • getTransport

      public Object getTransport()
      Specified by:
      getTransport in interface EndPoint
      Returns:
      The underlying transport object (socket, channel, etc.)
    • getIdleTimeout

      public long getIdleTimeout()
      Description copied from interface: EndPoint

      Returns the idle timeout in ms.

      The idle timeout is the time the endpoint can be idle before its close is initiated.

      A timeout less than or equal to 0 implies an infinite timeout.

      Specified by:
      getIdleTimeout in interface EndPoint
      Returns:
      the idle timeout in ms
    • setIdleTimeout

      public void setIdleTimeout(long idleTimeout)
      Description copied from interface: EndPoint

      Sets the idle timeout.

      Specified by:
      setIdleTimeout in interface EndPoint
      Parameters:
      idleTimeout - the idle timeout in MS. Timeout <= 0 implies an infinite timeout
    • shutdownOutput

      public void shutdownOutput()
      Description copied from interface: EndPoint

      Shuts down the output.

      This call indicates that no more data will be sent from this endpoint and that the remote endpoint should read an EOF once all previously sent data has been read. Shutdown may be done either at the TCP/IP level, as a protocol exchange (for example, TLS close handshake) or both.

      If the endpoint has EndPoint.isInputShutdown() true, then this call has the same effect as EndPoint.close().

      Specified by:
      shutdownOutput in interface EndPoint
    • isOutputShutdown

      public boolean isOutputShutdown()
      Description copied from interface: EndPoint

      Tests if output is shutdown.

      The output is shutdown by a call to EndPoint.shutdownOutput() or EndPoint.close().

      Specified by:
      isOutputShutdown in interface EndPoint
      Returns:
      true if the output is shutdown or the endpoint is closed.
    • isInputShutdown

      public boolean isInputShutdown()
      Description copied from interface: EndPoint

      Tests if the input is shutdown.

      The input is shutdown if an EOF has been read while doing a EndPoint.fill(ByteBuffer). Once the input is shutdown, all calls to EndPoint.fill(ByteBuffer) will return -1, until such time as the end point is close, when they will return EofException.

      Specified by:
      isInputShutdown in interface EndPoint
      Returns:
      true if the input is shutdown or the endpoint is closed.
    • shutdownInput

      public void shutdownInput(long appError)
    • shutdownOutput

      public void shutdownOutput(long appError, Promise.Invocable<StreamEndPoint> promise)
    • close

      public void close(Throwable failure)
      Description copied from interface: EndPoint

      Closes any backing stream associated with the endpoint, passing a possibly null failure cause.

      Specified by:
      close in interface EndPoint
      Parameters:
      failure - the reason for the close or null
    • disconnect

      public void disconnect(long appError, Throwable failure, boolean disconnectStream, Promise.Invocable<StreamEndPoint> promise)
    • onClose

      public void onClose(Throwable failure)
      Description copied from interface: EndPoint

      Callback method invoked when this EndPoint is closed.

      Specified by:
      onClose in interface EndPoint
      Parameters:
      failure - The reason for the close, or null if a normal close.
      See Also:
    • fill

      public int fill(ByteBuffer sink) throws IOException
      Description copied from interface: EndPoint

      Fills the passed buffer with data from this endpoint.

      The bytes are appended to any data already in the buffer by writing from the buffers limit up to its capacity. The limit is updated to include the filled bytes.

      Specified by:
      fill in interface EndPoint
      Parameters:
      sink - The buffer to fill. The position and limit are modified during the fill. After the operation, the position is unchanged and the limit is increased to reflect the new data filled.
      Returns:
      an int value indicating the number of bytes filled or -1 if EOF is read or the input is shutdown.
      Throws:
      IOException - if the endpoint is closed.
    • fill

      public Content.Chunk fill()

      Fills from this StreamEndPoint.

      This method should be used in alternative to fill(ByteBuffer), when the Connection installed on top of this StreamEndPoint needs to know both the bytes and whether the QUIC data is the last in the stream, for example in HTTP/3.

      The code calling this method is responsible to organize for the returned Content.Chunk to be eventually released.

      Returns:
      a Content.Chunk with data bytes or a failure, or null if there are no data bytes
    • flush

      public boolean flush(ByteBuffer... buffers) throws IOException
      Description copied from interface: EndPoint

      Flushes data from the passed header/buffer to this endpoint.

      As many bytes as can be consumed are taken from the header/buffer position up until the buffer limit. The header/buffers position is updated to indicate how many bytes have been consumed.

      Specified by:
      flush in interface EndPoint
      Parameters:
      buffers - the buffers to flush
      Returns:
      True IFF all the buffers have been consumed and the endpoint has flushed the data to its destination (ie is not buffering any data).
      Throws:
      IOException - If the endpoint is closed or output is shutdown.
    • write

      public void write(Callback callback, ByteBuffer... buffers) throws WritePendingException
      Description copied from interface: EndPoint

      Writes the given buffers via EndPoint.flush(ByteBuffer...) and invokes callback methods when either all the data has been flushed or an error occurs.

      Specified by:
      write in interface EndPoint
      Parameters:
      callback - the callback to call when an error occurs or the write completed. The callback may implement the Invocable interface to self declare its blocking status. Non-blocking callbacks may be called more efficiently without dispatch delays.
      buffers - one or more ByteBuffers that will be flushed.
      Throws:
      WritePendingException - if another write operation is concurrent.
    • write

      public void write(boolean last, ByteBuffer byteBuffer, Callback callback)
      Description copied from interface: Content.Sink

      Writes the given ByteBuffer, notifying the Callback when the write is complete.

      Implementations guarantee that calls to this method are safely reentrant so that stack overflows are avoided in the case of mutual recursion between the execution of the Callback and a call to this method.

      Specified by:
      write in interface Content.Sink
      Specified by:
      write in interface EndPoint
      Parameters:
      last - whether the ByteBuffer is the last to write
      byteBuffer - the ByteBuffer to write
      callback - the callback to notify when the write operation is complete
    • cancelWrite

      public Callback cancelWrite(Throwable cause)
      Description copied from interface: EndPoint
      Cancel any current EndPoint.write(Callback, ByteBuffer...) operation in progress. Calling this method with cause future calls to EndPoint.write(Callback, ByteBuffer...) and its variants, to fail the passed Callback.
      Specified by:
      cancelWrite in interface EndPoint
      Parameters:
      cause - the cause
      Returns:
      The callback passed to a pending/in progress write or null if there was none.
    • write

      public void write(boolean last, List<ByteBuffer> buffers, Callback callback)
    • isFillInterested

      public boolean isFillInterested()
      Specified by:
      isFillInterested in interface EndPoint
      Returns:
      whether EndPoint.fillInterested(Callback) has been called, but EndPoint.fill(ByteBuffer) has not yet been called
    • fillInterested

      public void fillInterested(Callback callback)
      Description copied from interface: EndPoint

      Requests callback methods to be invoked when a call to EndPoint.fill(ByteBuffer) would return data or EOF.

      Specified by:
      fillInterested in interface EndPoint
      Parameters:
      callback - the callback to call when an error occurs or we are readable. The callback may implement the Invocable interface to self declare its blocking status. Non-blocking callbacks may be called more efficiently without dispatch delays.
    • tryFillInterested

      public boolean tryFillInterested(Callback callback)
      Description copied from interface: EndPoint

      Requests callback methods to be invoked when a call to EndPoint.fill(ByteBuffer) would return data or EOF.

      Specified by:
      tryFillInterested in interface EndPoint
      Parameters:
      callback - the callback to call when an error occurs or we are readable. The callback may implement the Invocable interface to self declare its blocking status. Non-blocking callbacks may be called more efficiently without dispatch delays.
      Returns:
      true if set
    • getConnection

      public Connection getConnection()
      Specified by:
      getConnection in interface EndPoint
      Returns:
      the Connection associated with this EndPoint
      See Also:
    • setConnection

      public void setConnection(Connection connection)
      Specified by:
      setConnection in interface EndPoint
      Parameters:
      connection - the Connection associated with this EndPoint
      See Also:
    • onOpen

      public void onOpen()
      Description copied from interface: EndPoint

      Callback method invoked when this EndPoint is opened.

      Specified by:
      onOpen in interface EndPoint
      See Also:
    • upgrade

      public void upgrade(Connection newConnection)
      Description copied from interface: EndPoint

      Upgrades this EndPoint from the current connection to the given new connection.

      Closes the current connection, links this EndPoint to the new connection and then opens the new connection.

      If the current connection is an instance of Connection.UpgradeFrom then a buffer of unconsumed bytes is requested. If the buffer of unconsumed bytes is non-null and non-empty, then the new connection is tested: if it is an instance of Connection.UpgradeTo, then the unconsumed buffer is passed to the new connection; otherwise, an exception is thrown since there are unconsumed bytes that cannot be consumed by the new connection.

      Specified by:
      upgrade in interface EndPoint
      Parameters:
      newConnection - the connection to upgrade to
    • getSslSessionData

      public EndPoint.SslSessionData getSslSessionData()
      Description copied from interface: EndPoint

      Returns the SslSessionData of a secure end point.

      Specified by:
      getSslSessionData in interface EndPoint
      Returns:
      A EndPoint.SslSessionData instance (with possibly null field values) if secure, else null.
    • toString

      public String toString()
      Overrides:
      toString in class Object