Skip to content
Permalink
Browse files
o Used a CompletableFuture instead of a CountdownLatch
o Refer to MINA 2.1.3
  • Loading branch information
elecharny committed Jun 4, 2019
1 parent 6aff0d2 commit a39077a98aa72031bec76d7295677ae7030c2179
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
@@ -39,9 +39,11 @@
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.locks.ReentrantLock;

@@ -247,7 +249,8 @@ public class LdapNetworkConnection extends AbstractLdapConnection implements Lda
/** A future used to block any action until the handshake is completed */
private HandshakeFuture handshakeFuture;

private CountDownLatch closeLatch = new CountDownLatch( 1 );
/** A future used to wait for a connection to be closed */
private CompletableFuture<Integer> connectionCloseFuture = new CompletableFuture<>();

// ~~~~~~~~~~~~~~~~~ common error messages ~~~~~~~~~~~~~~~~~~~~~~~~~~
static final String TIME_OUT_ERROR = I18n.err( I18n.ERR_04170_TIMEOUT_OCCURED );
@@ -776,7 +779,7 @@ private void checkSecured( ConnectFuture connectionFuture ) throws LdapException
}

// Cancel the latch
closeLatch.countDown();
connectionCloseFuture.complete( 0 );

// if there is no cause assume timeout
if ( cause == null )
@@ -932,7 +935,7 @@ public boolean connect() throws LdapException
if ( !connectionFuture.isConnected() )
{
// Release the latch
closeLatch.countDown();
connectionCloseFuture.cancel( true );

close( connectionFuture );
}
@@ -955,7 +958,7 @@ public boolean connect() throws LdapException
// Initialize the MessageId
messageId.set( 0 );

closeLatch = new CountDownLatch( 1 );
connectionCloseFuture = new CompletableFuture<>();

// And return
return true;
@@ -978,10 +981,10 @@ public void close()
{
if ( ( ioSession != null ) && ioSession.isConnected() )
{
closeLatch.await();
connectionCloseFuture.get( timeout, TimeUnit.MILLISECONDS );
}
}
catch ( InterruptedException e )
catch ( TimeoutException | ExecutionException | InterruptedException e )
{
if ( LOG.isDebugEnabled() )
{
@@ -2167,7 +2170,7 @@ public Object run() throws Exception
}
catch ( Exception e )
{
closeLatch.countDown();
connectionCloseFuture.complete( 0 );
throw new LdapException( e );
}
}
@@ -2374,9 +2377,9 @@ public void unBind() throws LdapException

try
{
closeLatch.await();
connectionCloseFuture.get( timeout, TimeUnit.MILLISECONDS );
}
catch ( InterruptedException e )
catch ( TimeoutException | ExecutionException | InterruptedException e )
{
if ( LOG.isDebugEnabled() )
{
@@ -4776,7 +4779,7 @@ public void sessionClosed( IoSession session ) throws Exception
}
}

closeLatch.countDown();
connectionCloseFuture.complete( 0 );
}


@@ -67,7 +67,7 @@
<junit.platform.version>1.4.2</junit.platform.version>
<log4j.version>1.2.17</log4j.version>
<logback.version>1.2.3</logback.version>
<mina.core.version>2.1.2</mina.core.version>
<mina.core.version>2.1.3</mina.core.version>
<org.osgi.core.version>6.0.0</org.osgi.core.version>
<org.apache.felix.version>6.0.2</org.apache.felix.version>
<pax-exam.version>4.13.1</pax-exam.version>

0 comments on commit a39077a

Please sign in to comment.