/** * May be called from within timeReached(), but schedule() is better there. * * @param timeoutMs * @param useEarliestTime if its already scheduled, use the earlier of the two timeouts, else * use the later */ public synchronized void reschedule(long timeoutMs, boolean useEarliestTime) { final long now = System.currentTimeMillis(); long oldTimeout; boolean scheduled = _state == TimedEventState.SCHEDULED; if (scheduled) oldTimeout = _nextRun - now; else oldTimeout = timeoutMs; // don't bother rescheduling if within _fuzz ms if ((oldTimeout - _fuzz > timeoutMs && useEarliestTime) || (oldTimeout + _fuzz < timeoutMs && !useEarliestTime) || (!scheduled)) { if (scheduled && (now + timeoutMs) < _nextRun) { if (_log.shouldLog(Log.INFO)) _log.info( "Re-scheduling: " + this + " timeout = " + timeoutMs + " old timeout was " + oldTimeout + " state: " + _state); cancel(); } schedule(timeoutMs); } }
/** * Blocking, may take a while, up to 20 seconds */ public synchronized void stop() { if (_log.shouldLog(Log.DEBUG)) _log.debug("UPnP Stop"); _shouldBeRunning = false; _rescanner.cancel(); if (_isRunning) _upnp.terminate(); _isRunning = false; _detectedAddress = null; if (_log.shouldLog(Log.DEBUG)) _log.debug("UPnP Stop Done"); }
/** * Always use the new time - ignores fuzz * * @param timeoutMs */ public synchronized void forceReschedule(long timeoutMs) { cancel(); schedule(timeoutMs); }