use of java.util.concurrent.ScheduledFuture in project spring-framework by spring-projects.
the class WebSocketStompClientTests method cancelInactivityTasks.
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void cancelInactivityTasks() throws Exception {
TcpConnection<byte[]> tcpConnection = getTcpConnection();
ScheduledFuture future = mock(ScheduledFuture.class);
when(this.taskScheduler.scheduleWithFixedDelay(any(), eq(1L))).thenReturn(future);
tcpConnection.onReadInactivity(mock(Runnable.class), 2L);
tcpConnection.onWriteInactivity(mock(Runnable.class), 2L);
this.webSocketHandlerCaptor.getValue().afterConnectionClosed(this.webSocketSession, CloseStatus.NORMAL);
verify(future, times(2)).cancel(true);
verifyNoMoreInteractions(future);
}
use of java.util.concurrent.ScheduledFuture in project otter by alibaba.
the class MonitorScheduler method register.
/**
* 注册对应的Monitor对象
*
* @param monitor
* @param period 调度周期,单位ms
*/
public static void register(final Monitor monitor, Long delay, Long period) {
ScheduledFuture future = scheduler.scheduleAtFixedRate(new Runnable() {
public void run() {
monitor.reload();
}
}, delay, period, TimeUnit.MILLISECONDS);
register.put(monitor, future);
}
use of java.util.concurrent.ScheduledFuture in project cassandra by apache.
the class StreamTransferTask method complete.
/**
* Received ACK for file at {@code sequenceNumber}.
*
* @param sequenceNumber sequence number of file
*/
public void complete(int sequenceNumber) {
boolean signalComplete;
synchronized (this) {
ScheduledFuture timeout = timeoutTasks.remove(sequenceNumber);
if (timeout != null)
timeout.cancel(false);
OutgoingFileMessage file = files.remove(sequenceNumber);
if (file != null)
file.complete();
signalComplete = files.isEmpty();
}
// all file sent, notify session this task is complete.
if (signalComplete)
session.taskCompleted(this);
}
use of java.util.concurrent.ScheduledFuture in project commons by twitter.
the class LowResClockTest method testLowResClock.
@Test
public void testLowResClock() {
final WaitingFakeClock clock = new WaitingFakeClock();
final long start = clock.nowMillis();
ScheduledExecutorService mockExecutor = createMock(ScheduledExecutorService.class);
final Capture<Runnable> runnable = new Capture<Runnable>();
final Capture<Long> period = new Capture<Long>();
mockExecutor.scheduleAtFixedRate(capture(runnable), anyLong(), captureLong(period), eq(TimeUnit.MILLISECONDS));
expectLastCall().andAnswer(new IAnswer<ScheduledFuture<?>>() {
public ScheduledFuture<?> answer() {
final Thread ticker = new Thread() {
@Override
public void run() {
Tick tick = new Tick(clock, start, period.getValue(), runnable.getValue());
try {
while (true) {
clock.doOnAdvance(tick);
}
} catch (InterruptedException e) {
/* terminate */
}
}
};
ticker.setDaemon(true);
ticker.start();
final ScheduledFuture<?> future = createMock(ScheduledFuture.class);
final AtomicBoolean stopped = new AtomicBoolean(false);
expect(future.isCancelled()).andAnswer(new IAnswer<Boolean>() {
@Override
public Boolean answer() throws Throwable {
return stopped.get();
}
}).anyTimes();
expect(future.cancel(anyBoolean())).andAnswer(new IAnswer<Boolean>() {
@Override
public Boolean answer() throws Throwable {
ticker.interrupt();
stopped.set(true);
return true;
}
});
replay(future);
return future;
}
});
replay(mockExecutor);
LowResClock lowRes = new LowResClock(Amount.of(1L, Time.SECONDS), mockExecutor, clock);
long t = lowRes.nowMillis();
clock.advance(Amount.of(100L, Time.MILLISECONDS));
assertEquals(t, lowRes.nowMillis());
clock.advance(Amount.of(900L, Time.MILLISECONDS));
assertEquals(t + 1000, lowRes.nowMillis());
clock.advance(Amount.of(100L, Time.MILLISECONDS));
assertEquals(t + 1000, lowRes.nowMillis());
lowRes.close();
try {
lowRes.nowMillis();
fail("Closed clock should throw exception!");
} catch (IllegalStateException e) {
/* expected */
}
}
use of java.util.concurrent.ScheduledFuture in project hazelcast by hazelcast.
the class DefaultNearCacheManager method destroyAllNearCaches.
@Override
public void destroyAllNearCaches() {
for (NearCache nearCache : new HashSet<NearCache>(nearCacheMap.values())) {
nearCacheMap.remove(nearCache.getName());
nearCache.destroy();
}
for (ScheduledFuture preloadTaskFuture : preloadTaskFutures) {
preloadTaskFuture.cancel(true);
}
if (storageTaskFuture != null) {
storageTaskFuture.cancel(true);
}
}
Aggregations