/** * Creates a ProgressTask that will execute the given Process when run. * * @param process the process to execute * @param input the inputs to use when executing the process * @throws NullPointerException if process is null */ public ProgressTask(Process process, Map<String, Object> input) { if (process == null) { throw new NullPointerException(); } synchronizer = new Synchronizer(process, input); }
Map<String, Object> innerGet() throws InterruptedException, ExecutionException { acquireSharedInterruptibly(0); if (getState() == CANCELED) { throw new CancellationException(); } if (exception != null) { throw new ExecutionException(exception); } return result; }
boolean innerCancel(boolean mayInterruptIfRunning) { for (; ; ) { int s = getState(); if (ranOrCancelled(s)) { return false; } if (compareAndSetState(s, CANCELED)) { break; } } if (mayInterruptIfRunning) { Thread r = runningThread; if (r != null) { r.interrupt(); } } releaseShared(0); done(); return true; }
boolean innerCancel(boolean mayInterruptIfRunning) { for (;;) { int s = getState(); if (ranOrCancelled(s)) { return false; } if (compareAndSetState(s, CANCELED)) { break; } } if (mayInterruptIfRunning) { Thread r = runningThread; if (r != null) { r.interrupt(); } } releaseShared(0); done(); return true; }
void innerSetException(Throwable t) { for (;;) { int s = getState(); if (ranOrCancelled(s)) { return; } if (compareAndSetState(s, COMPLETED)) { break; } } exception = t; result = null; releaseShared(0); done(); }
public void setCanceled( boolean stop ) { innerCancel( stop ); }
boolean innerIsCancelled() { return getState() == CANCELED; }
boolean innerRunAndReset() { if (!compareAndSetState(0, RUNNING)) { return false; } try { runningThread = Thread.currentThread(); process.execute( input, this ); // don't set the result runningThread = null; return compareAndSetState(RUNNING, 0); } catch(Throwable ex) { innerSetException(ex); return false; } }
public boolean isCancelled() { return synchronizer.innerIsCancelled(); }
public boolean isDone() { return synchronizer.innerIsDone(); }
public Map<String,Object> get() throws InterruptedException, ExecutionException { return synchronizer.innerGet(); }
public boolean isCanceled() { return innerIsCancelled(); }
/** * Creates a ProgressTask that will execute the * given Process when run. * * @param process the process to execute * @param input the inputs to use when executing the process * @throws NullPointerException if process is null */ public ProgressTask(Process process, Map<String,Object> input) { if (process== null) { throw new NullPointerException(); } synchronizer = new Synchronizer(process, input); }
boolean innerIsDone() { return ranOrCancelled(getState()) && runningThread == null; }
public float getProgress() { return synchronizer.getProgress(); }
public boolean cancel(boolean mayInterruptIfRunning) { return synchronizer.innerCancel(mayInterruptIfRunning); }
@Deprecated public String getDescription() { return getTask().toString(); }
public Map<String,Object> get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return synchronizer.innerGet(unit.toNanos(timeout)); }
void innerSet(Map<String,Object> v) { for (;;) { int s = getState(); if (ranOrCancelled(s)) { return; } if (compareAndSetState(s, COMPLETED)) { break; } } result = v; releaseShared(0); done(); }
void innerRun() { if (!compareAndSetState(0, RUNNING)) { return; } try { runningThread = Thread.currentThread(); innerSet(process.execute( input, this )); } catch(Throwable ex) { innerSetException(ex); } }