[ 
https://issues.apache.org/jira/browse/FLINK-10552?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16696751#comment-16696751
 ] 

ASF GitHub Bot commented on FLINK-10552:
----------------------------------------

Clarkkkkk closed pull request #6878: [FLINK-10552][DataStream API]Add supports 
for RichAsyncFunction in Scala API
URL: https://github.com/apache/flink/pull/6878
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git 
a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/async/RichAsyncFunction.java
 
b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/async/RichAsyncFunction.java
index 8d9ac8fa185..c4051516b51 100644
--- 
a/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/async/RichAsyncFunction.java
+++ 
b/flink-streaming-java/src/main/java/org/apache/flink/streaming/api/functions/async/RichAsyncFunction.java
@@ -97,10 +97,10 @@ public void setRuntimeContext(RuntimeContext 
runtimeContext) {
         * context only supports basic operations which are thread safe. 
Consequently, state access,
         * accumulators, broadcast variables and the distributed cache are 
disabled.
         */
-       private static class RichAsyncFunctionRuntimeContext implements 
RuntimeContext {
+       public static class RichAsyncFunctionRuntimeContext implements 
RuntimeContext {
                private final RuntimeContext runtimeContext;
 
-               RichAsyncFunctionRuntimeContext(RuntimeContext context) {
+               public RichAsyncFunctionRuntimeContext(RuntimeContext context) {
                        runtimeContext = Preconditions.checkNotNull(context);
                }
 
@@ -239,11 +239,16 @@ public boolean hasBroadcastVariable(String name) {
                }
        }
 
-       private static class RichAsyncFunctionIterationRuntimeContext extends 
RichAsyncFunctionRuntimeContext implements IterationRuntimeContext {
+       /**
+        * A wrapper class for async function's {@link 
IterationRuntimeContext}. The async function runtime
+        * context only supports basic operations which are thread safe. 
Consequently, state access,
+        * accumulators, broadcast variables, the distributed cache and 
iteration aggregator are disabled.
+        */
+       public static class RichAsyncFunctionIterationRuntimeContext extends 
RichAsyncFunctionRuntimeContext implements IterationRuntimeContext {
 
                private final IterationRuntimeContext iterationRuntimeContext;
 
-               
RichAsyncFunctionIterationRuntimeContext(IterationRuntimeContext 
iterationRuntimeContext) {
+               public 
RichAsyncFunctionIterationRuntimeContext(IterationRuntimeContext 
iterationRuntimeContext) {
                        super(iterationRuntimeContext);
 
                        this.iterationRuntimeContext = 
Preconditions.checkNotNull(iterationRuntimeContext);
diff --git 
a/flink-streaming-scala/src/main/scala/org/apache/flink/streaming/api/scala/async/RichAsyncFunction.scala
 
b/flink-streaming-scala/src/main/scala/org/apache/flink/streaming/api/scala/async/RichAsyncFunction.scala
new file mode 100644
index 00000000000..6d88eef7643
--- /dev/null
+++ 
b/flink-streaming-scala/src/main/scala/org/apache/flink/streaming/api/scala/async/RichAsyncFunction.scala
@@ -0,0 +1,44 @@
+/*
+ * 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.api.scala.async
+
+import org.apache.flink.api.common.functions.{AbstractRichFunction, 
IterationRuntimeContext, RuntimeContext}
+import 
org.apache.flink.streaming.api.functions.async.RichAsyncFunction.{RichAsyncFunctionIterationRuntimeContext,
 RichAsyncFunctionRuntimeContext}
+import org.apache.flink.util.Preconditions
+
+/**
+  * Rich variant of the [[AsyncFunction]].
+  * As a [[org.apache.flink.api.common.functions.RichFunction]], it gives 
access to
+  * the [[RuntimeContext]] and provides setup and teardown methods.
+  *
+  * @tparam IN The type of the input element
+  * @tparam OUT The type of the output elements
+  */
+trait RichAsyncFunction[IN, OUT] extends AbstractRichFunction with 
AsyncFunction[IN, OUT]{
+  override def setRuntimeContext(runtimeContext: RuntimeContext): Unit = {
+    Preconditions.checkNotNull(runtimeContext)
+
+    if (runtimeContext.isInstanceOf[IterationRuntimeContext]) {
+      super.setRuntimeContext(new RichAsyncFunctionIterationRuntimeContext(
+        runtimeContext.asInstanceOf[IterationRuntimeContext]));
+    } else {
+      super.setRuntimeContext(new 
RichAsyncFunctionRuntimeContext(runtimeContext));
+    }
+  }
+}


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on 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


> Provide RichAsyncFunction for scala API
> ---------------------------------------
>
>                 Key: FLINK-10552
>                 URL: https://issues.apache.org/jira/browse/FLINK-10552
>             Project: Flink
>          Issue Type: Improvement
>          Components: DataStream API
>            Reporter: Shimin Yang
>            Assignee: Shimin Yang
>            Priority: Major
>
> Currently, only Java API provide a RichAsyncFunction abstract class while 
> scala dose not. Thought it would be nice to provide the same function for 
> scala api. 



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to