svn - r34252 - in branches/2.6.x/modules/library/data: . src/main/java/org/geotools/data/store

1 message Options
Embed this post
Permalink
svn_geotools

svn - r34252 - in branches/2.6.x/modules/library/data: . src/main/java/org/geotools/data/store

Reply Threaded More More options
Print post
Permalink
Author: aaime
Date: 2009-10-26 06:20:26 -0400 (Mon, 26 Oct 2009)
New Revision: 34252

Modified:
   branches/2.6.x/modules/library/data/
   branches/2.6.x/modules/library/data/src/main/java/org/geotools/data/store/ContentFeatureCollection.java
Log:
GEOT-2803, ContentFeatureCollection is leaking listeners


Property changes on: branches/2.6.x/modules/library/data
___________________________________________________________________
Added: svn:mergeinfo
   + /branches/2.5.x/modules/library/main/data:33331
/trunk/modules/library/data:34241,34249

Modified: branches/2.6.x/modules/library/data/src/main/java/org/geotools/data/store/ContentFeatureCollection.java
===================================================================
--- branches/2.6.x/modules/library/data/src/main/java/org/geotools/data/store/ContentFeatureCollection.java 2009-10-26 10:20:19 UTC (rev 34251)
+++ branches/2.6.x/modules/library/data/src/main/java/org/geotools/data/store/ContentFeatureCollection.java 2009-10-26 10:20:26 UTC (rev 34252)
@@ -111,9 +111,6 @@
         this.featureSource = featureSource;
         this.query = query;
         
-        //add the feautre source listener
-        featureSource.addFeatureListener(listener);
-        
         //retype feature type if necessary
         if ( query.getPropertyNames() != Query.ALL_NAMES ) {
             this.featureType =
@@ -151,7 +148,14 @@
      * @param listener The listener to add
      */
     public void addListener(CollectionListener listener) {
-        listeners.add(listener);
+        // create the bridge only if we have collection listeners around
+        synchronized (listeners) {
+            if(listeners.size() == 0) {
+                featureSource.addFeatureListener(this.listener);
+            }
+            
+            listeners.add(listener);
+        }
     }
 
     /**
@@ -160,7 +164,13 @@
      * @param listener The listener to remove
      */
     public void removeListener(CollectionListener listener) {
-        listeners.remove(listener);
+        // as soon as the listeners are out we clean up
+        synchronized (listeners) {
+            listeners.remove(listener);
+        
+            if(listeners.size() == 0)
+                featureSource.removeFeatureListener(this.listener);
+        }
     }
     
     // Iterators


------------------------------------------------------------------------------
Come build with us! The BlackBerry(R) Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference
_______________________________________________
GeoTools-commits mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/geotools-commits