Added a method to refresh an NFS mount point (necessary to prevent NFS flakiness when running on the LSF farm.

git-svn-id: file:///humgen/gsa-scr1/gsa-engineering/svn_contents/trunk@774 348d0f76-0448-11de-a6fe-93d51630548a
This commit is contained in:
kiran 2009-05-21 19:31:54 +00:00
parent 324ef9cbd1
commit a687c6bc03
1 changed files with 27 additions and 0 deletions

View File

@ -89,4 +89,31 @@ public class PathUtils {
}
}
/**
* Refreshes the volume associated with a given file or directory by attempting to access it
* a few times before giving up. The file need not exist, though the parent directory must.
* This method is particularly useful when your job has been dispatched to LSF and you need to
* ensure an NSF-mounted volume is actually accessible (many times it isn't for a few seconds,
* just enough to cause your program to come crashing down).
*
* @param file the file or directory that resides in the volume to be refreshed.
*/
public static void refreshVolume(File file) {
File dir = file.isDirectory() ? file : file.getParentFile();
int sleepCount = 0;
while (sleepCount < 3 && dir.listFiles() == null) {
try {
Thread.sleep((sleepCount + 1)*3000);
} catch (InterruptedException e) {
}
sleepCount++;
}
if (dir.listFiles() == null) {
throw new StingException("The volume '" + dir.getAbsolutePath() + "' could not be accessed.");
}
}
}