philipnee commented on code in PR #14118:
URL: https://github.com/apache/kafka/pull/14118#discussion_r1305857336


##########
clients/src/main/java/org/apache/kafka/clients/consumer/internals/WakeupTrigger.java:
##########
@@ -0,0 +1,105 @@
+/*
+ * 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.kafka.clients.consumer.internals;
+
+import org.apache.kafka.common.KafkaException;
+import org.apache.kafka.common.errors.WakeupException;
+
+import java.util.Objects;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.atomic.AtomicReference;
+
+/**
+ * Ensures blocking APIs can be woken up by the consumer.wakeup().
+ */
+public class WakeupTrigger {
+    private AtomicReference<Wakeupable> pendingTask = new 
AtomicReference<>(null);
+
+    /*
+    Wakeup a pending task.  If there isn't any pending task, return a 
WakedupFuture, so that the subsequent call
+    would know wakeup was previously called.
+
+    If there are active taks, complete it with WakeupException, then unset 
pending task (return null here.
+    If the current task has already been wakedup, do nothing.
+     */
+    public void wakeup() {
+        pendingTask.getAndUpdate(task -> {
+            if (task == null) {
+                return new WakedupFuture();

Review Comment:
   The purpose setting a WakeupFuture when there isn't any active task is 
because we want the subsequent blocking call the return immediately.  Are you 
wondering if we should maintain this WakeupFuture forever? This is my intend at 
the moment.



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