PDA

View Full Version : [FIXED] Dispatcher fix for concurrent access error add new controller



aconn7
15 Jul 2009, 1:27 PM
Iterating over a "copy" of the controller list should eliminate concurrent access errors that occur when trying to add a controller in the middle of an event being dispatched.

This is the same technique that is used in BaseObservable




private void dispatch(AppEvent event, boolean createhistory) {
MvcEvent e = new MvcEvent(this, event);
e.setAppEvent(event);
if (fireEvent(BeforeDispatch, e)) {
List<Controllers> copy = new ArrayList<Controllers>(controllers);
for (Controller controller : copy) {
if (controller.canHandle(event)) {
if (!controller.initialized) {
controller.initialized = true;
controller.initialize();
}
controller.handleEvent(event);
}
}
fireEvent(AfterDispatch, e);
}
if (createhistory && event.isHistoryEvent()) {
String token = event.getToken();
if (token == null) {
token = "" + new Date().getTime();
}
history.put(token, event);
History.newItem(token, false);
}
}

}

sven
15 Jul 2009, 1:36 PM
Fixed in SVN