From 9383d97579804391550ff25448c32661eadaf626 Mon Sep 17 00:00:00 2001 From: Max Schenkelberg Date: Thu, 7 Feb 2013 14:29:35 -0600 Subject: [PATCH] Issue #1590 Change localization notification observer to send notification to listeners after unlocking file to avoid deadlock Change-Id: I2b5ffa08af98259bdd860feb4cd989be013a05be Former-commit-id: 232400965d2bdd322edb293c51016dce39cce69d [formerly 1ebb6aa360c9f916f09a5da95e5d831a021508e1] Former-commit-id: 3f3359370d40536d341a11bc86f9e4ca2c97cf00 --- .../LocalizationNotificationObserver.java | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationNotificationObserver.java b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationNotificationObserver.java index 0ef58e324e..b23a7585a2 100644 --- a/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationNotificationObserver.java +++ b/edexOsgi/com.raytheon.uf.common.localization/src/com/raytheon/uf/common/localization/LocalizationNotificationObserver.java @@ -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 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 getLocalizationFiles(