Issue #1243 Revert locking in UtilityManager.getFileChecksum to avoid lock timing out until FileLocker can be fixed

Change-Id: I25ab9832d725647c17aea505514334a7c0026ae7

Former-commit-id: 71367ef5bb [formerly a7386c6570455fe6f9175eaeae1225923124cce8]
Former-commit-id: 0daa22064b
This commit is contained in:
Max Schenkelberg 2012-11-16 14:03:18 -06:00
parent 2ce90a79cb
commit 34c4ec44c3
3 changed files with 28 additions and 11 deletions

View file

@ -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();
}
}
}
/**

View file

@ -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;
}

View file

@ -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) {