Search in sources :

Example 41 with TimerTask

use of java.util.TimerTask in project PlayerHater by chrisrhoden.

the class PlaylistSupportingPlayer method startWithFade.

public void startWithFade() throws IllegalStateException {
    setVolume(0, 0);
    start();
    final Timer timer = new Timer(true);
    TimerTask timerTask = new TimerTask() {

        @Override
        public void run() {
            setVolume(mLeftVolume + 0.1f, mRightVolume + 01.f);
            if (mLeftVolume >= 1.0f || mRightVolume >= 1.0f) {
                timer.cancel();
                timer.purge();
            }
        }
    };
    timer.schedule(timerTask, 200, 200);
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Example 42 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 43 with TimerTask

use of java.util.TimerTask in project OpenGrok by OpenGrok.

the class RuntimeEnvironment method addMessage.

/**
     * Add a message to the application.
     * Also schedules a expiration timer to remove this message after its expiration.
     *
     * @param m the message
     */
public void addMessage(Message m) {
    if (!canAcceptMessage(m)) {
        return;
    }
    if (expirationTimer == null) {
        expireMessages();
    }
    boolean added = false;
    for (String tag : m.getTags()) {
        if (!tagMessages.containsKey(tag)) {
            tagMessages.put(tag, new ConcurrentSkipListSet<>());
        }
        if (tagMessages.get(tag).add(m)) {
            messagesInTheSystem++;
            added = true;
        }
    }
    if (added) {
        if (expirationTimer != null) {
            expirationTimer.schedule(new TimerTask() {

                @Override
                public void run() {
                    expireMessages();
                }
            }, new Date(m.getExpiration().getTime() + 10));
        }
    }
}
Also used : TimerTask(java.util.TimerTask) Date(java.util.Date)

Example 44 with TimerTask

use of java.util.TimerTask in project pinot by linkedin.

the class RealtimeTableDataManagerTest method testSetup.

public void testSetup() throws Exception {
    final HLRealtimeSegmentDataManager manager = new HLRealtimeSegmentDataManager(realtimeSegmentZKMetadata, tableConfig, instanceZKMetadata, null, tableDataManagerConfig.getDataDir(), ReadMode.valueOf(tableDataManagerConfig.getReadMode()), getTestSchema(), new ServerMetrics(new MetricsRegistry()));
    final long start = System.currentTimeMillis();
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            if (System.currentTimeMillis() - start >= (SEGMENT_CONSUMING_TIME)) {
                keepOnRunning = false;
            }
        }
    }, 1000, 1000 * 60 * 1);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("count");
                BlockValSet valSet = mDs.nextBlock().getBlockValueSet();
                BlockSingleValIterator valIt = (BlockSingleValIterator) valSet.iterator();
                int val = valIt.nextIntVal();
                while (val != Constants.EOF) {
                    val = valIt.nextIntVal();
                    sum += val;
                }
            } catch (Exception e) {
                LOGGER.info("count column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan metric col count : " + (stop - start) + " sum : " + sum);
        }
    }, 20000, 1000 * 5);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("viewerId");
                BlockValSet valSet = mDs.nextBlock().getBlockValueSet();
                BlockSingleValIterator valIt = (BlockSingleValIterator) valSet.iterator();
                int val = valIt.nextIntVal();
                while (val != Constants.EOF) {
                    val = valIt.nextIntVal();
                    sum += val;
                }
            } catch (Exception e) {
                LOGGER.info("viewerId column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan SV dimension col viewerId : " + (stop - start) + " sum : " + sum);
        }
    }, 20000, 1000 * 5);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("daysSinceEpoch");
                BlockValSet valSet = mDs.nextBlock().getBlockValueSet();
                BlockSingleValIterator valIt = (BlockSingleValIterator) valSet.iterator();
                int val = valIt.nextIntVal();
                while (val != Constants.EOF) {
                    val = valIt.nextIntVal();
                    sum += val;
                }
            } catch (Exception e) {
                LOGGER.info("daysSinceEpoch column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan SV time col daysSinceEpoch : " + (stop - start) + " sum : " + sum);
        }
    }, 20000, 1000 * 5);
    TimerService.timer.scheduleAtFixedRate(new TimerTask() {

        @Override
        public void run() {
            long start = System.currentTimeMillis();
            long sum = 0;
            float sumOfLengths = 0F;
            float counter = 0F;
            try {
                RealtimeSegment segment = (RealtimeSegment) manager.getSegment();
                RealtimeColumnDataSource mDs = (RealtimeColumnDataSource) segment.getDataSource("viewerCompanies");
                Block b = mDs.nextBlock();
                BlockValSet valSet = b.getBlockValueSet();
                BlockMultiValIterator valIt = (BlockMultiValIterator) valSet.iterator();
                BlockMetadata m = b.getMetadata();
                int maxVams = m.getMaxNumberOfMultiValues();
                while (valIt.hasNext()) {
                    int[] vals = new int[maxVams];
                    int len = valIt.nextIntVal(vals);
                    for (int i = 0; i < len; i++) {
                        sum += vals[i];
                    }
                    sumOfLengths += len;
                    counter++;
                }
            } catch (Exception e) {
                LOGGER.info("daysSinceEpoch column exception");
                e.printStackTrace();
            }
            long stop = System.currentTimeMillis();
            LOGGER.info("time to scan MV col viewerCompanies : " + (stop - start) + " sum : " + sum + " average len : " + (sumOfLengths / counter));
        }
    }, 20000, 1000 * 5);
    while (keepOnRunning) {
    // Wait for keepOnRunning to be set to false
    }
}
Also used : MetricsRegistry(com.yammer.metrics.core.MetricsRegistry) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException) ConfigurationException(org.apache.commons.configuration.ConfigurationException) BlockMultiValIterator(com.linkedin.pinot.core.common.BlockMultiValIterator) TimerTask(java.util.TimerTask) RealtimeColumnDataSource(com.linkedin.pinot.core.realtime.impl.datasource.RealtimeColumnDataSource) BlockSingleValIterator(com.linkedin.pinot.core.common.BlockSingleValIterator) BlockMetadata(com.linkedin.pinot.core.common.BlockMetadata) BlockValSet(com.linkedin.pinot.core.common.BlockValSet) Block(com.linkedin.pinot.core.common.Block) ServerMetrics(com.linkedin.pinot.common.metrics.ServerMetrics) HLRealtimeSegmentDataManager(com.linkedin.pinot.core.data.manager.realtime.HLRealtimeSegmentDataManager) RealtimeSegment(com.linkedin.pinot.core.realtime.RealtimeSegment)

Example 45 with TimerTask

use of java.util.TimerTask in project FastDev4Android by jiangqqlmj.

the class AutoGallery method start.

/**
     * 开启定时器
     */
public void start() {
    if (length > 0 && timer == null) {
        timer = new Timer();
        //进行每个delayMillis时间gallery切换一张图片
        timer.scheduleAtFixedRate(new TimerTask() {

            @Override
            public void run() {
                if (length > 0) {
                    onKeyDown(KeyEvent.KEYCODE_DPAD_RIGHT, null);
                }
            }
        }, delayMillis, delayMillis);
    }
}
Also used : Timer(java.util.Timer) TimerTask(java.util.TimerTask)

Aggregations

TimerTask (java.util.TimerTask)413 Timer (java.util.Timer)298 IOException (java.io.IOException)31 Date (java.util.Date)23 Test (org.junit.Test)21 ArrayList (java.util.ArrayList)17 File (java.io.File)16 Intent (android.content.Intent)8 Bundle (android.os.Bundle)8 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)8 InputMethodManager (android.view.inputmethod.InputMethodManager)7 HashMap (java.util.HashMap)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 TextView (android.widget.TextView)6 URI (java.net.URI)5 CountDownLatch (java.util.concurrent.CountDownLatch)5