vjagadish1989 commented on a change in pull request #905: SAMZA-2055: [WIP] 
Async high level api
URL: https://github.com/apache/samza/pull/905#discussion_r262797705
 
 

 ##########
 File path: 
samza-core/src/main/java/org/apache/samza/operators/impl/AsyncStreamOperatorImpl.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.operators.impl;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.concurrent.CompletionStage;
+import java.util.concurrent.ExecutionException;
+import org.apache.samza.SamzaException;
+import org.apache.samza.context.Context;
+import org.apache.samza.operators.functions.AsyncFlatMapFunction;
+import org.apache.samza.operators.spec.AsyncOperatorSpec;
+import org.apache.samza.operators.spec.OperatorSpec;
+import org.apache.samza.task.MessageCollector;
+import org.apache.samza.task.TaskCoordinator;
+
+
+public class AsyncStreamOperatorImpl<M, RM> extends OperatorImpl<M, RM> {
+  private final AsyncOperatorSpec<M, RM> asyncOperatorSpec;
+  private final AsyncFlatMapFunction<M, RM> transformFn;
+
+  AsyncStreamOperatorImpl(AsyncOperatorSpec<M, RM> asyncOperatorSpec) {
+    this.asyncOperatorSpec = asyncOperatorSpec;
+    this.transformFn = asyncOperatorSpec.getTransformFn();
+  }
+  @Override
+  protected void handleInit(Context context) {
+    this.transformFn.init(context);
+  }
+
+  @Override
+  protected Collection<RM> handleMessage(M message, MessageCollector 
collector, TaskCoordinator coordinator) {
 
 Review comment:
   this logic looks a bit complex, primarily stemming from these 2 issues; 
   
   Firstly, we are mixing sync and async-apis in the `OperatorImpl` base-class. 
   
   ```
   final T onMessage
   final Future[T] onMessageAsync
   protected T handleMessage
   protected Future[T] handleMessageAsync
   ```
   
   Secondly, the delegation sequence is a bit round-about for operator classes 
extending this base-class. For sync operators, `BaseClass#onMessageAsync` 
delegates to `BaseClass#handleMessageAsync` which in-turn delegates to 
`DerivedClass#handleMessageSync`. For async operators, 
`BaseClass#onMessageAsync` delegates to `DerivedClass#handleMessageAsync` 
   
   I would re-think the base class to only expose the async variant. 
Additionally,  make `handleMessageAsync()` abstract method.
   
   ```
    final Future[T] onMessageAsync
    abstract Future[T] handleMessageAsync
   ```
   This also un-confuses the delegation sequence; the base method 
`onMessageAsync` always delegates to `handleMessageAsync` on the derived 
class.. You may need to add a little bit of boiler-plate to some derived 
classes, but I think that's an acceptable tradeoff
   
   
   
   
   
   
   

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