You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by se...@apache.org on 2019/07/09 13:28:43 UTC

[directory-ldap-api] branch master updated: Fix the wait condition, no need to wait when already done or cancelled

This is an automated email from the ASF dual-hosted git repository.

seelmann pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/directory-ldap-api.git


The following commit(s) were added to refs/heads/master by this push:
     new b9c3f3d  Fix the wait condition, no need to wait when already done or cancelled
b9c3f3d is described below

commit b9c3f3d8f8ac7e0955741f77a6ab5018fa263800
Author: Stefan Seelmann <ma...@stefan-seelmann.de>
AuthorDate: Tue Jul 9 15:28:31 2019 +0200

    Fix the wait condition, no need to wait when already done or cancelled
---
 .../ldap/client/api/future/HandshakeFuture.java         | 17 +++++++++++------
 .../ldap/client/api/future/UniqueResponseFuture.java    |  3 ++-
 2 files changed, 13 insertions(+), 7 deletions(-)

diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/HandshakeFuture.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/HandshakeFuture.java
index cf8e869..7f3f379 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/HandshakeFuture.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/HandshakeFuture.java
@@ -56,7 +56,7 @@ public class HandshakeFuture implements Future<Boolean>
     {
         // set the cancel flag first
         cancelled = true;
-        
+
         // Notify the future
         notifyAll();
     }
@@ -68,7 +68,7 @@ public class HandshakeFuture implements Future<Boolean>
     public synchronized void secured()
     {
         done = true;
-        
+
         notifyAll();
     }
 
@@ -104,7 +104,7 @@ public class HandshakeFuture implements Future<Boolean>
         {
             wait();
         }
-        
+
         return done;
     }
 
@@ -113,10 +113,15 @@ public class HandshakeFuture implements Future<Boolean>
      * {@inheritDoc}
      */
     @Override
-    public synchronized Boolean get( long timeout, TimeUnit unit ) throws InterruptedException, ExecutionException, TimeoutException
+    public synchronized Boolean get( long timeout, TimeUnit unit )
+        throws InterruptedException, ExecutionException, TimeoutException
     {
-        wait( unit.toMillis( timeout ) );
-        
+        // no need to wait if already done or cancelled
+        if ( !done && !cancelled )
+        {
+            wait( unit.toMillis( timeout ) );
+        }
+
         return done;
     }
 
diff --git a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/UniqueResponseFuture.java b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/UniqueResponseFuture.java
index d52b88c..a938801 100644
--- a/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/UniqueResponseFuture.java
+++ b/ldap/client/api/src/main/java/org/apache/directory/ldap/client/api/future/UniqueResponseFuture.java
@@ -87,7 +87,8 @@ public abstract class UniqueResponseFuture<R extends Response> implements Respon
     @Override
     public synchronized R get( long timeout, TimeUnit unit ) throws InterruptedException
     {
-        while ( !done && !cancelled )
+        // no need to wait if already done or cancelled
+        if ( !done && !cancelled )
         {
             wait( unit.toMillis( timeout ) );
         }