adutra commented on code in PR #4648:
URL: https://github.com/apache/polaris/pull/4648#discussion_r3383199456


##########
runtime/service/src/main/java/org/apache/polaris/service/events/PolarisEventListeners.java:
##########
@@ -116,4 +143,43 @@ private void deliverEvent(
   public boolean hasListeners(PolarisEventType polarisEventType) {
     return enabledEventTypes.contains(polarisEventType);
   }
+
+  private static class ListenerExecutor implements Executor {
+
+    private final Executor delegate;
+    private final Queue<Runnable> queue;
+    private final AtomicBoolean draining = new AtomicBoolean(false);
+
+    ListenerExecutor(Executor delegate, int capacity) {
+      this.delegate = delegate;
+      this.queue =
+          capacity == -1 ? new ConcurrentLinkedQueue<>() : new 
ArrayBlockingQueue<>(capacity);
+    }
+
+    @Override
+    public void execute(@NonNull Runnable task) {
+      if (!queue.offer(task)) {
+        throw new RejectedExecutionException("Event listener queue is full");
+      }
+      if (draining.compareAndSet(false, true)) {
+        delegate.execute(this::drain);
+      }
+    }
+
+    private void drain() {
+      try {
+        Runnable task;
+        while ((task = queue.poll()) != null) {
+          task.run();

Review Comment:
   I am not sure it's worth the extra configuration option. The goal is to have 
at least as many threads as listeners, which is the default setup – unless you 
have more listeners than CPU cores which seems unlikely with modern hardware.



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to