[Swift-commit] r4467 - in trunk/src/org/griphyn/vdl: karajan mapping
hategan at ci.uchicago.edu
hategan at ci.uchicago.edu
Thu May 12 16:17:42 CDT 2011
Author: hategan
Date: 2011-05-12 16:17:41 -0500 (Thu, 12 May 2011)
New Revision: 4467
Modified:
trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java
trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
Log:
a better (hopefully) implementation of listeners
Modified: trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java 2011-05-12 21:16:03 UTC (rev 4466)
+++ trunk/src/org/griphyn/vdl/karajan/ArrayIndexFutureList.java 2011-05-12 21:17:41 UTC (rev 4467)
@@ -11,7 +11,6 @@
import org.globus.cog.karajan.stack.VariableNotFoundException;
import org.globus.cog.karajan.stack.VariableStack;
-import org.globus.cog.karajan.workflow.ExecutionException;
import org.globus.cog.karajan.workflow.events.EventTargetPair;
import org.globus.cog.karajan.workflow.futures.FutureEvaluationException;
import org.globus.cog.karajan.workflow.futures.FutureIterator;
@@ -19,18 +18,17 @@
import org.globus.cog.karajan.workflow.futures.FutureListener;
import org.globus.cog.karajan.workflow.futures.FutureNotYetAvailable;
import org.globus.cog.karajan.workflow.futures.ListenerStackPair;
-import org.globus.cog.util.CopyOnWriteArrayList;
import org.griphyn.vdl.mapping.DSHandle;
import org.griphyn.vdl.mapping.DSHandleListener;
public class ArrayIndexFutureList implements FutureList, DSHandleListener {
private ArrayList<Object> keys;
- private Map values;
+ private Map<?, ?> values;
private boolean closed;
- private CopyOnWriteArrayList<ListenerStackPair> listeners;
+ private ArrayList<ListenerStackPair> listeners;
private FutureEvaluationException exception;
- public ArrayIndexFutureList(DSHandle handle, Map values) {
+ public ArrayIndexFutureList(DSHandle handle, Map<?, ?> values) {
this.values = values;
keys = new ArrayList<Object>();
handle.addListener(this);
@@ -93,7 +91,7 @@
public synchronized void addModificationAction(FutureListener target,
VariableStack stack) {
if (listeners == null) {
- listeners = new CopyOnWriteArrayList<ListenerStackPair>();
+ listeners = new ArrayList<ListenerStackPair>();
}
listeners.add(new ListenerStackPair(target, stack));
@@ -102,22 +100,20 @@
}
}
- private synchronized void notifyListeners() {
- if (listeners == null) {
- return;
+ private void notifyListeners() {
+ ArrayList<ListenerStackPair> l;
+ synchronized (this) {
+ if (listeners == null) {
+ return;
+ }
+
+ l = listeners;
+ listeners = null;
}
- Iterator<ListenerStackPair> i = listeners.iterator();
- try {
- while (i.hasNext()) {
- ListenerStackPair etp = i.next();
- i.remove();
- etp.listener.futureModified(this, etp.stack);
- }
+ for (ListenerStackPair lsp : l) {
+ lsp.listener.futureModified(this, lsp.stack);
}
- finally {
- listeners.release();
- }
}
public EventTargetPair[] getListenerEvents() {
Modified: trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java
===================================================================
--- trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java 2011-05-12 21:16:03 UTC (rev 4466)
+++ trunk/src/org/griphyn/vdl/karajan/DSHandleFutureWrapper.java 2011-05-12 21:17:41 UTC (rev 4467)
@@ -4,10 +4,10 @@
package org.griphyn.vdl.karajan;
import java.util.LinkedList;
+import java.util.List;
import org.globus.cog.karajan.stack.VariableNotFoundException;
import org.globus.cog.karajan.stack.VariableStack;
-import org.globus.cog.karajan.workflow.events.EventBus;
import org.globus.cog.karajan.workflow.events.EventTargetPair;
import org.globus.cog.karajan.workflow.futures.Future;
import org.globus.cog.karajan.workflow.futures.FutureEvaluationException;
@@ -62,20 +62,21 @@
}
}
- private synchronized void notifyListeners() {
- if (listeners == null) {
- return;
+ private void notifyListeners() {
+ List<ListenerStackPair> l;
+ synchronized(this) {
+ if (listeners == null) {
+ return;
+ }
+
+ l = listeners;
+ listeners = null;
+ }
+
+ for (ListenerStackPair lsp : l) {
+ WaitingThreadsMonitor.removeThread(lsp.stack);
+ lsp.listener.futureModified(DSHandleFutureWrapper.this, lsp.stack);
}
- while (!listeners.isEmpty()) {
- final ListenerStackPair etp = listeners.removeFirst();
- WaitingThreadsMonitor.removeThread(etp.stack);
- EventBus.post(new Runnable() {
- public void run() {
- etp.listener.futureModified(DSHandleFutureWrapper.this, etp.stack);
- }
- });
- }
- listeners = null;
}
public synchronized int listenerCount() {
Modified: trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java
===================================================================
--- trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java 2011-05-12 21:16:03 UTC (rev 4466)
+++ trunk/src/org/griphyn/vdl/mapping/AbstractDataNode.java 2011-05-12 21:17:41 UTC (rev 4467)
@@ -3,23 +3,18 @@
*/
package org.griphyn.vdl.mapping;
-import org.griphyn.vdl.karajan.Loader;
-
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import org.apache.log4j.Logger;
+import org.griphyn.vdl.karajan.Loader;
+import org.griphyn.vdl.karajan.VDL2FutureException;
import org.griphyn.vdl.type.Field;
import org.griphyn.vdl.type.Type;
import org.griphyn.vdl.type.Types;
-
-import org.griphyn.vdl.karajan.VDL2FutureException;
-
import org.griphyn.vdl.util.VDL2Config;
@@ -573,17 +568,25 @@
}
}
- protected synchronized void notifyListeners() {
- if (listeners != null) {
- for (DSHandleListener listener : listeners) {
- if (logger.isDebugEnabled()) {
- logger.debug("Notifying listener \"" + listener
- + "\" about \"" + getIdentifyingString() + "\"");
- }
- listener.handleClosed(this);
+ protected void notifyListeners() {
+ List<DSHandleListener> l;
+
+ synchronized(this) {
+ if (listeners == null) {
+ return;
}
+
+ l = listeners;
listeners = null;
}
+
+ for (DSHandleListener listener : l) {
+ if (logger.isDebugEnabled()) {
+ logger.debug("Notifying listener \"" + listener
+ + "\" about \"" + getIdentifyingString() + "\"");
+ }
+ listener.handleClosed(this);
+ }
}
public String getIdentifier() {
More information about the Swift-commit
mailing list