nlu90 commented on a change in pull request #11112: URL: https://github.com/apache/pulsar/pull/11112#discussion_r664791831
########## 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 HookFunction) { + try { + ((HookFunction) function).cleanup(); + } catch (Exception e) { + log.error("function closeResource occurred exception", e); + throw e; + } + } + if (null != javaUtilFunction && javaUtilFunction instanceof HookFunction) { + try { + ((HookFunction) javaUtilFunction).cleanup(); + } catch (Exception e) { Review comment: I suggest we keep `java.util.Function` as simple as possible, and not add hook method for it ########## File path: pulsar-functions/instance/src/main/java/org/apache/pulsar/functions/instance/JavaInstance.java ########## @@ -74,6 +75,24 @@ public JavaInstance(ContextImpl contextImpl, Object userClassObject, InstanceCon } } + public void setup() throws Exception { + if (null != function && function instanceof HookFunction) { + try { + ((HookFunction) function).setup(); + } catch (Exception e) { + log.error("setup error:", e); + throw e; + } + } + if (null != javaUtilFunction && javaUtilFunction instanceof HookFunction) { + try { + ((HookFunction) javaUtilFunction).setup(); + } catch (Exception e) { + log.error("setup error:", e); + throw e; + } + } Review comment: I suggest we keep `java.util.Function` as simple as possible, and not add hook method for it -- 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-unsubscr...@pulsar.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org