/** * Start this watchable and run until it is finished or stopped. * Note the watchable may be stopped if go() with a * different time is called during execution. * * @param synchronous if true, run in this thread */ public synchronized void go(boolean synchronous) { gate = null; execute(synchronous); }
/** * Wait for this watchable to finish */ public void waitForFinish() { synchronized (statusLock) { while (!isFinished() && getStatus() != Watchable.STOPPED) { try { statusLock.wait(); } catch (InterruptedException ex) { // ignore } } } }
/** * Creates a new instance of BaseWatchable */ protected BaseWatchable() { setStatus(Watchable.NOT_STARTED); }
if (getStatus() == Watchable.NOT_STARTED) { setup(); setStatus(Watchable.PAUSED); while (!isFinished() && getStatus() != Watchable.STOPPED) { if (isExecutable()) { setStatus(Watchable.RUNNING); while ((getStatus() == Watchable.RUNNING) && (gate == null || !gate.iterate())) { setStatus(iterate()); if (getStatus() == Watchable.RUNNING) { setStatus(Watchable.PAUSED); setError(ex); if (!isExecutable()) { try { statusLock.wait(); if (getStatus() == Watchable.COMPLETED || getStatus() == Watchable.ERROR) { cleanup();
/** * Start executing this watchable * * @param synchronous if true, run in this thread */ protected synchronized void execute(boolean synchronous) { // see if we're already running if (thread != null) { // we're already running. Make sure we wake up on any change. synchronized (statusLock) { statusLock.notifyAll(); } return; } else if (isFinished()) { // we're all finished return; } // we'return not running. Start up if (synchronous) { thread = Thread.currentThread(); run(); } else { thread = new Thread(this); thread.setName(getClass().getName()); thread.start(); } }
/** * Return whether this watchable has finished. A watchable is finished * when its status is either COMPLETED, STOPPED or ERROR */ public boolean isFinished() { int s = getStatus(); return (s == Watchable.COMPLETED || s == Watchable.ERROR); }
if (getStatus() == Watchable.NOT_STARTED) { setup(); setStatus(Watchable.PAUSED); while (!isFinished() && getStatus() != Watchable.STOPPED) { if (isExecutable()) { setStatus(Watchable.RUNNING); while ((getStatus() == Watchable.RUNNING) && (gate == null || !gate.iterate())) { setStatus(iterate()); if (getStatus() == Watchable.RUNNING) { setStatus(Watchable.PAUSED); setError(ex); if (!isExecutable()) { try { statusLock.wait(); if (getStatus() == Watchable.COMPLETED || getStatus() == Watchable.ERROR) { cleanup();
/** * Start executing this watchable * * @param synchronous if true, run in this thread */ protected synchronized void execute(boolean synchronous) { // see if we're already running if (thread != null) { // we're already running. Make sure we wake up on any change. synchronized (statusLock) { statusLock.notifyAll(); } return; } else if (isFinished()) { // we're all finished return; } // we'return not running. Start up if (synchronous) { thread = Thread.currentThread(); run(); } else { thread = new Thread(this); thread.setName(getClass().getName()); thread.start(); } }
/** * Return whether this watchable has finished. A watchable is finished * when its status is either COMPLETED, STOPPED or ERROR */ public boolean isFinished() { int s = getStatus(); return (s == Watchable.COMPLETED || s == Watchable.ERROR); }
if (getStatus() == Watchable.NOT_STARTED) { setup(); setStatus(Watchable.PAUSED); while (!isFinished() && getStatus() != Watchable.STOPPED) { if (isExecutable()) { setStatus(Watchable.RUNNING); while ((getStatus() == Watchable.RUNNING) && (gate == null || !gate.iterate())) { setStatus(iterate()); if (getStatus() == Watchable.RUNNING) { setStatus(Watchable.PAUSED); setError(ex); if (!isExecutable()) { try { statusLock.wait(); if (getStatus() == Watchable.COMPLETED || getStatus() == Watchable.ERROR) { cleanup();
/** * Start this watchable and run in a new thread until it is finished or * stopped. * Note the watchable may be stopped if go() with a * different time is called during execution. */ public synchronized void go() { gate = null; execute(false); }
/** * Wait for this watchable to finish */ public void waitForFinish() { synchronized (statusLock) { while (!isFinished() && getStatus() != Watchable.STOPPED) { try { statusLock.wait(); } catch (InterruptedException ex) { // ignore } } } }
/** * Start executing this watchable * * @param synchronous if true, run in this thread */ protected synchronized void execute(boolean synchronous) { // see if we're already running if (thread != null) { // we're already running. Make sure we wake up on any change. synchronized (statusLock) { statusLock.notifyAll(); } return; } else if (isFinished()) { // we're all finished return; } // we'return not running. Start up if (synchronous) { thread = Thread.currentThread(); run(); } else { thread = new Thread(this); thread.setName(getClass().getName()); thread.start(); } }
/** * Creates a new instance of BaseWatchable */ protected BaseWatchable() { setStatus(Watchable.NOT_STARTED); }
/** * Return whether this watchable has finished. A watchable is finished * when its status is either COMPLETED, STOPPED or ERROR */ public boolean isFinished() { int s = getStatus(); return (s == Watchable.COMPLETED || s == Watchable.ERROR); }
/** * Start this watchable and run in a new thread until it is finished or * stopped. * Note the watchable may be stopped if go() with a * different time is called during execution. */ public synchronized void go() { gate = null; execute(false); }
/** * Wait for this watchable to finish */ public void waitForFinish() { synchronized (statusLock) { while (!isFinished() && getStatus() != Watchable.STOPPED) { try { statusLock.wait(); } catch (InterruptedException ex) { // ignore } } } }
/** * Stop this watchable. Stop will cause all processing to cease, * and the watchable to be destroyed. */ public void stop() { setStatus(Watchable.STOPPED); }
private String getStatusString() { switch (getStatus()) { case Watchable.NOT_STARTED: return "Not started"; case Watchable.RUNNING: return "Running"; case Watchable.NEEDS_DATA: return "Needs Data"; case Watchable.PAUSED: return "Paused"; case Watchable.STOPPED: return "Stopped"; case Watchable.COMPLETED: return "Completed"; case Watchable.ERROR: return "Error"; default: return "Unknown"; } }
/** * Start this watchable and run in a new thread until it is finished or * stopped. * Note the watchable may be stopped if go() with a * different time is called during execution. */ public synchronized void go() { gate = null; execute(false); }