@Override public void checkCancelled() throws InterruptedException { parent.checkCancelled(); }
@Override public OutputStream getOutput() throws IOException { return parent.getJobOutput(jobId); }
/** * Returns an output stream for jobs. * The default implementation returns the {@link #getOutput() this.getOutput()}. * @param jobId target job ID * @return the target stream * @throws IOException if failed to obtain output */ protected OutputStream getJobOutput(String jobId) throws IOException { return getOutput(); }
@Override public final void execute( PhaseMonitor monitor, ExecutionContext context, List<? extends Job> jobs, ErrorHandler errorHandler) throws InterruptedException, IOException { if (monitor == null) { throw new IllegalArgumentException("monitor must not be null"); //$NON-NLS-1$ } if (context == null) { throw new IllegalArgumentException("context must not be null"); //$NON-NLS-1$ } if (jobs == null) { throw new IllegalArgumentException("jobs must not be null"); //$NON-NLS-1$ } if (errorHandler == null) { throw new IllegalArgumentException("errorHandler must not be null"); //$NON-NLS-1$ } monitor.open(jobs.size()); try { monitor.checkCancelled(); Engine engine = new Engine(getJobExecutor(), monitor, context, errorHandler, jobs); engine.run(); } finally { monitor.close(); } }
private boolean submit(Job job) throws InterruptedException, IOException { assert job != null; monitor.checkCancelled(); try { Executing execution = executor.submit( monitor.createJobMonitor(job.getId(), 1), context, job, doneQueue); executing.put(execution.getJob().getId(), execution); return true; } catch (IOException e) { sawError = true; handleException(job, e); return false; } }
@Override public void checkCancelled() throws InterruptedException { if (Thread.interrupted() || isCancelRequested()) { throw new InterruptedException(); } }
/** * Begins a task and notify this event to the corresponding receiver. * This method can be invoked once for each object. * @param taskSize the total task size * @throws IOException if failed to notify this event * @throws IllegalArgumentException if some parameters were {@code null} */ @Override public synchronized void open(double taskSize) throws IOException { if (taskSize <= 0) { throw new IllegalArgumentException("taskSize must be > 0"); //$NON-NLS-1$ } this.currentTaskSize = taskSize; parent.onJobMonitorOpened(jobId); }
private void changeCurrentProgress(double nextProgress) throws IOException { if (closed) { return; } closed = true; if (taskSizeInParent == 0) { return; } double normalized = Math.max(0, Math.min(currentTaskSize, nextProgress)); assert 0 <= normalized && normalized <= currentTaskSize; double delta = normalized - currentProgress; double deltaInParent = delta / taskSizeInParent; currentProgress = normalized; if (deltaInParent != 0) { parent.progressed(deltaInParent); } } }
@Override public synchronized void close() throws IOException { changeCurrentProgress(currentTaskSize); parent.onJobMonitorClosed(jobId); }
private void waitForDone() throws InterruptedException, IOException { assert executing.isEmpty() == false; monitor.checkCancelled(); Executing done = doneQueue.take(); assert done.isDone(); handleDone(done); while (true) { monitor.checkCancelled(); Executing rest = doneQueue.poll(); if (rest == null) { break; } assert rest.isDone(); handleDone(rest); } }