當前位置: 首頁>>代碼示例>>Java>>正文


Java EventExecutor.schedule方法代碼示例

本文整理匯總了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);
}
 
開發者ID:projectsrepos,項目名稱:jim,代碼行數:19,代碼來源:AutoFlushHandler.java

示例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);
}
 
開發者ID:line,項目名稱:centraldogma,代碼行數:8,代碼來源:Polyfills.java

示例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);
    }
}
 
開發者ID:wuyinxian124,項目名稱:netty4.0.27Learn,代碼行數:31,代碼來源:IdleStateHandler.java

示例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);
}
 
開發者ID:line,項目名稱:armeria,代碼行數:42,代碼來源:RequestContextTest.java


注:本文中的io.netty.util.concurrent.EventExecutor.schedule方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。