You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@samza.apache.org by GitBox <gi...@apache.org> on 2020/05/27 04:05:12 UTC

[GitHub] [samza] cameronlee314 commented on a change in pull request #1366: SAMZA-2529: Extract interface from TaskInstance for reuse of RunLoop

cameronlee314 commented on a change in pull request #1366:
URL: https://github.com/apache/samza/pull/1366#discussion_r430587635



##########
File path: samza-core/src/main/java/org/apache/samza/container/RunLoopTask.java
##########
@@ -0,0 +1,68 @@
+/*
+ * 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.samza.container;
+
+import java.util.Collections;
+import org.apache.samza.checkpoint.OffsetManager;
+import org.apache.samza.scheduler.EpochTimeScheduler;
+import org.apache.samza.system.IncomingMessageEnvelope;
+import org.apache.samza.system.SystemStreamPartition;
+import org.apache.samza.task.ReadableCoordinator;
+import org.apache.samza.task.TaskCallbackFactory;
+import scala.collection.JavaConversions;
+
+
+public interface RunLoopTask {

Review comment:
       +1 regarding adding docs to each method. Ideally, there would have already been more docs in `TaskInstance`, but it is more useful now that this is an interface.

##########
File path: samza-core/src/test/java/org/apache/samza/container/TestRunLoop.java
##########
@@ -236,7 +236,7 @@ public void testProcessMultipleTasks() throws Exception {
     TaskInstance t0 = createTaskInstance(task0, taskName0, ssp0, offsetManager, consumerMultiplexer);
     TaskInstance t1 = createTaskInstance(task1, taskName1, ssp1, offsetManager, consumerMultiplexer);
 
-    Map<TaskName, TaskInstance> tasks = new HashMap<>();

Review comment:
       Should `RunLoopTask` now be mocked in this test instead of using a concrete `TaskInstance`? It could help to validate your extraction of the interface and simplify the test to not depend on `TaskInstance`.

##########
File path: samza-core/src/main/java/org/apache/samza/container/RunLoopTask.java
##########
@@ -0,0 +1,71 @@
+/*
+ * 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.samza.container;
+
+import java.util.Collections;
+import java.util.Set;
+import org.apache.samza.checkpoint.OffsetManager;
+import org.apache.samza.scheduler.EpochTimeScheduler;
+import org.apache.samza.system.IncomingMessageEnvelope;
+import org.apache.samza.system.SystemStreamPartition;
+import org.apache.samza.task.ReadableCoordinator;
+import org.apache.samza.task.TaskCallbackFactory;
+
+
+/**
+ * The interface required for a task's execution to be managed within {@link RunLoop}.
+ */
+public interface RunLoopTask {
+
+  TaskName taskName();
+
+  Set<SystemStreamPartition> systemStreamPartitions();
+
+  TaskInstanceMetrics metrics();
+
+  void process(IncomingMessageEnvelope envelope, ReadableCoordinator coordinator, TaskCallbackFactory callbackFactory);
+
+  void endOfStream(ReadableCoordinator coordinator);
+
+  void window(ReadableCoordinator coordinator);
+
+  void scheduler(ReadableCoordinator coordinator);
+
+  void commit();
+
+  default boolean isWindowableTask() {
+    return false;
+  }
+
+  default boolean isAsyncTask() {
+    return false;
+  }
+
+  default EpochTimeScheduler epochTimeScheduler() {
+    return null;
+  }
+
+  default Set<String> intermediateStreams() {
+    return Collections.emptySet();
+  }
+
+  default OffsetManager offsetManager() {
+    return null;
+  }

Review comment:
       In my opinion, default implementations should be used when most of the implementors do not need to implement the methods or when you want to evolve an interface in a backwards compatible way. It doesn't sound like that is the case here, so maybe just require all implementors to implement these methods. The disadvantage of default implementations is that someone could unintentionally forget to implement them when they were supposed to implement them. Requiring implementations makes things explicit, and sometimes that is helpful.




----------------------------------------------------------------
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:
users@infra.apache.org