xintongsong commented on code in PR #85:
URL: https://github.com/apache/flink-agents/pull/85#discussion_r2258736553


##########
runtime/src/main/java/org/apache/flink/agents/runtime/env/LocalExecutionEnvironment.java:
##########
@@ -0,0 +1,242 @@
+/*
+ * 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.env;
+
+import org.apache.flink.agents.api.Action;
+import org.apache.flink.agents.api.Agent;
+import org.apache.flink.agents.api.AgentBuilder;
+import org.apache.flink.agents.api.AgentsExecutionEnvironment;
+import org.apache.flink.agents.api.Event;
+import org.apache.flink.agents.api.InputEvent;
+import org.apache.flink.agents.api.OutputEvent;
+import org.apache.flink.agents.api.context.RunnerContext;
+import org.apache.flink.api.java.functions.KeySelector;
+import org.apache.flink.streaming.api.datastream.DataStream;
+import org.apache.flink.table.api.Schema;
+import org.apache.flink.table.api.Table;
+import org.apache.flink.table.api.bridge.java.StreamTableEnvironment;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Queue;
+
+/**
+ * Implementation of AgentsExecutionEnvironment for local execution.
+ *
+ * <p>This environment is primarily used for testing and development, allowing 
agents to be executed
+ * locally without a Flink cluster.
+ */
+public class LocalExecutionEnvironment extends AgentsExecutionEnvironment {
+
+    @Override
+    public AgentBuilder fromList(List<Object> input) {
+        return new LocalAgentBuilder(input);
+    }
+
+    @Override
+    public <T, K> AgentBuilder fromDataStream(DataStream<T> input, 
KeySelector<T, K> keySelector) {
+        throw new UnsupportedOperationException(
+                "LocalExecutionEnvironment does not support fromDataStream. 
Use RemoteExecutionEnvironment instead.");
+    }
+
+    @Override
+    public <K> AgentBuilder fromTable(
+            Table input, StreamTableEnvironment tableEnv, KeySelector<Object, 
K> keySelector) {
+        throw new UnsupportedOperationException(
+                "LocalExecutionEnvironment does not support fromTable. Use 
RemoteExecutionEnvironment instead.");
+    }
+
+    @Override
+    public void execute() throws Exception {
+        // For local execution, the execution happens immediately when 
toList() is
+        // called
+        // This method is kept for API compatibility
+    }
+
+    /** Implementation of AgentBuilder for local execution environment. */
+    private static class LocalAgentBuilder implements AgentBuilder {
+
+        private final List<Object> input;
+        private Agent agent;
+        private List<Map<String, Object>> output;
+
+        public LocalAgentBuilder(List<Object> input) {
+            this.input = input;
+        }
+
+        @Override
+        public AgentBuilder apply(Agent agent) {
+            this.agent = agent;
+            return this;
+        }
+
+        @Override
+        public List<Map<String, Object>> toList() {
+            if (agent == null) {
+                throw new IllegalStateException("Must apply agent before 
calling toList");
+            }
+
+            if (output == null) {
+                output = executeAgent();
+            }
+
+            return output;
+        }
+
+        @Override
+        public DataStream<Object> toDataStream() {
+            throw new UnsupportedOperationException(
+                    "LocalAgentBuilder does not support toDataStream. Use 
toList instead.");
+        }
+
+        @Override
+        public Table toTable(Schema schema) {
+            throw new UnsupportedOperationException(
+                    "LocalAgentBuilder does not support toTable. Use toList 
instead.");
+        }
+
+        private List<Map<String, Object>> executeAgent() {

Review Comment:
   Thank you. I also created an issue to track this.
   #95



-- 
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: issues-unsubscr...@flink.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to