Don't wrap the InterruptedException without unwrapping
@@ -32,6 +32,7 @@ import java.util.Iterator;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArraySet;
import javax.annotation.Nonnull;
+import jenkins.security.NotReallyRoleSensitiveCallable;
/**
* Controls mutual exclusion of {@link ResourceList}.
@@ -77,20 +78,18 @@ public class ResourceController {
*/
public void execute(@Nonnull Runnable task, final ResourceActivity activity ) throws InterruptedException {
final ResourceList resources = activity.getResourceList();
- _withLock(new Runnable() {
+ _withLock(new NotReallyRoleSensitiveCallable<Void,InterruptedException>() {
@Override
- public void run() {
- while(inUse.isCollidingWith(resources))
- try {
+ public Void call() throws InterruptedException {
+ while (inUse.isCollidingWith(resources)) {
// TODO revalidate the resource list after re-acquiring lock, for now we just let the build fail
_await();
- } catch (InterruptedException e) {
- throw new RuntimeException(e);
}
// we have a go
inProgress.add(activity);
inUse = ResourceList.union(inUse, resources);
+ return null;
}
});
@@ -184,5 +183,11 @@ public class ResourceController {
return callable.call();
}
}
+
+ protected <V, T extends Throwable> V _withLock(hudson.remoting.Callable<V,T> callable) throws T {
+ synchronized (this) {
+ return callable.call();
+ }
+ }
}
