private void execute(WorkChunk wc, WorkUnitContext wuc) { assert capacity() >= wc.size(); int e = 0; for (SubTask s : wc) { while (!get(e).isAvailable()) e++; get(e++).set(wuc.createWorkUnit(s)); } } }
/** * Estimate of how long will it take to execute this executable. * Measured in milliseconds. * * @return -1 if it's impossible to estimate; default, {@link SubTask#getEstimatedDuration} * @since 1.383 */ default long getEstimatedDuration() { return Executables.getParentOf(this).getEstimatedDuration(); }
/** * Makes sure that all the assignments are made and it is within the constraints. */ public boolean isCompletelyValid() { for (ExecutorChunk ec : mapping) if (ec==null) return false; // unassigned return isPartiallyValid(); }
/** * Checks if the assignments made thus far are valid an within the constraints. */ public boolean isPartiallyValid() { int[] used = new int[executors.size()]; for (int i=0; i<mapping.length; i++) { ExecutorChunk ec = mapping[i]; if (ec==null) continue; if (!ec.canAccept(works(i))) return false; // invalid assignment if ((used[ec.index] += works(i).size()) > ec.capacity()) return false; } return true; }
@Override public String toString() { return getShortDescription(); }
/** * All the {@link Executor}s that jointly execute a {@link Task} call this method to synchronize on the start. */ public void synchronizeStart() throws InterruptedException { startLatch.synchronize(); // the main thread will send a notification Executor e = Executor.currentExecutor(); WorkUnit wu = e.getCurrentWorkUnit(); if (wu.isMainWork()) { future.start.set(e.getCurrentExecutable()); } }
private WorkChunk(List<SubTask> base, int index) { super(base); assert !base.isEmpty(); this.index = index; this.assignedLabel = getAssignedLabel(base.get(0)); Node lbo = base.get(0).getLastBuiltOn(); for (ExecutorChunk ec : executors) { if (ec.node==lbo) { lastBuiltOn = ec; return; } } lastBuiltOn = null; }
/** * Estimates load starting from the 'start' timestamp, up to the 'end' timestamp. * * @param start * Where to start enumeration. Always bigger or equal to the current time of the execution. * @param plan * This is the execution plan for which we are making a load prediction. Never null. While * this object is still being partially constructed when this method is called, some * of its properties (like {@link MappingWorksheet#item} provide access to more contextual * information. * @since 1.380 */ public Iterable<FutureLoad> predict(MappingWorksheet plan, Computer computer, long start, long end) { // maintain backward compatibility by calling the old signature. return predict(computer,start,end); }
/** * Number of executors in this chunk. * Alias for size but more readable. */ public int capacity() { return size(); }
public TimeRange shiftTo(long newStart) { if (newStart==start) return this; return new TimeRange(newStart,duration); } }
private Object readResolve() { this.future = new FutureImpl(task); return this; }
/** * Override this method to provide the ordering of the sort. * * <p> * if lhs should be build before rhs, return a negative value. Or put another way, think of the comparison * as a process of converting a {@link BuildableItem} into a number, then doing num(lhs)-num(rhs). * * <p> * The default implementation does FIFO. */ public int compare(BuildableItem lhs, BuildableItem rhs) { return compare(lhs.buildableStartMilliseconds,rhs.buildableStartMilliseconds); }
public MappingWorksheet(BuildableItem item, List<? extends ExecutorSlot> offers) { this(item,offers,LoadPredictor.all()); }
public FutureLoad toFutureLoad(int size) { return new FutureLoad(start,duration,size); }
/** * Opposite of {@link #isRefused()} */ public final boolean isAccepted() { return !isRefused(); }
/** * If this is representing an item that started executing, this property returns * the primary executable (such as {@link AbstractBuild}) that created out of it. */ @Exported public @CheckForNull Executable getExecutable() { return outcome!=null ? outcome.getPrimaryWorkUnit().getExecutable() : null; }
public static CauseOfBlockage createNeedsMoreExecutor(Localizable l) { return new NeedsMoreExecutorImpl(l); }
public static Refused refused() { return new Refused(); } }
public static Created created(WaitingItem i) { return new Created(i); }
public static Existing existing(Item i) { return new Existing(i); }