本文整理了Java中io.netty.util.concurrent.ScheduledFuture.isDone()
方法的一些代码示例,展示了ScheduledFuture.isDone()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ScheduledFuture.isDone()
方法的具体详情如下:
包路径:io.netty.util.concurrent.ScheduledFuture
类名称:ScheduledFuture
方法名:isDone
暂无
代码示例来源:origin: yu199195/Raincat
if (!schedule.isDone()) {
schedule.cancel(false);
代码示例来源:origin: com.github.msemys/esjc
private boolean isRunning() {
return timer != null && !timer.isDone();
}
代码示例来源:origin: msemys/esjc
private boolean isRunning() {
return timer != null && !timer.isDone();
}
代码示例来源:origin: com.nike.riposte/riposte-core
@Override
public PipelineContinuationBehavior doChannelActive(ChannelHandlerContext ctx) throws Exception {
// New channel opening. See if we have too many open channels.
int actualOpenChannelsCount = openChannelsGroup.size();
if (actualOpenChannelsCount >= maxOpenChannelsThreshold) {
Channel channel = ctx.channel();
// Mark this channel as needing to be closed.
ctx.channel().attr(TOO_MANY_OPEN_CONNECTIONS_THIS_CHANNEL_SHOULD_CLOSE).set(actualOpenChannelsCount);
// Schedule a double-check event to make sure the channel gets closed.
ScheduledFuture doubleCheckScheduledFuture = ctx.channel().eventLoop().schedule(() -> {
if (channel.isOpen())
channel.close();
}, 100, TimeUnit.MILLISECONDS);
// Add a channel close future listener to cancel the double-check scheduled event immediately if the channel
// is closed quickly. Even though the double-check event will execute in 100 milliseconds that's 100
// milliseconds of potential garbage accumulating when it shouldn't. Could be a lot for a high traffic
// server (which this likely is if the open channels limit is being hit).
channel.closeFuture().addListener(future -> {
if (!doubleCheckScheduledFuture.isDone())
doubleCheckScheduledFuture.cancel(false);
});
}
else {
// Not at the threshold. Add this channel to the open channel group.
openChannelsGroup.add(ctx.channel());
}
return PipelineContinuationBehavior.CONTINUE;
}
代码示例来源:origin: Nike-Inc/riposte
@Override
public PipelineContinuationBehavior doChannelActive(ChannelHandlerContext ctx) throws Exception {
// New channel opening. See if we have too many open channels.
int actualOpenChannelsCount = openChannelsGroup.size();
if (actualOpenChannelsCount >= maxOpenChannelsThreshold) {
Channel channel = ctx.channel();
// Mark this channel as needing to be closed.
ctx.channel().attr(TOO_MANY_OPEN_CONNECTIONS_THIS_CHANNEL_SHOULD_CLOSE).set(actualOpenChannelsCount);
// Schedule a double-check event to make sure the channel gets closed.
ScheduledFuture doubleCheckScheduledFuture = ctx.channel().eventLoop().schedule(() -> {
if (channel.isOpen())
channel.close();
}, 100, TimeUnit.MILLISECONDS);
// Add a channel close future listener to cancel the double-check scheduled event immediately if the channel
// is closed quickly. Even though the double-check event will execute in 100 milliseconds that's 100
// milliseconds of potential garbage accumulating when it shouldn't. Could be a lot for a high traffic
// server (which this likely is if the open channels limit is being hit).
channel.closeFuture().addListener(future -> {
if (!doubleCheckScheduledFuture.isDone())
doubleCheckScheduledFuture.cancel(false);
});
}
else {
// Not at the threshold. Add this channel to the open channel group.
openChannelsGroup.add(ctx.channel());
}
return PipelineContinuationBehavior.CONTINUE;
}
代码示例来源:origin: Nike-Inc/riposte
private void verifyCloseFutureListener(GenericFutureListener closeFutureListener) throws Exception {
// If the double-check ScheduledFuture is not done then it cancels it.
reset(doubleCheckScheduledFutureMock);
doReturn(false).when(doubleCheckScheduledFutureMock).isDone();
closeFutureListener.operationComplete(null);
verify(doubleCheckScheduledFutureMock).isDone();
verify(doubleCheckScheduledFutureMock).cancel(false);
verifyNoMoreInteractions(doubleCheckScheduledFutureMock);
// And when the double-check ScheduledFuture is done, then nothing happens.
reset(doubleCheckScheduledFutureMock);
doReturn(true).when(doubleCheckScheduledFutureMock).isDone();
closeFutureListener.operationComplete(null);
verify(doubleCheckScheduledFutureMock).isDone();
verifyNoMoreInteractions(doubleCheckScheduledFutureMock);
}
代码示例来源:origin: Nike-Inc/riposte
@Test
public void doChannelRead_does_nothing_to_timeout_check_if_timeout_check_is_already_completed_when_response_completes() throws Exception {
// given
ScheduledFuture timeoutCheckMock = mock(ScheduledFuture.class);
doReturn(timeoutCheckMock).when(eventLoopMock).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));
handlerSpy.doChannelRead(ctxMock, msg);
ArgumentCaptor<BiConsumer> timeoutCheckCancellationLogicArgumentCaptor = ArgumentCaptor.forClass(BiConsumer.class);
// The 2nd whenComplete is for cancelling the timeout check if the response finishes before the timeout
verify(futureThatWillBeAttachedToSpy, times(2)).whenComplete(timeoutCheckCancellationLogicArgumentCaptor.capture());
BiConsumer<ResponseInfo<?>, Throwable> timeoutCheckCancellationLogic = timeoutCheckCancellationLogicArgumentCaptor.getAllValues().get(1);
// when: the timeout check scheduled future is already done
doReturn(true).when(timeoutCheckMock).isDone();
timeoutCheckCancellationLogic.accept(mock(ResponseInfo.class), null);
// then: nothing should be done
verify(timeoutCheckMock).isDone();
verify(timeoutCheckMock, times(0)).cancel(any(Boolean.class));
verifyNoMoreInteractions(timeoutCheckMock);
}
代码示例来源:origin: Nike-Inc/riposte
@Test
public void doChannelRead_cancels_timeout_check_if_response_finishes_before_timeout_check_occurs() throws Exception {
// given
ScheduledFuture timeoutCheckMock = mock(ScheduledFuture.class);
doReturn(timeoutCheckMock).when(eventLoopMock).schedule(any(Runnable.class), any(Long.class), any(TimeUnit.class));
handlerSpy.doChannelRead(ctxMock, msg);
ArgumentCaptor<BiConsumer> timeoutCheckCancellationLogicArgumentCaptor = ArgumentCaptor.forClass(BiConsumer.class);
// The 2nd whenComplete is for cancelling the timeout check if the response finishes before the timeout
verify(futureThatWillBeAttachedToSpy, times(2)).whenComplete(timeoutCheckCancellationLogicArgumentCaptor.capture());
BiConsumer<ResponseInfo<?>, Throwable> timeoutCheckCancellationLogic = timeoutCheckCancellationLogicArgumentCaptor.getAllValues().get(1);
// when: the timeout check scheduled future is not yet complete when the response finishes
doReturn(false).when(timeoutCheckMock).isDone();
timeoutCheckCancellationLogic.accept(mock(ResponseInfo.class), null);
// then: timeout check scheduled future should be cancelled
verify(timeoutCheckMock).cancel(false);
}
代码示例来源:origin: Nike-Inc/riposte
@Before
public void beforeMethod() {
channelMock = mock(Channel.class);
ctxMock = mock(ChannelHandlerContext.class);
tooManyOpenConnectionsAttributeMock = mock(Attribute.class);
doReturn(channelMock).when(ctxMock).channel();
doReturn(tooManyOpenConnectionsAttributeMock).when(channelMock)
.attr(TOO_MANY_OPEN_CONNECTIONS_THIS_CHANNEL_SHOULD_CLOSE);
doReturn(true).when(channelMock).isOpen();
eventLoopMock = mock(EventLoop.class);
closeFutureMock = mock(ChannelFuture.class);
doReturn(eventLoopMock).when(channelMock).eventLoop();
doReturn(closeFutureMock).when(channelMock).closeFuture();
doubleCheckScheduledFutureMock = mock(ScheduledFuture.class);
doubleCheckRunnableCaptor = ArgumentCaptor.forClass(Runnable.class);
closeFutureListenerCaptor = ArgumentCaptor.forClass(GenericFutureListener.class);
doReturn(doubleCheckScheduledFutureMock).when(eventLoopMock)
.schedule(any(Runnable.class), anyLong(), any(TimeUnit.class));
doReturn(false).when(doubleCheckScheduledFutureMock).isDone();
channelGroupMock = mock(ChannelGroup.class);
maxOpenChannelsThreshold = 42;
handler = new OpenChannelLimitHandler(channelGroupMock, maxOpenChannelsThreshold);
}
代码示例来源:origin: com.nike.riposte/riposte-core
if (!responseTimeoutScheduledFuture.isDone())
responseTimeoutScheduledFuture.cancel(false);
});
代码示例来源:origin: Nike-Inc/riposte
if (!responseTimeoutScheduledFuture.isDone())
responseTimeoutScheduledFuture.cancel(false);
});
代码示例来源:origin: keets2012/Lottor
if (!schedule.isDone()) {
schedule.cancel(false);
内容来源于网络,如有侵权,请联系作者删除!