[Swift-commit] r3486 - trunk/src/org/griphyn/vdl/karajan

noreply at svn.ci.uchicago.edu noreply at svn.ci.uchicago.edu
Wed Jul 28 14:41:08 CDT 2010


Author: hategan
Date: 2010-07-28 14:41:08 -0500 (Wed, 28 Jul 2010)
New Revision: 3486

Modified:
   trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
Log:
a cow list is better here

Modified: trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java	2010-07-28 19:36:27 UTC (rev 3485)
+++ trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java	2010-07-28 19:41:08 UTC (rev 3486)
@@ -5,8 +5,7 @@
 
 import java.util.ArrayList;
 import java.util.HashSet;
-import java.util.LinkedList;
-import java.util.List;
+import java.util.Iterator;
 import java.util.Map;
 import java.util.Set;
 
@@ -20,6 +19,7 @@
 import org.globus.cog.karajan.workflow.futures.FutureIterator;
 import org.globus.cog.karajan.workflow.futures.FutureList;
 import org.globus.cog.karajan.workflow.futures.FutureNotYetAvailable;
+import org.globus.cog.util.CopyOnWriteArrayList;
 import org.griphyn.vdl.mapping.DSHandle;
 import org.griphyn.vdl.mapping.DSHandleListener;
 
@@ -27,7 +27,7 @@
     private ArrayList<Object> keys;
     private Map values;
     private boolean closed;
-    private List<EventTargetPair> listeners;
+    private CopyOnWriteArrayList<EventTargetPair> listeners;
     private FutureEvaluationException exception;
 
     public ArrayIndexFutureList(DSHandle handle, Map values) {
@@ -82,7 +82,7 @@
         notifyListeners();
     }
 
-    public boolean isClosed() {
+    public synchronized boolean isClosed() {
         return closed;
     }
 
@@ -93,7 +93,7 @@
     public synchronized void addModificationAction(EventListener target,
             Event event) {
         if (listeners == null) {
-            listeners = new LinkedList<EventTargetPair>();
+            listeners = new CopyOnWriteArrayList<EventTargetPair>();
         }
 
         listeners.add(new EventTargetPair(event, target));
@@ -107,15 +107,22 @@
             return;
         }
 
-        for (EventTargetPair etp : listeners) {
-            try {
-                etp.getTarget().event(etp.getEvent());
+        Iterator<EventTargetPair> i = listeners.iterator();
+        try {
+            while (i.hasNext()) {
+                try {
+                    EventTargetPair etp = i.next();
+                    i.remove();
+                    etp.getTarget().event(etp.getEvent());
+                }
+                catch (ExecutionException e) {
+                    e.printStackTrace();
+                }
             }
-            catch (ExecutionException e) {
-                e.printStackTrace();
-            }
         }
-        listeners = null;
+        finally {
+            listeners.release();
+        }
     }
 
     public EventTargetPair[] getListenerEvents() {




More information about the Swift-commit mailing list