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;
}
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;
}
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;
}
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);
}
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;
}
Aggregations