Search in sources :

Example 31 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project geode by apache.

the class ScheduledThreadPoolExecutorWithKeepAlive method schedule.

private ScheduledFuture schedule(Runnable command, long delay, TimeUnit unit, Object result) {
    DelegatingScheduledFuture future = new DelegatingScheduledFuture(command, result);
    ScheduledFuture timerFuture = timer.schedule(new HandOffTask(future), delay, unit);
    future.setDelegate(timerFuture);
    return future;
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 32 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project geode by apache.

the class ScheduledThreadPoolExecutorWithKeepAlive method schedule.

public ScheduledFuture schedule(Callable callable, long delay, TimeUnit unit) {
    DelegatingScheduledFuture future = new DelegatingScheduledFuture(callable);
    ScheduledFuture timerFuture = timer.schedule(new HandOffTask(future), delay, unit);
    future.setDelegate(timerFuture);
    return future;
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 33 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project geode by apache.

the class ScheduledThreadPoolExecutorWithKeepAlive method scheduleAtFixedRate.

public ScheduledFuture scheduleAtFixedRate(Runnable command, long initialDelay, long period, TimeUnit unit) {
    DelegatingScheduledFuture future = new DelegatingScheduledFuture(command, null, true);
    ScheduledFuture timerFuture = timer.scheduleAtFixedRate(new HandOffTask(future), initialDelay, period, unit);
    future.setDelegate(timerFuture);
    return future;
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 34 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project geode by apache.

the class StorageCommand method scheduleExpiration.

/**
   * Schedules the entry to expire based on the following: the expiration time sent may either be
   * Unix time (number of seconds since January 1, 1970, as a 32-bit value), or a number of seconds
   * starting from current time. In the latter case, this number of seconds may not exceed
   * 60*60*24*30 (number of seconds in 30 days); if the number sent by a client is larger than that,
   * the server will consider it to be real Unix time value rather than an offset from current time.
   * 
   * @param key
   * @param p_expTime
   * @param cache
   */
private void scheduleExpiration(final Object key, long p_expTime, final Cache cache) {
    long expTime = p_expTime;
    assert expTime > 0;
    if (p_expTime > secsIn30Days) {
        expTime = p_expTime - System.currentTimeMillis();
        if (expTime < 0) {
            getLogger().info("Invalid expiration time passed, key:" + key + " will not expire");
            return;
        }
    }
    ScheduledFuture f = expiryExecutor.schedule(new ExpiryTask(cache, key), expTime, TimeUnit.SECONDS);
    expiryFutures.put(key, f);
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 35 with ScheduledFuture

use of java.util.concurrent.ScheduledFuture in project geode by apache.

the class StorageCommand method rescheduleExpiration.

/**
   * reschedules expiration for a key only if one was previously scheduled
   * 
   * @param key
   * @param newExpTime
   * @return true if successfully rescheduled, false otherwise
   */
public static boolean rescheduleExpiration(Cache cache, Object key, int newExpTime) {
    ScheduledFuture f = expiryFutures.get(key);
    if (f != null) {
        if (f.cancel(false)) {
            ScheduledFuture f2 = expiryExecutor.schedule(new ExpiryTask(cache, key), newExpTime, TimeUnit.SECONDS);
            expiryFutures.put(key, f2);
            return true;
        }
    }
    return false;
}
Also used : ScheduledFuture(java.util.concurrent.ScheduledFuture)

Aggregations

ScheduledFuture (java.util.concurrent.ScheduledFuture)85 Test (org.junit.Test)27 Date (java.util.Date)10 DelegatingScheduledFutureStripper (com.hazelcast.scheduledexecutor.impl.DelegatingScheduledFutureStripper)9 ParallelTest (com.hazelcast.test.annotation.ParallelTest)9 QuickTest (com.hazelcast.test.annotation.QuickTest)9 IOException (java.io.IOException)8 Map (java.util.Map)7 ScheduledExecutorService (java.util.concurrent.ScheduledExecutorService)7 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 Future (java.util.concurrent.Future)4 ScheduledThreadPoolExecutor (java.util.concurrent.ScheduledThreadPoolExecutor)4