use of java.util.concurrent.ScheduledFuture in project uPortal by Jasig.
the class DelegatingThreadPoolTaskScheduler method scheduleWithFixedDelay.
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, Date startTime, long delay) {
task = wrapRunnable(task);
// Add scheduled task delay
startTime = getDelayedStartDate(startTime);
// Add period to inital run time
startTime = new Date(startTime.getTime() + delay);
final DelegatingRunnable delegatingRunnable = new DelegatingRunnable(this.executorService, task);
@SuppressWarnings("unchecked") final ScheduledFuture<?> future = super.scheduleWithFixedDelay(delegatingRunnable, startTime, delay);
return (ScheduledFuture<ScheduledFuture<?>>) new DelegatingForwardingScheduledFuture(future);
}
use of java.util.concurrent.ScheduledFuture in project uPortal by Jasig.
the class DelegatingThreadPoolTaskScheduler method scheduleWithFixedDelay.
@Override
public ScheduledFuture<?> scheduleWithFixedDelay(Runnable task, long delay) {
task = wrapRunnable(task);
final long additionalStartDelay = this.getAdditionalStartDelay();
if (additionalStartDelay > 0) {
// If there is an additional delay use the alternate call which includes a startTime
return this.scheduleWithFixedDelay(task, new Date(), delay);
}
final DelegatingRunnable delegatingRunnable = new DelegatingRunnable(this.executorService, task);
@SuppressWarnings("unchecked") final ScheduledFuture<?> future = super.scheduleWithFixedDelay(delegatingRunnable, delay);
return (ScheduledFuture<ScheduledFuture<?>>) new DelegatingForwardingScheduledFuture(future);
}
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);
}
use of java.util.concurrent.ScheduledFuture in project spring-boot-admin by codecentric.
the class RegistrationApplicationListenerTest method test_no_register_after_close.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_no_register_after_close() throws Exception {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
ScheduledFuture task = mock(ScheduledFuture.class);
when(scheduler.scheduleAtFixedRate(isA(Runnable.class), eq(10_000L))).thenReturn(task);
listener.onApplicationReady(new ApplicationReadyEvent(mock(SpringApplication.class), null, mock(ConfigurableWebApplicationContext.class)));
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
listener.onClosedContext(new ContextClosedEvent(mock(EmbeddedWebApplicationContext.class)));
verify(task).cancel(true);
}
use of java.util.concurrent.ScheduledFuture in project spring-boot-admin by codecentric.
the class RegistrationApplicationListenerTest method test_start_stop.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void test_start_stop() throws Exception {
ApplicationRegistrator registrator = mock(ApplicationRegistrator.class);
TaskScheduler scheduler = mock(TaskScheduler.class);
RegistrationApplicationListener listener = new RegistrationApplicationListener(registrator, scheduler);
ScheduledFuture task = mock(ScheduledFuture.class);
when(scheduler.scheduleAtFixedRate(isA(Runnable.class), eq(10_000L))).thenReturn(task);
listener.startRegisterTask();
verify(scheduler).scheduleAtFixedRate(isA(Runnable.class), eq(10_000L));
listener.stopRegisterTask();
verify(task).cancel(true);
}
Aggregations