提交 93e366ae 编写于 作者: K kohsuke

Future used in Queue can now cancel the task

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@18939 71c3de6d-444a-0410-be80-ed276b4c234a
上级 cf439c5b
......@@ -36,8 +36,6 @@ import javax.servlet.ServletException;
import java.io.IOException;
import java.util.logging.Logger;
import java.util.logging.Level;
import java.util.concurrent.TimeUnit;
import java.util.GregorianCalendar;
/**
......@@ -112,6 +110,7 @@ public class Executor extends Thread implements ModelObject {
startTime = System.currentTimeMillis();
executable = task.createExecutable();
queueItem.future.startExecuting(this);
if (executable instanceof Actionable) {
for (Action action: queueItem.getActions()) {
((Actionable) executable).addAction(action);
......
......@@ -974,6 +974,35 @@ public class Queue extends ResourceController implements Saveable {
String toString();
}
/*package*/ static final class FutureImpl extends AsyncFutureImpl<Executable> {
private final Task task;
/**
* If the computation has started, set to {@link Executor} that's running the build.
*/
private volatile Executor executor;
private FutureImpl(Task task) {
this.task = task;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
Queue q = Hudson.getInstance().getQueue();
synchronized (q) {
if(executor!=null) {
if(mayInterruptIfRunning)
executor.interrupt();
return mayInterruptIfRunning;
}
return q.cancel(task);
}
}
/*package*/ void startExecuting(Executor executor) {
this.executor = executor;
}
}
/**
* Item in a queue.
*/
......@@ -991,7 +1020,7 @@ public class Queue extends ResourceController implements Saveable {
@Exported
public final Task task;
/*package almost final*/ transient AsyncFutureImpl<Executable> future;
/*package almost final*/ transient FutureImpl future;
/**
* Build is blocked because another build is in progress,
......@@ -1022,7 +1051,7 @@ public class Queue extends ResourceController implements Saveable {
*/
public Future<Executable> getFuture() { return future; }
protected Item(Task task, List<Action> actions, int id, AsyncFutureImpl<Executable> future) {
protected Item(Task task, List<Action> actions, int id, FutureImpl future) {
this.task = task;
this.id = id;
this.future = future;
......@@ -1069,7 +1098,7 @@ public class Queue extends ResourceController implements Saveable {
}
private Object readResolve() {
this.future = new AsyncFutureImpl<Executable>();
this.future = new FutureImpl(task);
return this;
}
}
......@@ -1099,7 +1128,7 @@ public class Queue extends ResourceController implements Saveable {
public Calendar timestamp;
WaitingItem(Calendar timestamp, Task project, List<Action> actions) {
super(project, actions, COUNTER.incrementAndGet(), new AsyncFutureImpl<Executable>());
super(project, actions, COUNTER.incrementAndGet(), new FutureImpl(project));
this.timestamp = timestamp;
}
......
......@@ -48,11 +48,6 @@ public class AsyncFutureImpl<V> implements Future<V> {
private Throwable problem;
private boolean cancelled;
/**
* @deprecated
* Not externally cancellable, since this class doesn't know where the computation is actually happening.
* So you shouldn't be calling this method.
*/
public boolean cancel(boolean mayInterruptIfRunning) {
return false;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册