Author: b00__1
Date: 2007-07-23 21:10:51-0700
New Revision: 13124
Modified:
branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java
Log:
Synchronized propertyChange() and fixed a register/unregister threading issue when an event triggers register/unregister actions that change the current list of listeners (that also need to be notified).
Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java?view=diff&rev=13124&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java&r1=13123&r2=13124
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java (original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/ModelEventPumpEUMLImpl.java 2007-07-23 21:10:51-0700
@@ -36,6 +36,7 @@
import java.util.Map;
import java.util.Set;
+import org.apache.log4j.Logger;
import org.argouml.model.AbstractModelEventPump;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
@@ -109,6 +110,8 @@
private Object mutex;
+ private Logger LOG = Logger.getLogger(ModelEventPumpEUMLImpl.class);
+
/**
* Constructor.
*
@@ -161,8 +164,10 @@
}
synchronized (mutex) {
List<Listener> list = register.get(notifier);
+ boolean new_ = false;
boolean found = false;
if (list == null) {
+ new_ = true;
list = new ArrayList<Listener>();
} else {
for (Listener l : list) {
@@ -176,7 +181,7 @@
}
}
}
- if (!found) {
+ if (new_ || !found) {
list.add(new Listener(listener, propertyNames));
register.put(notifier, list);
}
@@ -243,24 +248,47 @@
*/
@SuppressWarnings("unchecked")
public void notifyChanged(Notification notification) {
- Object notifier = notification.getNotifier();
- List<Listener> list = registerForElements.get(notifier);
- if (list != null) {
- for (Listener l : list) {
- fireNotification(notification, l);
- }
+ if (notification.getEventType() == Notification.REMOVING_ADAPTER) {
+ return;
+ }
+ Object source = null;
+ switch (notification.getEventType()) {
+ case Notification.REMOVE:
+ source = notification.getOldValue();
+ break;
+ default:
+ source = notification.getNotifier();
}
- for (Object o : registerForClasses.keySet()) {
- if (o instanceof Class) {
- Class type = (Class) o;
- if (type.isAssignableFrom(notifier.getClass())) {
- for (Listener l : registerForClasses.get(o)) {
- fireNotification(notification, l);
+ List<Listener> listeners = new ArrayList<Listener>();
+ synchronized (mutex) {
+ List<Listener> list = registerForElements.get(source);
+ if (list != null) {
+ for (Listener l : list) {
+ listeners.add(l);
+ }
+ }
+
+ boolean logged = false;
+ for (Object o : registerForClasses.keySet()) {
+ if (o instanceof Class) {
+ Class type = (Class) o;
+ if (type.isAssignableFrom(source.getClass())) {
+ if (!logged) {
+ LOG.debug("eUML is firing " + notification); //$NON-NLS-1$
+ logged = true;
+ }
+ for (Listener l : registerForClasses.get(o)) {
+ listeners.add(l);
+ }
}
}
}
}
+
+ for (Listener l : listeners) {
+ fireNotification(notification, l);
+ }
}
private void fireNotification(Notification n, Listener l) {
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.