本文整理汇总了Java中io.netty.util.Timer.newTimeout方法的典型用法代码示例。如果您正苦于以下问题:Java Timer.newTimeout方法的具体用法?Java Timer.newTimeout怎么用?Java Timer.newTimeout使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.Timer
的用法示例。
在下文中一共展示了Timer.newTimeout方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testTryWithResourcesShouldCloseAllClustersButNotTimerIfProvided
import io.netty.util.Timer; //导入方法依赖的package包/类
@Test
public void testTryWithResourcesShouldCloseAllClustersButNotTimerIfProvided() throws Exception {
EventLoopGroup eventLoop;
Timer timer = new HashedWheelTimer();
try (Server server = Server.builder().withTimer(timer).build()) {
// Do nothing here, since this is a unit test, we don't want to create any inet sockets
// which is what Server does by default.
eventLoop = server.eventLoopGroup;
}
// event loop should have been closed since a custom one was not provided.
assertThat(eventLoop.isShutdown()).isTrue();
// timer should not have been closed since a custom one was provided.
timer.newTimeout(
timeout -> {
// noop
},
1,
TimeUnit.SECONDS);
timer.stop();
}
示例2: testTryWithResourcesShouldCloseAllResources
import io.netty.util.Timer; //导入方法依赖的package包/类
@Test
public void testTryWithResourcesShouldCloseAllResources() throws Exception {
EventLoopGroup eventLoop;
Timer timer;
try (Server server = Server.builder().build()) {
// Do nothing here, since this is a unit test, we don't want to create any inet sockets
// which is what Server does by default.
eventLoop = server.eventLoopGroup;
timer = server.timer;
}
// event loop should have been closed since a custom one was not provided.
assertThat(eventLoop.isShutdown()).isTrue();
// timer should have since a custom one was not provided.
try {
timer.newTimeout(
timeout -> {
// noop
},
1,
TimeUnit.SECONDS);
fail("Expected IllegalStateException");
} catch (IllegalStateException ise) {
// expected
}
}
示例3: tryInterruptInterruptsWaitingThreads
import io.netty.util.Timer; //导入方法依赖的package包/类
@Test(expected = InterruptedException.class)
public void tryInterruptInterruptsWaitingThreads() throws Exception {
final InterruptingSemaphore interruptingSemaphore = new InterruptingSemaphore(0);
final Timer timer = new HashedWheelTimer();
timer.newTimeout(new TimerTask() {
@Override
public void run(Timeout timeout) throws Exception {
interruptingSemaphore.tryInterrupt();
}
}, 10, TimeUnit.MILLISECONDS);
interruptingSemaphore.acquire();
}
示例4: init
import io.netty.util.Timer; //导入方法依赖的package包/类
/**
* Initialization for plugin called by the OFSwitchHandshakeHandler
*
* @param state the current state of the OFSwitchHandshakeHandler
* @param sw the current switch of the OFSwitchHandshakeHandler
*/
final void init(WaitAppHandshakeState state, IOFSwitch sw, Timer timer) {
this.state = state;
this.sw = sw;
this.timeout = timer.newTimeout(new PluginTimeoutTask(), timeoutS, TimeUnit.SECONDS);
}