tisonkun commented on code in PR #464:
URL: https://github.com/apache/curator/pull/464#discussion_r1211779013


##########
curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java:
##########
@@ -694,17 +714,46 @@ <DATA_TYPE> void 
processBackgroundOperation(OperationAndData<DATA_TYPE> operatio
         }
     }
 
+    private void closeOperation(OperationAndData<?> operation) {
+        if (operation.getCallback() == null) {
+            return;
+        }
+        CuratorEvent event = new CuratorEventImpl(this, 
CuratorEventType.CLOSING, KeeperException.Code.SESSIONEXPIRED.intValue(), null, 
null, operation.getContext(), null, null, null, null, null, null);
+        sendToBackgroundCallback(operation, event);
+    }
+
+    private void requeueSleepOperation(OperationAndData<?> operationAndData) {
+        operationAndData.clearSleep();
+        synchronized (closeLock)
+        {
+            if (getState() == CuratorFrameworkState.STARTED)
+            {
+                if (backgroundOperations.remove(operationAndData))
+                {
+                    // due to the internals of DelayQueue, operation must be 
removed/re-added so that re-sorting occurs
+                    backgroundOperations.offer(operationAndData);
+                }   // This operation has been taken over by background thread.
+                return;
+            }
+        }
+        closeOperation(operationAndData);
+    }
+
     /**
      * @param operationAndData operation entry
      * @return true if the operation was actually queued, false if not
      */
     <DATA_TYPE> boolean queueOperation(OperationAndData<DATA_TYPE> 
operationAndData)
     {
-        if ( getState() == CuratorFrameworkState.STARTED )
+        synchronized (closeLock)
         {
-            backgroundOperations.offer(operationAndData);
-            return true;
+            if (getState() == CuratorFrameworkState.STARTED)

Review Comment:
   ```suggestion
               if (isStarted())
   ```
   
   nit - a bit bikeshedding



##########
curator-framework/src/main/java/org/apache/curator/framework/imps/CuratorFrameworkImpl.java:
##########
@@ -430,6 +448,8 @@ public void close()
             {
                 ensembleTracker.close();
             }
+            backgroundOperations.forEach(this::closeOperation);
+            backgroundOperations.clear();

Review Comment:
   Perhaps following these line 
https://github.com/apache/curator/pull/464/files#diff-1c44d20ca65904e08924d5b0fbc2e3e34d2a043f71f14aa1386e9f45a95ada52R1105-R1107
   
   ... to drain the queue first and then process ops one by one. I guess 
BlockingQueue.foreach is somehow a smell.



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