use of java.util.TimerTask in project buck by facebook.
the class DelegateRunNotifier method fireTestStarted.
@Override
public void fireTestStarted(final Description description) throws StoppedByUserException {
delegate.fireTestStarted(description);
// Do not do apply the default timeout if the test has its own @Test(timeout).
if (hasJunitTimeout(description)) {
return;
}
// Schedule a timer that verifies that the test completed within the specified timeout.
TimerTask task = new TimerTask() {
@Override
public void run() {
synchronized (finishedTests) {
// If the test already finished, then do nothing.
if (finishedTests.contains(description)) {
return;
}
hasTestThatExceededTimeout.set(true);
// Should report the failure. The Exception is modeled after the one created by
// org.junit.internal.runners.statements.FailOnTimeout#createTimeoutException(Thread).
Exception exception = new Exception(String.format("test timed out after %d milliseconds", defaultTestTimeoutMillis));
Failure failure = new Failure(description, exception);
fireTestFailure(failure);
fireTestFinished(description);
if (!finishedTests.contains(description)) {
throw new IllegalStateException("fireTestFinished() should update finishedTests.");
}
onTestRunFinished();
}
}
};
timer.schedule(task, defaultTestTimeoutMillis);
}
use of java.util.TimerTask in project android_frameworks_base by ParanoidAndroid.
the class ComprehensiveCountryDetector method scheduleLocationRefresh.
/**
* Schedule the next location refresh. We will do nothing if the scheduled task exists.
*/
private synchronized void scheduleLocationRefresh() {
if (mLocationRefreshTimer != null)
return;
if (DEBUG) {
Slog.d(TAG, "start periodic location refresh timer. Interval: " + LOCATION_REFRESH_INTERVAL);
}
mLocationRefreshTimer = new Timer();
mLocationRefreshTimer.schedule(new TimerTask() {
@Override
public void run() {
if (DEBUG) {
Slog.d(TAG, "periodic location refresh event. Starts detecting Country code");
}
mLocationRefreshTimer = null;
detectCountry(false, true);
}
}, LOCATION_REFRESH_INTERVAL);
}
use of java.util.TimerTask in project SKMCLauncher by SKCraft.
the class SwingProgressObserver method updatePeriodically.
/**
* Schedule a progress updater.
*
* @param updater the object to call
* @return a timer task that can be cancelled
*/
public static TimerTask updatePeriodically(ProgressUpdater updater) {
TimerTask timerTask = new ProgressTimerTask(updater);
timer.schedule(timerTask, PROGRESS_INTERVAL, PROGRESS_INTERVAL);
return timerTask;
}
use of java.util.TimerTask in project simperium-android by Simperium.
the class WebSocketManager method scheduleHeartbeat.
private void scheduleHeartbeat() {
cancelHeartbeat();
mHeartbeatTimer = new Timer();
mHeartbeatTimer.schedule(new TimerTask() {
public void run() {
sendHearbeat();
}
}, HEARTBEAT_INTERVAL);
}
use of java.util.TimerTask in project storymaker by StoryMaker.
the class ProjectsProvider method setTimer.
synchronized void setTimer(long delay) {
// if there is no pin set, do not set a timer (will force a lock and potentially cause a crash)
SharedPreferences settings = getContext().getApplicationContext().getSharedPreferences("appPrefs", Context.MODE_PRIVATE);
String cachewordStatus = settings.getString("cacheword_status", null);
if (cachewordStatus == null) {
return;
}
// if there is an existing timer, clear it
if (dbTimer != null) {
dbTimer.cancel();
dbTimer = null;
}
// set timer to disconnect from cacheword service so it can timeout
dbTimer = new Timer();
dbTimer.schedule(new TimerTask() {
public void run() {
mCacheWordHandler.disconnectFromService();
dbTimer.cancel();
dbTimer = null;
}
}, // 1 min delay
delay);
}
Aggregations