Merge "Issue #1243 Revert locking in UtilityManager.getFileChecksum to avoid lock timing out until FileLocker can be fixed" into development
Former-commit-id:63cdc32988
[formerly264dc4bc43
[formerly0d16c0c0df
] [formerly63cdc32988
[formerly 4dac2ba9a01b36885188f93fdaf974099cbc9d0c]]] Former-commit-id:264dc4bc43
[formerly0d16c0c0df
] Former-commit-id:264dc4bc43
Former-commit-id:972bbe5676
This commit is contained in:
commit
63fde80d24
3 changed files with 28 additions and 11 deletions
|
@ -1756,10 +1756,15 @@ public class PointsDataManager implements ILocalizationFileObserver {
|
|||
*/
|
||||
private Point unmarshalPointFromXmlFile(LocalizationFile lFile)
|
||||
throws LocalizationException, IOException {
|
||||
InputStream stream = lFile.openInputStream();
|
||||
Point point = JAXB.unmarshal(stream, Point.class);
|
||||
stream.close();
|
||||
return point;
|
||||
InputStream stream = null;
|
||||
try {
|
||||
stream = lFile.openInputStream();
|
||||
return JAXB.unmarshal(stream, Point.class);
|
||||
} finally {
|
||||
if (stream != null) {
|
||||
stream.close();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -34,8 +34,6 @@ import org.apache.commons.logging.LogFactory;
|
|||
|
||||
import com.raytheon.edex.utility.ProtectedFiles;
|
||||
import com.raytheon.uf.common.localization.Checksum;
|
||||
import com.raytheon.uf.common.localization.FileLocker;
|
||||
import com.raytheon.uf.common.localization.FileLocker.Type;
|
||||
import com.raytheon.uf.common.localization.FileUpdatedMessage;
|
||||
import com.raytheon.uf.common.localization.FileUpdatedMessage.FileChangeType;
|
||||
import com.raytheon.uf.common.localization.LocalizationContext;
|
||||
|
@ -123,12 +121,13 @@ public class UtilityManager {
|
|||
* @throws EdexException
|
||||
*/
|
||||
private static String getFileChecksum(File file) throws EdexException {
|
||||
FileLocker.lock(UtilityManager.class, file, Type.WRITE);
|
||||
// TODO: Fix FileLocker so it never times out in test driver
|
||||
File checksumFile = getChecksumFile(file);
|
||||
String chksum = null;
|
||||
try {
|
||||
if (checksumFile.exists()
|
||||
&& checksumFile.lastModified() >= file.lastModified()) {
|
||||
|
||||
BufferedReader reader = new BufferedReader(new FileReader(
|
||||
checksumFile));
|
||||
try {
|
||||
|
@ -144,8 +143,6 @@ public class UtilityManager {
|
|||
} catch (Exception e) {
|
||||
// log, no checksum will be provided
|
||||
logger.error("Error determing file checksum for: " + file, e);
|
||||
} finally {
|
||||
FileLocker.unlock(UtilityManager.class, file);
|
||||
}
|
||||
return chksum;
|
||||
}
|
||||
|
|
|
@ -78,6 +78,8 @@ public class FileLocker {
|
|||
READ, WRITE
|
||||
}
|
||||
|
||||
private static final int MAX_WAIT = 30 * 1000;
|
||||
|
||||
/** Map of waiters on threads */
|
||||
private Map<File, Deque<LockWaiter>> waiters = new HashMap<File, Deque<LockWaiter>>();
|
||||
|
||||
|
@ -215,7 +217,7 @@ public class FileLocker {
|
|||
while (true) {
|
||||
// Sleep
|
||||
try {
|
||||
Thread.sleep(1);
|
||||
Thread.sleep(10);
|
||||
} catch (InterruptedException e) {
|
||||
// Ignore
|
||||
}
|
||||
|
@ -231,6 +233,20 @@ public class FileLocker {
|
|||
false);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
synchronized (lock) {
|
||||
if (lock.lockFile.exists() == false
|
||||
|| (System.currentTimeMillis()
|
||||
- lock.lockFile.lastModified() > MAX_WAIT)) {
|
||||
System.err
|
||||
.println("Releasing lock since: "
|
||||
+ (lock.lockFile.exists() ? "Lock has been allocated for more than "
|
||||
+ (MAX_WAIT / 1000)
|
||||
+ "s"
|
||||
: "Lock file no longer exists!"));
|
||||
locks.remove(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -317,7 +333,6 @@ public class FileLocker {
|
|||
File lockFile = new File(parentDir, "." + file.getName() + "_LOCK");
|
||||
boolean gotLock = lockFile.createNewFile();
|
||||
if (!gotLock) {
|
||||
long MAX_WAIT = 30 * 1000;
|
||||
long waitInterval = 500;
|
||||
long tryCount = MAX_WAIT / waitInterval;
|
||||
for (int i = 0; !gotLock && i < tryCount; ++i) {
|
||||
|
|
Loading…
Add table
Reference in a new issue