directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From elecha...@apache.org
Subject svn commit: r916978 - /directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
Date Sat, 27 Feb 2010 15:57:48 GMT
Author: elecharny
Date: Sat Feb 27 15:57:48 2010
New Revision: 916978

URL: http://svn.apache.org/viewvc?rev=916978&view=rev
Log:
o Added some debug LOG
o Removed a call to UnbindFuture.await() as it locks randomly due to some race condition in
MINA
o Using AtomicBoolean to manage the authenticated and connected states

Modified:
    directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java?rev=916978&r1=916977&r2=916978&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
(original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapConnection.java
Sat Feb 27 15:57:48 2010
@@ -32,9 +32,9 @@
 import java.util.Set;
 import java.util.concurrent.BlockingQueue;
 import java.util.concurrent.ConcurrentHashMap;
-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.atomic.AtomicInteger;
 
 import javax.naming.InvalidNameException;
@@ -204,7 +204,10 @@
     private Entry rootDSE;
     
     /** A flag indicating that the BindRequest has been issued and successfully authenticated
the user */
-    private boolean authenticated = false;
+    private AtomicBoolean authenticated = new AtomicBoolean( false );
+    
+    /** A flag indicating that the connection is connected or not */
+    private AtomicBoolean connected = new AtomicBoolean( false );
     
     /** the schema manager */
     private SchemaManager schemaManager;
@@ -228,7 +231,7 @@
      */
     public boolean isConnected()
     {
-        return ( ldapSession != null ) && ldapSession.isConnected();
+        return ( ldapSession != null ) && connected.get();
     }
 
 
@@ -239,7 +242,7 @@
      */
     public boolean isAuthenticated()
     {
-        return isConnected() && authenticated;
+        return isConnected() && authenticated.get();
     }
 
 
@@ -256,7 +259,7 @@
             throw new InvalidConnectionException( "Cannot connect on the server, the connection
is null" );
         }
 
-        if ( !isConnected() )
+        if ( !connected.get() )
         {
             throw new InvalidConnectionException( "Cannot connect on the server, the connection
is invalid" );
         }
@@ -265,7 +268,7 @@
     
     private void addToFutureMap( int messageId, ResponseFuture<? extends Response>
future )
     {
-        //System.out.println( "Adding <" + messageId + ", " + future.getClass().getName()
+ ">" );
+        LOG.debug( "Adding <" + messageId + ", " + future.getClass().getName() + ">"
);
         futureMap.put( messageId, future );
     }
     
@@ -276,7 +279,7 @@
         
         if ( future != null )
         {
-            //System.out.println( "Removing <" + messageId + ", " + future.getClass().getName()
+ ">" );
+            LOG.debug( "Removing <" + messageId + ", " + future.getClass().getName() +
">" );
         }
         
         return future;
@@ -286,7 +289,7 @@
     private ResponseFuture<? extends Response> peekFromFutureMap( int messageId )
     {
         ResponseFuture<? extends Response> future = futureMap.get( messageId );
-        //System.out.println( "Getting <" + messageId + ", " + future.getClass().getName()
+ ">" );
+        LOG.debug( "Getting <" + messageId + ", " + future.getClass().getName() + ">"
);
         
         return future;
     }
@@ -587,7 +590,7 @@
      */
     public boolean connect() throws LdapException, IOException
     {
-        if ( ( ldapSession != null ) && ldapSession.isConnected() )
+        if ( ( ldapSession != null ) && connected.get() )
         {
             // No need to connect if we already have a connected session
             return true;
@@ -658,6 +661,7 @@
 
         // Get back the session
         ldapSession = connectionFuture.getSession();
+        connected.set( true );
 
         // And inject the current Ldap container into the session
         IAsn1Container ldapMessageContainer = new LdapMessageContainer();
@@ -679,9 +683,10 @@
     public boolean close() throws IOException
     {
         // Close the session
-        if ( ( ldapSession != null ) && ldapSession.isConnected() )
+        if ( ( ldapSession != null ) && connected.get() )
         {
             ldapSession.close( true );
+            connected.set( false );
         }
 
         // And close the connector if it has been created locally
@@ -1113,7 +1118,7 @@
             
             if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
             {
-                authenticated = true;
+                authenticated.set( true );
 
                 // Everything is fine, return the response
                 LOG.debug( "Bind successful : {}", bindResponse );
@@ -1311,7 +1316,7 @@
     public BindFuture bindAsync( BindRequest bindRequest ) throws LdapException, IOException
     {
         // First switch to anonymous state
-        authenticated = false;
+        authenticated.set( false );
         
         // try to connect, if we aren't already connected.
         connect();
@@ -1560,18 +1565,24 @@
         // Send the request to the server
         WriteFuture unbindFuture = ldapSession.write( unbindRequest );
 
-        unbindFuture.awaitUninterruptibly();
+        //LOG.debug( "waiting for unbindFuture" );
+        //unbindFuture.awaitUninterruptibly();
+        //LOG.debug( "unbindFuture done" );
         
-        authenticated = false;
+        authenticated.set( false );
 
         // clear the mappings
         clearMaps();
         
         //  We now have to close the session
-        if ( ( ldapSession != null ) && ldapSession.isConnected() )
+        if ( ( ldapSession != null ) && connected.get() )
         {
             CloseFuture closeFuture = ldapSession.close( true );
+
+            LOG.debug( "waiting for closeFuture" );
             closeFuture.awaitUninterruptibly();
+            LOG.debug( "closeFuture done" );
+            connected.set( false );
         }
 
         // And get out
@@ -1685,7 +1696,7 @@
                 // remove the listener from the listener map
                 if ( bindResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS
)
                 {
-                    authenticated = true;
+                    authenticated.set( true );
 
                     // Everything is fine, return the response
                     LOG.debug( "Bind successful : {}", bindResponse );



Mime
View raw message