StephanEwen commented on a change in pull request #10483: 
[FLINK-15099][runtime] (FLIP-27) Add Operator Coordinators and Events
URL: https://github.com/apache/flink/pull/10483#discussion_r377727252
 
 

 ##########
 File path: 
flink-streaming-java/src/main/java/org/apache/flink/streaming/runtime/tasks/OperatorEventDispatcherImpl.java
 ##########
 @@ -0,0 +1,124 @@
+/*
+ * 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.streaming.runtime.tasks;
+
+import org.apache.flink.annotation.Internal;
+import org.apache.flink.runtime.execution.Environment;
+import org.apache.flink.runtime.jobgraph.OperatorID;
+import org.apache.flink.runtime.jobgraph.tasks.OperatorEventSender;
+import org.apache.flink.runtime.operators.coordination.OperatorEvent;
+import org.apache.flink.runtime.operators.coordination.OperatorEventDispatcher;
+import org.apache.flink.runtime.operators.coordination.OperatorEventGateway;
+import org.apache.flink.runtime.operators.coordination.OperatorEventHandler;
+import org.apache.flink.util.FlinkException;
+import org.apache.flink.util.FlinkRuntimeException;
+import org.apache.flink.util.SerializedValue;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+
+/**
+ * An implementation of the {@link OperatorEventDispatcher}.
+ *
+ * <p>This class is intended for single threaded use from the stream task 
mailbox.
+ */
+@Internal
+final class OperatorEventDispatcherImpl implements OperatorEventDispatcher {
+
+       private final Map<OperatorID, OperatorEventHandler> handlers;
+
+       private final ClassLoader classLoader;
+
+       private final OperatorEventSender toCoordinator;
+
+       OperatorEventDispatcherImpl(ClassLoader classLoader, 
OperatorEventSender toCoordinator) {
+               this.classLoader = checkNotNull(classLoader);
+               this.toCoordinator = checkNotNull(toCoordinator);
+               this.handlers = new HashMap<>();
+       }
+
+       void dispatchEventToHandlers(OperatorID operatorID, 
SerializedValue<OperatorEvent> serializedEvent) throws FlinkException {
+               final OperatorEvent evt;
+               try {
+                       evt = serializedEvent.deserializeValue(classLoader);
+               }
+               catch (IOException | ClassNotFoundException e) {
+                       throw new FlinkException("Could not deserialize 
operator event", e);
+               }
+
+               final OperatorEventHandler handler = handlers.get(operatorID);
+               if (handler != null) {
+                       handler.handleOperatorEvent(evt);
+               }
+               else {
+                       throw new FlinkException("Operator not registered for 
operator events");
+               }
+       }
+
+       @Override
+       public OperatorEventGateway registerEventHandler(OperatorID operator, 
OperatorEventHandler handler) {
+               final OperatorEventGateway gateway = new 
OperatorEventGatewayImpl(toCoordinator, operator);
+               final OperatorEventHandler prior = 
handlers.putIfAbsent(operator, handler);
+
+               if (prior == null) {
+                       return gateway;
+               }
+               else {
+                       throw new IllegalStateException("already a handler 
registered for this operatorId");
+               }
+       }
+
+       // 
------------------------------------------------------------------------
+
+       static OperatorEventDispatcherImpl fromEnvironment(Environment env) {
 
 Review comment:
   Fair enough. I have no strong feelings about this particular issue, so if 
you believe it is better to remove the static method, let me do that.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to