java.lang.Object
org.miaixz.bus.http.metric.http.Http2Connection.Listener
org.miaixz.bus.http.accord.RealConnection
- All Implemented Interfaces:
Connection
A concrete connection to a target server (either directly or via a proxy). This class handles the low-level details
of establishing and maintaining the connection, including TLS handshakes and HTTP/2 multiplexing.
- Since:
- Java 17+
- Author:
- Kimi Liu
-
Field Summary
FieldsFields inherited from class org.miaixz.bus.http.metric.http.Http2Connection.Listener
REFUSE_INCOMING_STREAMS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidcancel()Cancels this connection.voidconnect(int connectTimeout, int readTimeout, int writeTimeout, int pingIntervalMillis, boolean connectionRetryEnabled, NewCall call, EventListener eventListener) Establishes a connection to the target server.Returns the TLS handshake used to establish this connection, or null if the connection is not HTTPS.booleanisHealthy(boolean doExtensiveChecks) Returns true if this connection is ready to host new streams.booleanReturns true if this is an HTTP/2 connection.voidPrevents further exchanges from being created on this connection.voidonSettings(Http2Connection connection) When settings are received, adjust the allocation limit.voidonStream(Http2Stream stream) Refuses incoming streams.org.miaixz.bus.core.net.Protocolprotocol()Returns the protocol negotiated by this connection, orProtocol.HTTP_1_1if no protocol was negotiated.route()Returns the route that this connection follows.socket()Returns the socket that this connection uses.booleansupportsUrl(UnoUrl url) Returns true if this connection can be used forurl.toString()
-
Field Details
-
connectionPool
-
-
Constructor Details
-
RealConnection
-
-
Method Details
-
noNewExchanges
public void noNewExchanges()Prevents further exchanges from being created on this connection. -
connect
public void connect(int connectTimeout, int readTimeout, int writeTimeout, int pingIntervalMillis, boolean connectionRetryEnabled, NewCall call, EventListener eventListener) throws IOException Establishes a connection to the target server.- Parameters:
connectTimeout- The connect timeout in milliseconds.readTimeout- The read timeout in milliseconds.writeTimeout- The write timeout in milliseconds.pingIntervalMillis- The ping interval in milliseconds for HTTP/2.connectionRetryEnabled- Whether connection retries are enabled.call- The call that initiated this connection.eventListener- The event listener for connection events.- Throws:
IOException- if an I/O error occurs during connection establishment.
-
supportsUrl
Returns true if this connection can be used forurl.- Parameters:
url- The URL to check.- Returns:
trueif the connection supports the URL.
-
route
Description copied from interface:ConnectionReturns the route that this connection follows.- Specified by:
routein interfaceConnection- Returns:
- The route of this connection.
-
cancel
public void cancel()Cancels this connection. -
socket
Description copied from interface:ConnectionReturns the socket that this connection uses. If this connection is HTTPS, this is anSSLSocket. If this is an HTTP/2 connection the socket may be shared by multiple concurrent calls.- Specified by:
socketin interfaceConnection- Returns:
- The socket for this connection.
-
isHealthy
public boolean isHealthy(boolean doExtensiveChecks) Returns true if this connection is ready to host new streams.- Parameters:
doExtensiveChecks- Whether to perform extensive health checks.- Returns:
trueif the connection is healthy.
-
onStream
Refuses incoming streams.- Specified by:
onStreamin classHttp2Connection.Listener- Parameters:
stream- The HTTP/2 stream.- Throws:
IOException- if an I/O error occurs.
-
onSettings
When settings are received, adjust the allocation limit.- Overrides:
onSettingsin classHttp2Connection.Listener- Parameters:
connection- The HTTP/2 connection.
-
handshake
Description copied from interface:ConnectionReturns the TLS handshake used to establish this connection, or null if the connection is not HTTPS.- Specified by:
handshakein interfaceConnection- Returns:
- The TLS handshake, or null.
-
isMultiplexed
public boolean isMultiplexed()Returns true if this is an HTTP/2 connection. Such connections can be used in multiple HTTP requests simultaneously.- Returns:
trueif the connection is multiplexed.
-
protocol
public org.miaixz.bus.core.net.Protocol protocol()Description copied from interface:ConnectionReturns the protocol negotiated by this connection, orProtocol.HTTP_1_1if no protocol was negotiated. This method returnsProtocol.HTTP_1_1even if the remote peer is usingProtocol.HTTP_1_0.- Specified by:
protocolin interfaceConnection- Returns:
- The negotiated protocol.
-
toString
-