Search in sources :

Example 21 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.

the class LoggingScheduledExecutor method afterExecute.

@Override
protected void afterExecute(Runnable runnable, Throwable throwable) {
    super.afterExecute(runnable, throwable);
    Level level = FINE;
    if (throwable == null && runnable instanceof ScheduledFuture && ((ScheduledFuture) runnable).isDone()) {
        try {
            ((Future) runnable).get();
        } catch (CancellationException ce) {
            throwable = ce;
        } catch (ExecutionException ee) {
            level = SEVERE;
            throwable = ee.getCause();
        } catch (InterruptedException ie) {
            throwable = ie;
            currentThread().interrupt();
        }
    }
    if (throwable != null) {
        logger.log(level, "Failed to execute " + runnable, throwable);
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(java.util.concurrent.Future) RunnableScheduledFuture(java.util.concurrent.RunnableScheduledFuture) Level(java.util.logging.Level) ExecutionException(java.util.concurrent.ExecutionException) ScheduledFuture(java.util.concurrent.ScheduledFuture) RunnableScheduledFuture(java.util.concurrent.RunnableScheduledFuture)

Example 22 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.

the class SecondsBasedEntryTaskScheduler method cancelAll.

public void cancelAll() {
    synchronized (mutex) {
        secondsOfKeys.clear();
        scheduledEntries.clear();
        for (ScheduledFuture task : scheduledTaskMap.values()) {
            task.cancel(false);
        }
        scheduledTaskMap.clear();
    }
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 23 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.

the class DelegatingScheduledFutureStripperTest method get_unsupported.

@Test(expected = UnsupportedOperationException.class)
public void get_unsupported() throws ExecutionException, InterruptedException, TimeoutException {
    ScheduledFuture future = scheduler.schedule(new SimpleCallableTestTask(), 0, TimeUnit.SECONDS);
    new DelegatingScheduledFutureStripper(future).get(1, TimeUnit.SECONDS);
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) DelegatingScheduledFutureStripper(com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 24 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.

the class DelegatingScheduledFutureStripperTest method get.

@Test
public void get() throws ExecutionException, InterruptedException {
    ScheduledFuture original = taskScheduler.schedule(new SimpleCallableTestTask(), 0, TimeUnit.SECONDS);
    ScheduledFuture stripper = new DelegatingScheduledFutureStripper(original);
    assertTrue(original.get() instanceof Future);
    assertEquals(5, stripper.get());
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) Future(java.util.concurrent.Future) ScheduledFuture(java.util.concurrent.ScheduledFuture) DelegatingScheduledFutureStripper(com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Example 25 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.

the class DelegatingScheduledFutureStripperTest method equals.

@Test
public void equals() {
    ScheduledFuture original = taskScheduler.schedule(new SimpleCallableTestTask(), 0, TimeUnit.SECONDS);
    ScheduledFuture joker = taskScheduler.schedule(new SimpleCallableTestTask(), 1, TimeUnit.SECONDS);
    ScheduledFuture testA = new DelegatingScheduledFutureStripper(original);
    ScheduledFuture testB = new DelegatingScheduledFutureStripper(original);
    ScheduledFuture testC = new DelegatingScheduledFutureStripper(joker);
    assertTrue(testA.equals(testA));
    assertTrue(testA.equals(testB));
    assertFalse(testA.equals(null));
    assertFalse(testA.equals(testC));
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture) DelegatingScheduledFutureStripper(com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper) QuickTest(com.hazelcast.test.annotation.QuickTest) Test(org.junit.Test) ParallelTest(com.hazelcast.test.annotation.ParallelTest)

Aggregations

ScheduledFuture (java.util.concurrent.ScheduledFuture)83 Test (org.junit.Test)27 DelegatingScheduledFutureStripper (com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 Date (java.util.Date)9 IOException (java.io.IOException)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 Map (java.util.Map)6 TimeValue (org.elasticsearch.common.unit.TimeValue)6 None (com.linkedin.common.util.None)5 D2Client (com.linkedin.d2.balancer.D2Client)5 D2ClientBuilder (com.linkedin.d2.balancer.D2ClientBuilder)5 CountDownLatch (java.util.concurrent.CountDownLatch)5 TestThreadPool (org.elasticsearch.threadpool.TestThreadPool)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 JSONObject (org.json.simple.JSONObject)5 IdleReaderException (com.twitter.distributedlog.exceptions.IdleReaderException)4 ExecutionException (java.util.concurrent.ExecutionException)4 Future (java.util.concurrent.Future)4