Bläddra i källkod

delay until after final last-modified-time stamp on newly-staged files

since last-modified-time stamp can be delayed by filesystem buffering.
tags/V1_1_0
wisberg 21 år sedan
förälder
incheckning
5a602c6007
2 ändrade filer med 66 tillägg och 1 borttagningar
  1. 26
    0
      util/src/org/aspectj/util/FileUtil.java
  2. 40
    1
      util/src/org/aspectj/util/LangUtil.java

+ 26
- 0
util/src/org/aspectj/util/FileUtil.java Visa fil

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

}

+ 40
- 1
util/src/org/aspectj/util/LangUtil.java Visa fil

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

}



Laddar…
Avbryt
Spara