use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.
the class DelegatingScheduledFutureStripperTest method cancel.
@Test
public void cancel() throws ExecutionException, InterruptedException {
ScheduledFuture outter = mock(ScheduledFuture.class);
ScheduledFuture inner = mock(ScheduledFuture.class);
when(outter.get()).thenReturn(inner);
new DelegatingScheduledFutureStripper(outter).cancel(true);
verify(inner).cancel(eq(true));
}
use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.
the class DelegatingScheduledFutureStripperTest method cancel_twice.
@Test
public void cancel_twice() throws ExecutionException, InterruptedException, TimeoutException {
ScheduledFuture original = taskScheduler.schedule(new SimpleCallableTestTask(), 10, TimeUnit.SECONDS);
ScheduledFuture stripper = new DelegatingScheduledFutureStripper(original);
stripper.cancel(true);
stripper.cancel(true);
}
use of java.util.concurrent.ScheduledFuture in project jdk8u_jdk by JetBrains.
the class LdapTimeoutTest method call.
public Boolean call() {
InitialContext ctx = null;
ScheduledFuture killer = null;
long start = System.nanoTime();
try {
while (!server.accepting()) // allow the server to start up
Thread.sleep(200);
// to be sure
Thread.sleep(200);
// interrupt after a certain time
if (killSwitchPool != null) {
final Thread current = Thread.currentThread();
killer = killSwitchPool.schedule(new Callable<Void>() {
public Void call() throws Exception {
current.interrupt();
return null;
}
}, HANGING_TEST_TIMEOUT, MILLISECONDS);
}
env.put(Context.PROVIDER_URL, "ldap://localhost:" + server.getLocalPort());
try {
ctx = new InitialDirContext(env);
performOp(ctx);
fail();
} catch (NamingException e) {
long end = System.nanoTime();
System.out.println(this.getClass().toString() + " - elapsed: " + NANOSECONDS.toMillis(end - start));
handleNamingException(e, start, end);
} finally {
if (killer != null && !killer.isDone())
killer.cancel(true);
shutItDown(ctx);
server.close();
}
return passed;
} catch (IOException | InterruptedException e) {
throw new RuntimeException(e);
}
}
use of java.util.concurrent.ScheduledFuture in project geode by apache.
the class QueueManagerImpl method scheduleRedundancySatisfierIfNeeded.
protected void scheduleRedundancySatisfierIfNeeded(long delay) {
if (shuttingDown) {
return;
}
synchronized (lock) {
if (shuttingDown) {
return;
}
if (queueConnections.getPrimary() == null || getCurrentRedundancy() < redundancyLevel || redundancyLevel == -1 || queueConnections.primaryDiscoveryFailed()) {
if (redundancySatisfierTask != null) {
if (redundancySatisfierTask.getRemainingDelay() > delay) {
redundancySatisfierTask.cancel();
} else {
return;
}
}
redundancySatisfierTask = new RedundancySatisfierTask();
try {
ScheduledFuture future = recoveryThread.schedule(redundancySatisfierTask, delay, TimeUnit.MILLISECONDS);
redundancySatisfierTask.setFuture(future);
} catch (RejectedExecutionException e) {
// ignore, the timer has been cancelled, which means we're shutting down.
}
}
}
}
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;
}
Aggregations