本文整理匯總了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);
}