Class Http2Connection

java.lang.Object
org.miaixz.bus.http.metric.http.Http2Connection
All Implemented Interfaces:
Closeable, AutoCloseable

public class Http2Connection extends Object implements Closeable
到远程对等点的套接字连接。连接主机可以发送和接收数据流.
Since:
Java 17+
Author:
Kimi Liu
  • Method Details

    • openStreamCount

      public int openStreamCount()
      Returns the number of open streams on this connection.
    • maxConcurrentStreams

      public int maxConcurrentStreams()
    • pushStream

      public Http2Stream pushStream(int associatedStreamId, List<Http2Header> requestHeaders, boolean out) throws IOException
      返回一个新的服务器发起的流.
      Parameters:
      associatedStreamId - 触发发送方创建此流的流.
      requestHeaders - 请求头信息
      out - 创建一个输出流,我们可以使用它将数据发送到远程对等端。对应FLAG_FIN
      Returns:
      http请求流
      Throws:
      IOException - 异常
    • newStream

      public Http2Stream newStream(List<Http2Header> requestHeaders, boolean out) throws IOException
      Returns a new locally-initiated stream.
      Parameters:
      out - true to create an output stream that we can use to send data to the remote peer. Corresponds to FLAG_FIN.
      Throws:
      IOException
    • writeData

      public void writeData(int streamId, boolean outFinished, org.miaixz.bus.core.io.buffer.Buffer buffer, long byteCount) throws IOException
      此方法的调用程序不是线程安全的,有时在应用程序线程上也是如此。 通常,将调用此方法将数据的缓冲区发送给对等方. 写取决于流和连接的写窗口。在有足够的窗口发送byteCount之前, 调用者将阻塞。例如,HttpURLConnection的用户向输出流刷新的 字节比连接的写窗口多,就会阻塞
      Parameters:
      streamId - 是否streamId
      outFinished - 是否结束
      buffer - 缓冲
      byteCount - 字节流大小
      Throws:
      IOException - 异常
    • flush

      public void flush() throws IOException
      Throws:
      IOException
    • shutdown

      public void shutdown(Http2ErrorCode statusCode) throws IOException
      Degrades this connection such that new streams can neither be created locally, nor accepted from the remote peer. Existing streams are not impacted. This is intended to permit an endpoint to gracefully stop accepting new requests without harming previously established streams.
      Throws:
      IOException
    • close

      public void close()
      Closes this connection. This cancels all open streams and unanswered pings. It closes the underlying input and output streams and shuts down internal executor services.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • start

      public void start() throws IOException
      Sends any initial frames and starts reading frames from the remote peer. This should be called after Http2Connection.Builder.build() for all new connections.
      Throws:
      IOException
    • setSettings

      public void setSettings(Http2Settings settings) throws IOException
      Merges settings into this peer's settings and sends them to the remote peer.
      Throws:
      IOException
    • isHealthy

      public boolean isHealthy(long nowNs)