本文整理汇总了Java中io.netty.util.concurrent.EventExecutor.schedule方法的典型用法代码示例。如果您正苦于以下问题:Java EventExecutor.schedule方法的具体用法?Java EventExecutor.schedule怎么用?Java EventExecutor.schedule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.netty.util.concurrent.EventExecutor
的用法示例。
在下文中一共展示了EventExecutor.schedule方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: initialize
import io.netty.util.concurrent.EventExecutor; //导入方法依赖的package包/类
private void initialize(ChannelHandlerContext ctx) {
// Avoid the case where destroy() is called before scheduling timeouts.
// See: https://github.com/netty/netty/issues/143
switch (state) {
case 1:
case 2:
return;
}
state = 1;
EventExecutor loop = ctx.executor();
lastWriteTime = System.nanoTime();
writerIdleTimeout = loop.schedule(
new WriterIdleTimeoutTask(ctx),
writerIdleTimeNanos, TimeUnit.NANOSECONDS);
}
示例2: setTimeout
import io.netty.util.concurrent.EventExecutor; //导入方法依赖的package包/类
public static Future<?> setTimeout(EventExecutor executor, Runnable task, long delay) {
if (delay <= 0) {
return executor.submit(task);
}
return executor.schedule(task, delay, TimeUnit.MILLISECONDS);
}
示例3: initialize
import io.netty.util.concurrent.EventExecutor; //导入方法依赖的package包/类
private void initialize(ChannelHandlerContext ctx) {
// Avoid the case where destroy() is called before scheduling timeouts.
// See: https://github.com/netty/netty/issues/143
switch (state) {
case 1:
case 2:
return;
}
state = 1;
EventExecutor loop = ctx.executor();
lastReadTime = lastWriteTime = System.nanoTime();
if (readerIdleTimeNanos > 0) {
readerIdleTimeout = loop.schedule(
new ReaderIdleTimeoutTask(ctx),
readerIdleTimeNanos, TimeUnit.NANOSECONDS);
}
if (writerIdleTimeNanos > 0) {
writerIdleTimeout = loop.schedule(
new WriterIdleTimeoutTask(ctx),
writerIdleTimeNanos, TimeUnit.NANOSECONDS);
}
if (allIdleTimeNanos > 0) {
allIdleTimeout = loop.schedule(
new AllIdleTimeoutTask(ctx),
allIdleTimeNanos, TimeUnit.NANOSECONDS);
}
}
示例4: contextAwareEventExecutor
import io.netty.util.concurrent.EventExecutor; //导入方法依赖的package包/类
@Test
public void contextAwareEventExecutor() throws Exception {
when(channel.eventLoop()).thenReturn(eventLoop);
RequestContext context = createContext();
Set<Integer> callbacksCalled = Collections.newSetFromMap(new ConcurrentHashMap<>());
EventExecutor executor = context.contextAwareEventLoop();
CountDownLatch latch = new CountDownLatch(18);
executor.execute(() -> checkCallback(1, context, callbacksCalled, latch));
executor.schedule(() -> checkCallback(2, context, callbacksCalled, latch), 0, TimeUnit.SECONDS);
executor.schedule(() -> {
checkCallback(2, context, callbacksCalled, latch);
return "success";
}, 0, TimeUnit.SECONDS);
executor.scheduleAtFixedRate(() -> checkCallback(3, context, callbacksCalled, latch), 0, 1000,
TimeUnit.SECONDS);
executor.scheduleWithFixedDelay(() -> checkCallback(4, context, callbacksCalled, latch), 0, 1000,
TimeUnit.SECONDS);
executor.submit(() -> checkCallback(5, context, callbacksCalled, latch));
executor.submit(() -> checkCallback(6, context, callbacksCalled, latch), "success");
executor.submit(() -> {
checkCallback(7, context, callbacksCalled, latch);
return "success";
});
executor.invokeAll(makeTaskList(8, 10, context, callbacksCalled, latch));
executor.invokeAll(makeTaskList(11, 12, context, callbacksCalled, latch), 10000, TimeUnit.SECONDS);
executor.invokeAny(makeTaskList(13, 13, context, callbacksCalled, latch));
executor.invokeAny(makeTaskList(14, 14, context, callbacksCalled, latch), 10000, TimeUnit.SECONDS);
Promise<String> promise = executor.newPromise();
promise.addListener(f -> checkCallback(15, context, callbacksCalled, latch));
promise.setSuccess("success");
executor.newSucceededFuture("success")
.addListener(f -> checkCallback(16, context, callbacksCalled, latch));
executor.newFailedFuture(new IllegalArgumentException())
.addListener(f -> checkCallback(17, context, callbacksCalled, latch));
ProgressivePromise<String> progressivePromise = executor.newProgressivePromise();
progressivePromise.addListener(f -> checkCallback(18, context, callbacksCalled, latch));
progressivePromise.setSuccess("success");
latch.await();
eventLoop.shutdownGracefully().sync();
assertThat(callbacksCalled).containsExactlyElementsOf(IntStream.rangeClosed(1, 18).boxed()::iterator);
}