From a687c6bc0362547b9dc00addb531726ffbc364cd Mon Sep 17 00:00:00 2001 From: kiran Date: Thu, 21 May 2009 19:31:54 +0000 Subject: [PATCH] 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 --- .../broadinstitute/sting/utils/PathUtils.java | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/java/src/org/broadinstitute/sting/utils/PathUtils.java b/java/src/org/broadinstitute/sting/utils/PathUtils.java index e046b8bfe..d4cd26c7f 100755 --- a/java/src/org/broadinstitute/sting/utils/PathUtils.java +++ b/java/src/org/broadinstitute/sting/utils/PathUtils.java @@ -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."); + } + } + }