You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2021/11/29 20:31:17 UTC

[GitHub] [pulsar] eolivelli commented on a change in pull request #11112: [PIP 86][Function] Preload and release of external resources

eolivelli commented on a change in pull request #11112:
URL: https://github.com/apache/pulsar/pull/11112#discussion_r758711420



##########
File path: pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstance.java
##########
@@ -158,9 +177,25 @@ private void processAsyncResults(BiConsumer<Record, JavaExecutionResult> resultC
     }
 
     @Override
-    public void close() {
+    public void close() throws Exception {
         context.close();
         executor.shutdown();
+        if (null != function && function instanceof RichFunction) {

Review comment:
       Actually you don't need the null check as null is never a instance of a class

##########
File path: pulsar-functions/api-java/src/main/java/org/apache/pulsar/functions/api/RichFunction.java
##########
@@ -0,0 +1,45 @@
+/**
+ * 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.pulsar.functions.api;
+
+import org.apache.pulsar.common.classification.InterfaceAudience;
+
+/**
+ * An interface for richFunction
+ * Extension for Function interface
+ * Initial and close of external resources
+ */
+@InterfaceAudience.Public
+public interface RichFunction extends Function{
+
+    /**
+     * InitialResource Function Hook
+     *
+     * @throws Exception
+     */
+    void setup() throws Exception;

Review comment:
       I would pass some Context in order to let the Function initialise using the information about the env.




-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org