directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kayyag...@apache.org
Subject svn commit: r944610 - in /directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api: ConnectionClosedEventListener.java LdapNetworkConnection.java
Date Sat, 15 May 2010 10:46:37 GMT
Author: kayyagari
Date: Sat May 15 10:46:37 2010
New Revision: 944610

URL: http://svn.apache.org/viewvc?rev=944610&view=rev
Log:
o added a new interface to handle the connection closed event raised due to any network issues
o implemented support for notifying registered ConnectionClosedEventListenerS when the session
gets closed 

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

Added: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/ConnectionClosedEventListener.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/ConnectionClosedEventListener.java?rev=944610&view=auto
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/ConnectionClosedEventListener.java
(added)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/ConnectionClosedEventListener.java
Sat May 15 10:46:37 2010
@@ -0,0 +1,36 @@
+/*
+ *   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.directory.ldap.client.api;
+
+/**
+ * A listener class intended for notifying the classes using LdapNetworkConnection
+ * in the event of any network failure
+ *
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public interface ConnectionClosedEventListener
+{
+    /**
+     * called when the LdapNetworkConnection is unable to reach the server it is connected
to
+     */
+    void connectionClosed();
+}

Modified: directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
URL: http://svn.apache.org/viewvc/directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java?rev=944610&r1=944609&r2=944610&view=diff
==============================================================================
--- directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
(original)
+++ directory/clients/ldap/trunk/ldap-client-api/src/main/java/org/apache/directory/ldap/client/api/LdapNetworkConnection.java
Sat May 15 10:46:37 2010
@@ -211,12 +211,15 @@ public class LdapNetworkConnection exten
     
     /** A flag indicating that the connection is connected or not */
     private AtomicBoolean connected = new AtomicBoolean( false );
+
+    /** a list of listeners interested in getting notified when the
+     *  connection's session gets closed cause of network issues
+     */
+    private List<ConnectionClosedEventListener> conCloseListeners;
     
     /** the schema manager */
     private SchemaManager schemaManager;
 
-    /** flag to make the the connection schema aware */
-    private boolean enableSchema;
     // ~~~~~~~~~~~~~~~~~ common error messages ~~~~~~~~~~~~~~~~~~~~~~~~~~
 
     private static final String OPERATION_CANCELLED = "Operation would have been cancelled";
@@ -3202,4 +3205,40 @@ public class LdapNetworkConnection exten
     {
         return futureMap.get( messageId ) != null;
     }
+    
+    
+    public void addConnectionClosedEventListener( ConnectionClosedEventListener ccListenr
)
+    {
+        if( conCloseListeners == null )
+        {
+            conCloseListeners = new ArrayList<ConnectionClosedEventListener>();
+        }
+        
+        conCloseListeners.add( ccListenr );
+    }
+
+
+    @Override
+    public void sessionClosed( IoSession session ) throws Exception
+    {
+        ldapSession.close( true );
+        connected.set( false );
+        // Reset the messageId
+        messageId.set( 0 );
+        
+        // DO NOT call connector.dispose(), it is hanging when there is no network connection
+        connector = null;
+        
+        clearMaps();
+        
+        if( conCloseListeners != null )
+        {
+            LOG.debug( "notifying the registered ConnectionClosedEventListeners.." );
+            for( ConnectionClosedEventListener listener : conCloseListeners )
+            {
+                listener.connectionClosed();
+            }
+        }
+    }
+    
 }



Mime
View raw message