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

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

View file

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