当前位置: 首页>>代码示例>>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;未经允许,请勿转载。