Search in sources :

Example 41 with ScheduledFuture

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);
}
Also used : Date(java.util.Date) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 42 with ScheduledFuture

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);
}
Also used : Date(java.util.Date) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 43 with ScheduledFuture

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);
}
Also used : CURunnable(org.apache.openejb.threads.task.CURunnable) CUScheduleFuture(org.apache.openejb.threads.future.CUScheduleFuture) ScheduledFuture(java.util.concurrent.ScheduledFuture)

Example 44 with ScheduledFuture

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);
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) ApplicationReadyEvent(org.springframework.boot.context.event.ApplicationReadyEvent) TaskScheduler(org.springframework.scheduling.TaskScheduler) ScheduledFuture(java.util.concurrent.ScheduledFuture) ContextClosedEvent(org.springframework.context.event.ContextClosedEvent) Test(org.junit.Test)

Example 45 with ScheduledFuture

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);
}
Also used : RegistrationApplicationListener(de.codecentric.boot.admin.client.registration.RegistrationApplicationListener) ApplicationRegistrator(de.codecentric.boot.admin.client.registration.ApplicationRegistrator) TaskScheduler(org.springframework.scheduling.TaskScheduler) ScheduledFuture(java.util.concurrent.ScheduledFuture) Test(org.junit.Test)

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