pltbkd commented on code in PR #938:
URL: https://github.com/apache/flink-agents/pull/938#discussion_r3765267968


##########
runtime/src/main/java/org/apache/flink/agents/runtime/subagent/SubagentFutureGroup.java:
##########
@@ -0,0 +1,100 @@
+/*
+ * 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.flink.agents.runtime.subagent;
+
+import org.apache.flink.agents.api.subagent.Result;
+import org.apache.flink.agents.api.subagent.SubagentFuture;
+import org.apache.flink.agents.api.subagent.SubagentFutures;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * Batched resolve of several handles in submission order. The group knows 
deferred handles: {@link
+ * #awaitAll} prepares every pending deferred handle up front, executes the 
prepared calls as a
+ * batch, and only then collects the outcomes — so the requests are issued 
together instead of one
+ * at a time as each wait starts. Already resolved handles simply contribute 
their value.
+ */
+final class SubagentFutureGroup extends SubagentFutures {
+
+    private final List<SubagentFuture> futures;
+
+    SubagentFutureGroup(SubagentFuture first, SubagentFuture[] others) {
+        this(withFirst(first, others));
+    }
+
+    private static List<SubagentFuture> withFirst(SubagentFuture first, 
SubagentFuture[] others) {
+        List<SubagentFuture> all = new ArrayList<>(1 + others.length);
+        all.add(first);
+        all.addAll(Arrays.asList(others));
+        return all;
+    }
+
+    private SubagentFutureGroup(List<SubagentFuture> futures) {
+        this.futures = futures;
+    }
+
+    @Override
+    public boolean isDone() {
+        for (SubagentFuture future : futures) {
+            if (!future.isDone()) {
+                return false;
+            }
+        }
+        return true;
+    }
+
+    @Override
+    public List<Result> awaitAll() throws Exception {
+        // Prepare every pending deferred handle up front, so the whole batch 
is ready before any
+        // execution starts.
+        for (SubagentFuture future : futures) {
+            if (future instanceof DeferredSubagentFuture && !future.isDone()) {
+                ((DeferredSubagentFuture) future).prepare();
+            }
+        }
+        // TODO: execute the prepared calls as one batch once durable 
execution supports batched

Review Comment:
   Sorry about the confusion — I'll polish the code and docs again once we 
agree on the new surface.
   
   On batching: the plan is indeed to build it on #926, but I haven't verified 
the fit yet. I'd rather pick it up as a follow-up after #926 lands — batching 
stays internal to group resolution, so it shouldn't affect the overall design.



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

Reply via email to