mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 05:52:26 +00:00
improving cross-linking between WorkUnit and Executor
git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@34614 71c3de6d-444a-0410-be80-ed276b4c234a
This commit is contained in:
1 parent
0cee4ef199
commit
40d4c2d76a
5 files changed
+50
-9
No files matched your search
@@ -1010,6 +1010,7 @@ public abstract class AbstractProject<P extends AbstractProject<P,R>,R extends A
|
||||
|
||||
public List<SubTask> getSubTasks() {
|
||||
List<SubTask> r = new ArrayList<SubTask>();
|
||||
r.add(this);
|
||||
for (SubTaskContributor euc : SubTaskContributor.all())
|
||||
r.addAll(euc.forProject(this));
|
||||
for (JobProperty<? super P> p : properties)
|
||||
|
||||
@@ -108,6 +108,7 @@ public class Executor extends Thread implements ModelObject {
|
||||
try {
|
||||
synchronized (queue) {// perform this state change as an atomic operation wrt other queue operations
|
||||
workUnit = grabJob();
|
||||
workUnit.setExecutor(this);
|
||||
task = workUnit.work;
|
||||
startTime = System.currentTimeMillis();
|
||||
executable = task.createExecutable();
|
||||
|
||||
@@ -44,11 +44,27 @@ public final class WorkUnit {
|
||||
*/
|
||||
public final WorkUnitContext context;
|
||||
|
||||
private Executor executor;
|
||||
|
||||
WorkUnit(WorkUnitContext context, SubTask work) {
|
||||
this.context = context;
|
||||
this.work = work;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@link Executor} running this work unit.
|
||||
* <p>
|
||||
* {@link Executor#getCurrentWorkUnit()} and {@link WorkUnit#getExecutor()}
|
||||
* form a bi-directional reachability between them.
|
||||
*/
|
||||
public Executor getExecutor() {
|
||||
return executor;
|
||||
}
|
||||
|
||||
public void setExecutor(Executor e) {
|
||||
executor = e;
|
||||
}
|
||||
|
||||
/**
|
||||
* Is this work unit the "main work", which is the primary {@link SubTask}
|
||||
* represented by {@link Task} itself.
|
||||
|
||||
@@ -29,6 +29,8 @@ import hudson.model.Queue;
|
||||
import hudson.model.Queue.BuildableItem;
|
||||
import hudson.model.Queue.Task;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -37,7 +39,6 @@ import java.util.List;
|
||||
* @author Kohsuke Kawaguchi
|
||||
*/
|
||||
public final class WorkUnitContext {
|
||||
private final int workUnitSize;
|
||||
|
||||
public final BuildableItem item;
|
||||
|
||||
@@ -55,6 +56,8 @@ public final class WorkUnitContext {
|
||||
|
||||
private final Latch startLatch, endLatch;
|
||||
|
||||
private List<WorkUnit> workUnits = new ArrayList<WorkUnit>();
|
||||
|
||||
public WorkUnitContext(BuildableItem item) {
|
||||
this.item = item;
|
||||
this.task = item.task;
|
||||
@@ -62,7 +65,7 @@ public final class WorkUnitContext {
|
||||
this.actions = item.getActions();
|
||||
|
||||
// +1 for the main task
|
||||
workUnitSize = task.getSubTasks().size();
|
||||
int workUnitSize = task.getSubTasks().size();
|
||||
startLatch = new Latch(workUnitSize) {
|
||||
@Override
|
||||
protected void onCriteriaMet() {
|
||||
@@ -84,7 +87,17 @@ public final class WorkUnitContext {
|
||||
*/
|
||||
public WorkUnit createWorkUnit(SubTask execUnit) {
|
||||
future.addExecutor(Executor.currentExecutor());
|
||||
return new WorkUnit(this,execUnit);
|
||||
WorkUnit wu = new WorkUnit(this, execUnit);
|
||||
workUnits.add(wu);
|
||||
return wu;
|
||||
}
|
||||
|
||||
public List<WorkUnit> getWorkUnits() {
|
||||
return Collections.unmodifiableList(workUnits);
|
||||
}
|
||||
|
||||
public WorkUnit getPrimaryWorkUnit() {
|
||||
return workUnits.get(0);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in new issue
Block a user