public WorkUnitContext(BuildableItem item) { this.item = item; this.task = item.task; this.future = (FutureImpl)item.getFuture(); // JENKINS-51584 do not use item.getAllActions() here. this.actions = new ArrayList<Action>(item.getActions()); // +1 for the main task int workUnitSize = task.getSubTasks().size(); startLatch = new Latch(workUnitSize) { @Override protected void onCriteriaMet() { // on behalf of the member Executors, // the one that executes the main thing will send notifications // Unclear if this will work with AsynchronousExecution; it *seems* this is only called from synchronize which is only called from synchronizeStart which is only called from an executor thread. Executor e = Executor.currentExecutor(); if (e.getCurrentWorkUnit().isMainWork()) { e.getOwner().taskAccepted(e,task); } } }; endLatch = new Latch(workUnitSize); }
/** * Waits for N threads to enter the {@link #synchronize()} method, then * returns. * * @return * returns normally if N threads successfully synchronized. * @throws InterruptedException * if any of the threads that were synchronizing get interrupted, * or if the {@link #abort(Throwable)} is called. */ public synchronized void synchronize() throws InterruptedException { check(n); try { onCriteriaMet(); } catch (Error e) { abort(e); throw e; } catch (RuntimeException e) { abort(e); throw e; } check(n*2); }
/** * 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()); } }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
public synchronized void synchronize() throws InterruptedException { check(n); try { onCriteriaMet(); } catch (Error e) { abort(e); throw e; } catch (RuntimeException e) { abort(e); throw e; } check(n*2); }
/** * All the {@link Executor}s that jointly execute a {@link Task} call this method to synchronize on the end of the task. * * @throws InterruptedException * If any of the member thread is interrupted while waiting for other threads to join, all * the member threads will report {@link InterruptedException}. */ public void synchronizeEnd(Executor e, Queue.Executable executable, Throwable problems, long duration) throws InterruptedException { endLatch.synchronize(); // the main thread will send a notification WorkUnit wu = e.getCurrentWorkUnit(); if (wu.isMainWork()) { if (problems == null) { future.set(executable); e.getOwner().taskCompleted(e, task, duration); } else { future.set(problems); e.getOwner().taskCompletedWithProblems(e, task, duration, problems); } } }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
public WorkUnitContext(BuildableItem item) { this.item = item; this.task = item.task; this.future = (FutureImpl)item.getFuture(); this.actions = new ArrayList<Action>(item.getAllActions()); // +1 for the main task int workUnitSize = task.getSubTasks().size(); startLatch = new Latch(workUnitSize) { @Override protected void onCriteriaMet() { // on behalf of the member Executors, // the one that executes the main thing will send notifications // Unclear if this will work with AsynchronousExecution; it *seems* this is only called from synchronize which is only called from synchronizeStart which is only called from an executor thread. Executor e = Executor.currentExecutor(); if (e.getCurrentWorkUnit().isMainWork()) { e.getOwner().taskAccepted(e,task); } } }; endLatch = new Latch(workUnitSize); }
public synchronized void synchronize() throws InterruptedException { check(n); try { onCriteriaMet(); } catch (Error e) { abort(e); throw e; } catch (RuntimeException e) { abort(e); throw e; } check(n*2); }
/** * 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(); }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
public WorkUnitContext(BuildableItem item) { this.item = item; this.task = item.task; this.future = (FutureImpl)item.getFuture(); this.actions = item.getActions(); // +1 for the main task int workUnitSize = Tasks.getSubTasksOf(task).size(); startLatch = new Latch(workUnitSize) { @Override protected void onCriteriaMet() { // on behalf of the member Executors, // the one that executes the main thing will send notifications Executor e = Executor.currentExecutor(); if (e.getCurrentWorkUnit().isMainWork()) { e.getOwner().taskAccepted(e,task); } } }; endLatch = new Latch(workUnitSize); }
public synchronized void synchronize() throws InterruptedException { check(n); try { onCriteriaMet(); } catch (Error e) { abort(e); throw e; } catch (RuntimeException e) { abort(e); throw e; } check(n * 2); }
/** * 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(); }
/** * When one of the work unit is aborted, call this method to abort all the other work units. */ public synchronized void abort(Throwable cause) { if (cause==null) throw new IllegalArgumentException(); if (aborted!=null) return; // already aborted aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e!=null && e!=c) e.interrupt(); } } }
public WorkUnitContext(BuildableItem item) { this.item = item; this.task = item.task; this.future = (FutureImpl)item.getFuture(); this.actions = item.getActions(); // +1 for the main task int workUnitSize = Tasks.getSubTasksOf(task).size(); startLatch = new Latch(workUnitSize) { @Override protected void onCriteriaMet() { // on behalf of the member Executors, // the one that executes the main thing will send notifications Executor e = Executor.currentExecutor(); if (e.getCurrentWorkUnit().isMainWork()) { e.getOwner().taskAccepted(e,task); } } }; endLatch = new Latch(workUnitSize); }
public synchronized void synchronize() throws InterruptedException { check(n); try { onCriteriaMet(); } catch (Error e) { abort(e); throw e; } catch (RuntimeException e) { abort(e); throw e; } check(n*2); }
/** * 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(); }
/** * When one of the work unit is aborted, call this method to abort all the * other work units. */ public synchronized void abort(Throwable cause) { if (cause == null) { throw new IllegalArgumentException(); } if (aborted != null) { return; // already aborted } aborted = cause; startLatch.abort(cause); endLatch.abort(cause); Thread c = Thread.currentThread(); for (WorkUnit wu : workUnits) { Executor e = wu.getExecutor(); if (e != null && e != c) { e.interrupt(); } } } }