
hudson.model.queue.FutureImpl Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hudson-core Show documentation
Show all versions of hudson-core Show documentation
Contains the core Hudson code and view files to render HTML.
The newest version!
/*******************************************************************************
*
* Copyright (c) 2010, InfraDNA, Inc.
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
*
*
*
*
*******************************************************************************/
package hudson.model.queue;
import hudson.model.Executor;
import hudson.model.Hudson;
import hudson.model.Queue;
import hudson.model.Queue.Executable;
import hudson.model.Queue.Task;
import hudson.remoting.AsyncFutureImpl;
import java.util.HashSet;
import java.util.Set;
/**
* Created when {@link Queue.Item} is created so that the caller can track the
* progress of the task.
*
* @author Kohsuke Kawaguchi
*/
public final class FutureImpl extends AsyncFutureImpl {
private final Task task;
/**
* If the computation has started, set to {@link Executor}s that are running
* the build.
*/
private final Set executors = new HashSet();
public FutureImpl(Task task) {
this.task = task;
}
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
Queue q = Hudson.getInstance().getQueue();
synchronized (q) {
synchronized (this) {
if (!executors.isEmpty()) {
if (mayInterruptIfRunning) {
for (Executor e : executors) {
e.interrupt();
}
}
return mayInterruptIfRunning;
}
return q.cancel(task);
}
}
}
synchronized void addExecutor(Executor executor) {
this.executors.add(executor);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy