abbccdda commented on a change in pull request #8887:
URL: https://github.com/apache/kafka/pull/8887#discussion_r441954245



##########
File path: 
streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java
##########
@@ -1048,4 +1042,28 @@ public String toString(final String indent) {
     Set<TaskId> lockedTaskDirectories() {
         return Collections.unmodifiableSet(lockedTaskDirectories);
     }
+
+    public static void executeAndMaybeSwallow(final boolean clean,
+                                              final Runnable runnable,
+                                              final 
java.util.function.Consumer<RuntimeException> actionIfClean,
+                                              final 
java.util.function.Consumer<RuntimeException> actionIfNotClean) {

Review comment:
       It seems not possible in Java

##########
File path: 
streams/src/main/java/org/apache/kafka/streams/processor/internals/TaskManager.java
##########
@@ -741,29 +741,23 @@ void shutdown(final boolean clean) {
 
         for (final Task task : tasks.values()) {
             if (task.isActive()) {
-                try {
-                    
activeTaskCreator.closeAndRemoveTaskProducerIfNeeded(task.id());
-                } catch (final RuntimeException e) {
-                    if (clean) {
-                        firstException.compareAndSet(null, e);
-                    } else {
-                        log.warn("Ignoring an exception while closing task " + 
task.id() + " producer.", e);
-                    }
-                }
+                executeAndMaybeSwallow(
+                    clean,
+                    () -> 
activeTaskCreator.closeAndRemoveTaskProducerIfNeeded(task.id()),
+                    e -> firstException.compareAndSet(null, e),
+                    e -> log.warn("Ignoring an exception while closing task " 
+ task.id() + " producer.", e)
+                );
             }
         }
 
         tasks.clear();
 
-        try {
-            activeTaskCreator.closeThreadProducerIfNeeded();
-        } catch (final RuntimeException e) {
-            if (clean) {
-                firstException.compareAndSet(null, e);
-            } else {
-                log.warn("Ignoring an exception while closing thread 
producer.", e);
-            }
-        }
+        executeAndMaybeSwallow(
+            clean,
+            () -> activeTaskCreator.closeThreadProducerIfNeeded(),

Review comment:
       could be replaced by lambda.




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


Reply via email to