aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ross2011-11-15 09:36:07 (EST)
committerJohn Ross2011-11-15 11:35:51 (EST)
commitb10ce329e05fabc0348417bb7979200249f2ccb1 (patch)
tree1810f8b9f59257c64523ece619d340a362a61fc0
parent7f0b6beff3476b0726d498638b488bebf1d09f04 (diff)
downloadrt.equinox.bundles-b10ce329e05fabc0348417bb7979200249f2ccb1.zip
rt.equinox.bundles-b10ce329e05fabc0348417bb7979200249f2ccb1.tar.gz
rt.equinox.bundles-b10ce329e05fabc0348417bb7979200249f2ccb1.tar.bz2
Bug 363819: Coordinator.join will now keep track of the elapsed time for specified wait times greater than zero. It will also now validate thev20111115-1635
specified wait time parameter.
-rw-r--r--bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinationImpl.java24
-rw-r--r--bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/Messages.java2
-rw-r--r--bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/messages.properties2
3 files changed, 19 insertions, 9 deletions
diff --git a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinationImpl.java b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinationImpl.java
index cfa5888..3325ae6 100644
--- a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinationImpl.java
+++ b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/CoordinationImpl.java
@@ -304,17 +304,27 @@ public class CoordinationImpl {
return terminated;
}
- public void join(long timeInMillis) throws InterruptedException {
+ public void join(final long timeInMillis) throws InterruptedException {
coordinator.checkPermission(CoordinationPermission.PARTICIPATE, name);
+ validateTimeout(timeInMillis);
+ // How much system time has elapsed across all waits.
+ long elapsed = 0;
+ // The system time at the start of the wait.
long start = System.currentTimeMillis();
// Wait until this coordination has terminated. Guard against spurious
- // wakeups using isTerminated().
+ // wakeups using the termination status.
synchronized (this) {
while (!terminated) {
- wait(timeInMillis);
- long elapsed = System.currentTimeMillis() - start;
- if (elapsed > timeInMillis)
- break;
+ // Wait for the desired amount of time minus any time that has already elapsed.
+ wait(timeInMillis - elapsed);
+ // Only track elapsed time if a definite interval was specified.
+ if (timeInMillis != 0) {
+ // Update the elapsed time.
+ elapsed = System.currentTimeMillis() - start;
+ // If the allotted wait time has fully expired, we're done.
+ if (elapsed >= timeInMillis) // Don't allow a wait of zero here!
+ break;
+ }
}
}
}
@@ -398,6 +408,6 @@ public class CoordinationImpl {
private static void validateTimeout(long timeout) {
if (timeout < 0)
- throw new IllegalArgumentException(Messages.InvalidTimeout);
+ throw new IllegalArgumentException(Messages.InvalidTimeInterval);
}
}
diff --git a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/Messages.java b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/Messages.java
index 57b96c6..5070fb3 100644
--- a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/Messages.java
+++ b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/Messages.java
@@ -18,7 +18,7 @@ public class Messages extends NLS {
public static String Deadlock;
public static String InvalidCoordinationName;
public static String MissingFailureCause;
- public static String InvalidTimeout;
+ public static String InvalidTimeInterval;
public static String InterruptedTimeoutExtension;
public static String EndingThreadNotSame;
public static String LockInterrupted;
diff --git a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/messages.properties b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/messages.properties
index a4ca732..95b09c2 100644
--- a/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/messages.properties
+++ b/bundles/org.eclipse.equinox.coordinator/src/org/eclipse/equinox/coordinator/messages.properties
@@ -12,7 +12,7 @@ NullParameter=Parameter must not be null: {0}
Deadlock=Deadlock detected
InvalidCoordinationName=The coordination name does not match the Bundle Symbolic Name pattern
MissingFailureCause=A reason must be specified when failing a coordination
-InvalidTimeout=A timeout must be a non-negative integer
+InvalidTimeInterval=A time interval must be a non-negative integer
InterruptedTimeoutExtension=The timeout could not be extended because the previous one had already expired. The current thread was interrupted before it was possible to determine how this coordination terminated.
EndingThreadNotSame=Coordinations may only be ended by the same thread that pushed them onto the thread local stack
LockInterrupted=The lock was interrupted