Search in sources :

Example 26 with TimerTask

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);
}
Also used : TimerTask(java.util.TimerTask) StoppedByUserException(org.junit.runner.notification.StoppedByUserException) Failure(org.junit.runner.notification.Failure)

Example 27 with TimerTask

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);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 28 with TimerTask

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;
}
Also used : TimerTask(java.util.TimerTask)

Example 29 with 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);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 30 with TimerTask

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);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask) SharedPreferences(android.content.SharedPreferences)

Aggregations

TimerTask (java.util.TimerTask)359 Timer (java.util.Timer)260 IOException (java.io.IOException)25 Date (java.util.Date)21 Test (org.junit.Test)20 File (java.io.File)13 ArrayList (java.util.ArrayList)11 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 InputMethodManager (android.view.inputmethod.InputMethodManager)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)7 Location (android.location.Location)6 LocationListener (android.location.LocationListener)6 View (android.view.View)6 ImageView (android.widget.ImageView)6 HashMap (java.util.HashMap)6 TextView (android.widget.TextView)5 URI (java.net.URI)5 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)5