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


##########
common/src/main/java/org/apache/seata/common/util/SeataHttpWatch.java:
##########
@@ -0,0 +1,286 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.seata.common.util;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import okhttp3.Call;
+import okhttp3.OkHttpClient;
+import okhttp3.Request;
+import okhttp3.ResponseBody;
+import okio.BufferedSource;
+import org.apache.seata.common.exception.FrameworkException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * Seata HTTP/2 Watch implementation.
+ * Consumes server-pushed SSE data frames via an iterator-style API.
+ *
+ * @param <T> event data type
+ */
+public class SeataHttpWatch<T>
+        implements Iterator<SeataHttpWatch.Response<T>>, 
Iterable<SeataHttpWatch.Response<T>>, AutoCloseable {

Review Comment:
   Yes, this is intentional.
   The Iterable interface is implemented specifically to allow for-each style 
consumption.
   The iterator() method deliberately returns this, so the Iterable and 
Iterator share the same instance.
   
   This watch represents a one-shot, sequential network stream (HTTP/2 SSE), 
not a replayable collection.
   Multiple iterations are therefore not supported by design — all next() calls 
consume the same underlying stream and continue from the current position.
   
   Guarding against multiple iterations would not add real safety here and 
could be misleading, since re-iteration is neither expected nor meaningful for 
a streaming source.
   
   这个类实现 Iterable 的目的很明确:
   只是为了支持 for-each 使用方式。
   iterator() 返回 this 是刻意设计的,意味着:
   Iterable 和 Iterator 是同一个对象
   所有 next() 调用都在消费同一条底层网络流
   该 watch 是一次性的 streaming source,而不是可重复遍历的集合



-- 
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