Issue #1590 Change localization notification observer to send notification to listeners after unlocking file to avoid deadlock

Change-Id: I2b5ffa08af98259bdd860feb4cd989be013a05be

Former-commit-id: 232400965d [formerly 1ebb6aa360c9f916f09a5da95e5d831a021508e1]
Former-commit-id: 3f3359370d
This commit is contained in:
Max Schenkelberg 2013-02-07 14:29:35 -06:00
parent 276b302002
commit 9383d97579

View file

@ -200,6 +200,7 @@ public class LocalizationNotificationObserver {
if (file.getContext().equals(fum.getContext())) {
// exact match found, skip old updates (in case we have changed
// the file since this update)
boolean notify = false;
try {
FileLocker.lock(this, file.file, Type.WRITE);
Date fileTS = file.getTimeStamp();
@ -209,11 +210,15 @@ public class LocalizationNotificationObserver {
return;
} else {
// Proceed with update process
processUpdate(fum, file);
notify = processUpdate(fum, file);
break;
}
} finally {
FileLocker.unlock(this, file.file);
if (notify) {
// Notify after unlocking file to avoid dead locks
file.notifyObservers(fum);
}
}
}
}
@ -234,7 +239,9 @@ public class LocalizationNotificationObserver {
// Process other file, skipping context match that was processed above
for (LocalizationFile file : potentialFiles) {
if (file.getContext().equals(fum.getContext()) == false) {
processUpdate(fum, file);
if (processUpdate(fum, file)) {
file.notifyObservers(fum);
}
}
}
@ -253,7 +260,9 @@ public class LocalizationNotificationObserver {
Collection<LocalizationFile> files = getLocalizationFiles(type,
subpath);
for (LocalizationFile file : files) {
processUpdate(fum, file);
if (processUpdate(fum, file)) {
file.notifyObservers(fum);
}
}
}
@ -265,15 +274,15 @@ public class LocalizationNotificationObserver {
}
}
private void processUpdate(FileUpdatedMessage fum, LocalizationFile file) {
private boolean processUpdate(FileUpdatedMessage fum, LocalizationFile file) {
LocalizationContext context = fum.getContext();
LocalizationLevel level = context.getLocalizationLevel();
LocalizationType type = context.getLocalizationType();
String contextName = context.getContextName();
boolean notify = false;
int compVal = file.getContext().getLocalizationLevel().compareTo(level);
if (compVal <= 0) {
boolean notify = false;
if (compVal < 0) {
// Different level, check our context name to
// make sure it matches update message
@ -309,12 +318,8 @@ public class LocalizationNotificationObserver {
}
}
}
if (notify) {
// Notify file of change
file.notifyObservers(fum);
}
}
return notify;
}
private Collection<LocalizationFile> getLocalizationFiles(