YvCeung commented on code in PR #7903:
URL: https://github.com/apache/incubator-seata/pull/7903#discussion_r2777224468


##########
common/src/main/java/org/apache/seata/common/util/HttpClientUtil.java:
##########
@@ -265,25 +215,101 @@ private static String buildUrlWithParams(String url, 
Map<String, String> params)
         return urlBuilder.toString();
     }
 
-    private static void executeAsync(OkHttpClient client, Request request, 
final HttpCallback<Response> callback) {
-        client.newCall(request).enqueue(new Callback() {
-            @Override
-            public void onResponse(Call call, Response response) {
-                try {
-                    callback.onSuccess(response);
-                } finally {
-                    response.close();
-                }
-            }
+    /**
+     * Create an HTTP/2 client for watch connections.
+     * This client is configured for long-lived connections to receive 
Server-Sent Events (SSE).
+     * The client instances are cached and reused based on the connection 
timeout to improve performance.
+     *
+     * @param connectTimeoutSeconds connection timeout in seconds (fast 
failure if server is unreachable)
+     * @return configured OkHttpClient instance (cached and reused)
+     */
+    private static OkHttpClient createHttp2WatchClient(int 
connectTimeoutSeconds) {
+        return HTTP2_CLIENT_MAP.computeIfAbsent(connectTimeoutSeconds, k -> 
new OkHttpClient.Builder()
+                
.protocols(Collections.singletonList(Protocol.H2_PRIOR_KNOWLEDGE))
+                // Fast failure during connection phase
+                .connectTimeout(connectTimeoutSeconds, TimeUnit.SECONDS)
+                // Infinite read timeout to allow continuous listening for 
server push
+                .readTimeout(0, TimeUnit.SECONDS)
+                .writeTimeout(connectTimeoutSeconds, TimeUnit.SECONDS)
+                .build());

Review Comment:
   Currently, read timeout is being used as the key, which is a more reasonable 
approach.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to