directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From akaras...@apache.org
Subject svn commit: rev 20556 - incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile
Date Fri, 28 May 2004 22:31:04 GMT
Author: akarasulu
Date: Fri May 28 15:31:02 2004
New Revision: 20556

Modified:
   incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
Log:
Made the JeProfileRoleLinkDAO an Observer of JeIterator changes to cleanup
after them properly.  Still need to add cleanup code though.


Modified: incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
==============================================================================
--- incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
(original)
+++ incubator/directory/rms/trunk/je/src/java/org/apache/rms/je/profile/JeProfileRoleLinkDAO.java
Fri May 28 15:31:02 2004
@@ -29,8 +29,7 @@
 
 import org.apache.commons.lang.Validate ;
 
-import java.util.List ;
-import java.util.Iterator ;
+import java.util.*;
 
 import java.io.IOException ;
 import java.io.UnsupportedEncodingException ;
@@ -44,7 +43,7 @@
  * @author <a href="mailto:directory-dev@incubator.apache.org">Apache Directory Project</a>
  * @version $Rev$
  */
-public class JeProfileRoleLinkDAO implements ProfileRoleLinkDAO
+public class JeProfileRoleLinkDAO implements ProfileRoleLinkDAO, Observer
 {
     /** the name of secondary db used to associate links with an appName */
     public static final String APPNAME_SECDB  = "roleLinkByAppName" ;
@@ -71,6 +70,9 @@
     /** callback used to for monitoring noteable events */
     private ProfileRoleLinkDAOMonitor monitor = null ;
 
+    /** set of open iterators created by this DAO */
+    private HashSet openIterators = new HashSet() ;
+
 
     // -----------------------------------------------------------------------
     // C O N S T R U C T O R S
@@ -584,6 +586,8 @@
 
             JeIterator iterator = new JeIterator( cursor, secCursors,
                     JeProfileRoleLinkBinding.ROLENAME_BINDING, true ) ;
+            iterator.addObserver( this ) ;
+            openIterators.add( iterator ) ;
             monitor.listingRoleNames( this, appName, userName, iterator ) ;
             iterator.setMonitor( LIST_MONITOR ) ;
             return iterator ;
@@ -686,6 +690,8 @@
             cursor = db.join( secCursors, null ) ;
             JeIterator iterator = new JeIterator( cursor, secCursors,
                     JeProfileRoleLinkBinding.USERNAME_BINDING, true ) ;
+            iterator.addObserver( this ) ;
+            openIterators.add( iterator ) ;
             monitor.listingUserNames( this, appName, roleName, iterator ) ;
             iterator.setMonitor( LIST_MONITOR ) ;
             return iterator ;
@@ -907,5 +913,29 @@
     public void setMonitor( ProfileRoleLinkDAOMonitor monitor )
     {
         this.monitor = monitor ;
+    }
+
+
+    // -----------------------------------------------------------------------
+    // Observer Implemenation
+    // -----------------------------------------------------------------------
+
+
+    /**
+     * All JeIterators created by this DAO are tracked to make sure they are
+     * cleaned up properly.  The Observer pattern helps it keep track of open
+     * and closed JeIterators by notifying this DAO when the iterator is
+     * closed.  When these cursors close they can be removed from the list of
+     * open iterators.
+     *
+     * @param o the Observable object
+     * @param arg an argument associated with the object
+     */
+    public void update( Observable o, Object arg )
+    {
+        if ( o instanceof JeIterator )
+        {
+            openIterators.remove( o ) ;
+        }
     }
 }

Mime
View raw message