sohardforaname commented on code in PR #13659:
URL: https://github.com/apache/doris/pull/13659#discussion_r1028717974


##########
fe/fe-core/src/main/java/org/apache/doris/nereids/metrics/EventChannel.java:
##########
@@ -0,0 +1,127 @@
+// 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.doris.nereids.metrics;
+
+import org.apache.doris.qe.ConnectContext;
+
+import com.google.common.base.Preconditions;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+import java.util.Set;
+import java.util.concurrent.BlockingQueue;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.atomic.AtomicBoolean;
+
+/**
+ * event channel
+ */
+public class EventChannel {
+    private static final Logger LOG = LogManager.getLogger(EventChannel.class);
+    private static final EventChannel DEFAULT_CHANNEL = new EventChannel();
+    private Set<Class<? extends Event>> eventSwitch = new HashSet<>();
+    private final Map<Class<? extends Event>, List<EventConsumer>> consumers = 
Maps.newHashMap();
+    private final Map<Class<? extends Event>, EventEnhancer> enhancers = 
Maps.newHashMap();
+    private final BlockingQueue<Event> queue = new LinkedBlockingQueue<>(4096);
+    private final AtomicBoolean isStop = new AtomicBoolean(false);
+    private Thread thread;
+
+    public void add(Event e) {
+        queue.add(e);
+    }
+
+    public synchronized EventChannel addConsumers(List<EventConsumer> 
consumers) {
+        consumers.forEach(consumer -> this.consumers
+                .computeIfAbsent(consumer.getTargetClass(), k -> 
Lists.newArrayList()).add(consumer));
+        return this;
+    }
+
+    public synchronized EventChannel addEnhancers(List<EventEnhancer> 
enhancers) {
+        enhancers.forEach(enhancer -> 
this.enhancers.putIfAbsent(enhancer.getTargetClass(), enhancer));
+        return this;
+    }
+
+    public synchronized EventChannel setConnectContext(ConnectContext context) 
{
+        Preconditions.checkArgument(Objects.nonNull(context));
+        if (context.getSessionVariable().isEnableNereidsTrace()) {
+            eventSwitch = new 
EventSwitchParser().parse(context.getSessionVariable().getNereidsEventMode());

Review Comment:
   yes, I forget to add when Nereids initializes, I will change it.



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