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


##########
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:
   Hey Jun - For the blocking calls (syncCommit for example), the future should 
have been cleared in the finally block. I didn't implement wakeup for the poll 
method because it is not yet ready at the state of the current trunk.  (I'm not 
sure if i'm answering your question)
   
   Basically - the wakeup future should be cleared in the finally blocks for 
the blocking APIs, see commitSync. Poll API is still incomplete so I didn't 
clear the future there.



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