Merge "Issue #1590 Change localization notification observer to send notification to listeners after unlocking file to avoid deadlock" into development

Former-commit-id: ef0194872a [formerly ef0194872a [formerly 6eefd1de088b4b3e334a3c587c371a4028ee09dd]]
Former-commit-id: 1cf73c4426
Former-commit-id: 69ebf80213
This commit is contained in:
Nate Jensen 2013-02-11 09:48:42 -06:00 committed by Gerrit Code Review
commit f8734bbe6a

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(