use of java.util.concurrent.ScheduledFuture in project samza by apache.
the class ScheduleAfterDebounceTime method scheduleAfterDebounceTime.
public synchronized void scheduleAfterDebounceTime(String actionName, long debounceTimeMs, Runnable runnable) {
// check if this action has been scheduled already
ScheduledFuture sf = futureHandles.get(actionName);
if (sf != null && !sf.isDone()) {
LOG.info("cancel future for " + actionName);
// attempt to cancel
if (!sf.cancel(false)) {
try {
sf.get(TIMEOUT_MS, TimeUnit.MILLISECONDS);
} catch (Exception e) {
// we ignore the exception
LOG.warn("cancel for action " + actionName + " failed with ", e);
}
}
futureHandles.remove(actionName);
}
// schedule a new task
sf = scheduledExecutorService.schedule(() -> {
try {
runnable.run();
LOG.debug(actionName + " completed successfully.");
} catch (Throwable t) {
LOG.error(actionName + " threw an exception.", t);
if (scheduledTaskFailureCallback != null) {
scheduledTaskFailureCallback.onError(t);
}
}
}, debounceTimeMs, TimeUnit.MILLISECONDS);
LOG.info("scheduled " + actionName + " in " + debounceTimeMs);
futureHandles.put(actionName, sf);
}
use of java.util.concurrent.ScheduledFuture in project samza by apache.
the class TaskCallbackManager method createCallback.
public TaskCallbackImpl createCallback(TaskName taskName, IncomingMessageEnvelope envelope, ReadableCoordinator coordinator) {
final TaskCallbackImpl callback = new TaskCallbackImpl(listener, taskName, envelope, coordinator, seqNum++, clock.nanoTime());
if (timer != null) {
Runnable timerTask = new Runnable() {
@Override
public void run() {
String msg = "Task " + callback.taskName + " callback times out";
callback.failure(new TaskCallbackTimeoutException(msg));
}
};
ScheduledFuture scheduledFuture = timer.schedule(timerTask, timeout, TimeUnit.MILLISECONDS);
callback.setScheduledFuture(scheduledFuture);
}
return callback;
}
use of java.util.concurrent.ScheduledFuture in project tomee by apache.
the class ManagedScheduledExecutorServiceImpl method scheduleWithFixedDelay.
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(final Runnable command, final long initialDelay, final long delay, final TimeUnit unit) {
final CURunnable wrapper = new CURunnable(command);
final ScheduledFuture<?> future = delegate.scheduleWithFixedDelay(wrapper, initialDelay, delay, unit);
wrapper.taskSubmitted(future, this, command);
return new CUScheduleFuture<Object>(ScheduledFuture.class.cast(future), wrapper);
}
Aggregations