From 5a602c6007df9e46fefc1386fb88dd13f5c56ac3 Mon Sep 17 00:00:00 2001 From: wisberg Date: Sat, 31 May 2003 07:22:44 +0000 Subject: delay until after final last-modified-time stamp on newly-staged files since last-modified-time stamp can be delayed by filesystem buffering. --- util/src/org/aspectj/util/FileUtil.java | 26 +++++++++++++++++++++ util/src/org/aspectj/util/LangUtil.java | 41 ++++++++++++++++++++++++++++++++- 2 files changed, 66 insertions(+), 1 deletion(-) (limited to 'util') diff --git a/util/src/org/aspectj/util/FileUtil.java b/util/src/org/aspectj/util/FileUtil.java index 89ed1fe4a..c9d5fe324 100644 --- a/util/src/org/aspectj/util/FileUtil.java +++ b/util/src/org/aspectj/util/FileUtil.java @@ -1169,6 +1169,31 @@ public class FileUtil { return new BufferedOutputStream(new FileOutputStream(file)); } + /** + * Sleep until after the last last-modified stamp from the files. + * @param files the File[] of files to inspect for last modified times + * (this ignores null or empty files array + * and null or non-existing components of files array) + * @return true if succeeded without 100 interrupts + */ + public static boolean sleepPastFinalModifiedTime(File[] files) { + if ((null == files) || (0 == files.length)) { + return true; + } + long delayUntil = System.currentTimeMillis(); + for (int i = 0; i < files.length; i++) { + File file = files[i]; + if ((null == file) || !file.exists()) { + continue; + } + long nextModTime = file.lastModified(); + if (nextModTime > delayUntil) { + delayUntil = nextModTime; + } + } + return LangUtil.sleepUntil(++delayUntil); + } + /** map name to result, removing any fromSuffix and adding any toSuffix */ private static String map(String name, String fromSuffix, String toSuffix) { if (null != name) { @@ -1386,4 +1411,5 @@ public class FileUtil { protected void completing(long totalWritten, Throwable thrown) { } } + } diff --git a/util/src/org/aspectj/util/LangUtil.java b/util/src/org/aspectj/util/LangUtil.java index 5d8de7f7b..4887fda4e 100644 --- a/util/src/org/aspectj/util/LangUtil.java +++ b/util/src/org/aspectj/util/LangUtil.java @@ -980,6 +980,44 @@ public class LangUtil { } } return result; + } + + /** + * Sleep for a particular period (in milliseconds). + * @param time the long time in milliseconds to sleep + * @return true if delay succeeded, false if interrupted 100 times + */ + public static boolean sleep(long milliseconds) { + if (milliseconds == 0) { + return true; + } else if (milliseconds < 0) { + throw new IllegalArgumentException("negative: " + milliseconds); + } + return sleepUntil(milliseconds + System.currentTimeMillis()); + } + + /** + * Sleep until a particular time. + * @param time the long time in milliseconds to sleep until + * @return true if delay succeeded, false if interrupted 100 times + */ + public static boolean sleepUntil(long time) { + if (time == 0) { + return true; + } else if (time < 0) { + throw new IllegalArgumentException("negative: " + time); + } + final Thread thread = Thread.currentThread(); + long curTime = System.currentTimeMillis(); + for (int i = 0; (i < 100) && (curTime < time); i++) { + try { + thread.sleep(time-curTime); + } catch (InterruptedException e) { + // ignore + } + curTime = System.currentTimeMillis(); + } + return (curTime >= time); } /** @@ -1336,7 +1374,8 @@ public class LangUtil { } } } // class Thrown - } // class ProcessController + } + } -- cgit v1.2.3