当前位置: 首页>>代码示例>>Java>>正文


Java EventLoop类代码示例

本文整理汇总了Java中io.netty.channel.EventLoop的典型用法代码示例。如果您正苦于以下问题:Java EventLoop类的具体用法?Java EventLoop怎么用?Java EventLoop使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EventLoop类属于io.netty.channel包,在下文中一共展示了EventLoop类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: scheduleTimeout

import io.netty.channel.EventLoop; //导入依赖的package包/类
private <T> void scheduleTimeout(CompletableFuture<T> result, long timeoutMillis) {
    pendingFutures.add(result);
    if (isServerStopping()) {
        pendingFutures.remove(result);
        return;
    }

    final ScheduledFuture<?> timeoutFuture;
    if (timeoutMillis > 0) {
        final EventLoop eventLoop = RequestContext.current().eventLoop();
        timeoutFuture = eventLoop.schedule(() -> result.completeExceptionally(CANCELLATION_EXCEPTION),
                                           timeoutMillis, TimeUnit.MILLISECONDS);
    } else {
        timeoutFuture = null;
    }

    result.whenComplete((revision, cause) -> {
        if (timeoutFuture != null) {
            timeoutFuture.cancel(true);
        }
        pendingFutures.remove(result);
    });
}
 
开发者ID:line,项目名称:centraldogma,代码行数:24,代码来源:WatchService.java

示例2: mapToThread

import io.netty.channel.EventLoop; //导入依赖的package包/类
private EventLoop mapToThread(int affinity, HandlerRegistration handler) {
    EventLoopGroup group;

    // Check if a dedicated thread pool is defined for this protocol.
    if (handler.config().getEventLoop() == null) {
        // Use core thread pool.
        group = coreEventLoopGroup;
    } else {
        // Use dedicated thread pool.
        group = handler.config().getEventLoop();
    }

    List<EventLoop> eventLoops = new ArrayList<>();

    // Assumes that the same group always returns its event loops in the same order.
    for (Iterator<EventExecutor> it = group.iterator(); it.hasNext(); ) {
        eventLoops.add((EventLoop)it.next());
    }

    return eventLoops.get(Utils.mod(affinity, eventLoops.size()));
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:22,代码来源:NettyServerClient.java

示例3: runAtAllCost

import io.netty.channel.EventLoop; //导入依赖的package包/类
/**
 * Executes the task using the provided event loop or falls back to {@link AsyncUtils#fallbackExecutor()} if event loop is {@link
 * EventLoop#isShuttingDown() shut down}.
 *
 * @param eventLoop Event loop.
 * @param task Task.
 */
public static void runAtAllCost(EventLoop eventLoop, Runnable task) {
    assert eventLoop != null : "Event loop is null.";
    assert task != null : "Task is null.";

    boolean notified = false;

    // Try to execute via event loop.
    if (!eventLoop.isShuttingDown()) {
        try {
            eventLoop.execute(task);

            notified = true;
        } catch (RejectedExecutionException e) {
            // No-op.
        }
    }

    // If couldn't notify via event loop then use the fallback executor.
    if (!notified) {
        AsyncUtils.fallbackExecutor().execute(task);
    }
}
 
开发者ID:hekate-io,项目名称:hekate,代码行数:30,代码来源:NettyUtils.java

示例4: operationComplete

import io.netty.channel.EventLoop; //导入依赖的package包/类
@Override
public void operationComplete(ChannelFuture channelFuture) throws Exception {
    if (!channelFuture.isSuccess()) {
        channelFuture.channel().close();

        if (count.incrementAndGet() < MAX_RETRY) {
            final EventLoop loop = channelFuture.channel().eventLoop();

            loop.schedule(() -> {
                controller.connectRetry(this.ip, this.port, this);
            }, 1L, TimeUnit.SECONDS);
        } else {
            log.info("Connection to the ovsdb {}:{} failed",
                     this.ip.toString(), this.port.toString());
        }
    } else {
        handleNewNodeConnection(channelFuture.channel());
    }
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:Controller.java

示例5: AsyncCall

import io.netty.channel.EventLoop; //导入依赖的package包/类
/**
 * Constructor
 *
 * @param eventLoop           for call
 * @param connectId           connection id
 * @param md                  the method descriptor
 * @param param               parameters to send to Server
 * @param controller          controller for response
 * @param responseDefaultType the default response type
 */
public AsyncCall(EventLoop eventLoop, int connectId, Descriptors.MethodDescriptor md, Message
    param, PayloadCarryingRpcController controller, Message responseDefaultType,
    MetricsConnection.CallStats callStats) {
  super(eventLoop);

  this.id = connectId;

  this.method = md;
  this.param = param;
  this.controller = controller;
  this.responseDefaultType = responseDefaultType;

  this.startTime = EnvironmentEdgeManager.currentTime();
  this.rpcTimeout = controller.hasCallTimeout() ? controller.getCallTimeout() : 0;
  this.callStats = callStats;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:27,代码来源:AsyncCall.java

示例6: getCircuitBreaker

import io.netty.channel.EventLoop; //导入依赖的package包/类
protected Optional<CircuitBreaker<HttpResponse>> getCircuitBreaker(
    DownstreamRequestFirstChunkInfo downstreamReqFirstChunkInfo, ChannelHandlerContext ctx
) {
    if (downstreamReqFirstChunkInfo == null || downstreamReqFirstChunkInfo.disableCircuitBreaker)
        return Optional.empty();

    // Circuit breaking is enabled for this call. So we return the custom one specified or use the default one if a
    //      custom one is not specified.
    if (downstreamReqFirstChunkInfo.customCircuitBreaker.isPresent())
        return downstreamReqFirstChunkInfo.customCircuitBreaker;

    // No custom circuit breaker. Use the default for the given request's host.
    EventLoop nettyEventLoop = ctx.channel().eventLoop();
    CircuitBreaker<Integer> defaultStatusCodeCircuitBreaker = getDefaultHttpStatusCodeCircuitBreakerForKey(
        downstreamReqFirstChunkInfo.host, Optional.ofNullable(nettyEventLoop), Optional.ofNullable(nettyEventLoop)
    );
    return Optional.of(
        new CircuitBreakerDelegate<>(
            defaultStatusCodeCircuitBreaker,
            httpResponse -> (httpResponse == null ? null : httpResponse.getStatus().code())
        )
    );
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:24,代码来源:ProxyRouterEndpointExecutionHandler.java

示例7: getCircuitBreaker

import io.netty.channel.EventLoop; //导入依赖的package包/类
protected Optional<CircuitBreaker<Response>> getCircuitBreaker(RequestBuilderWrapper requestBuilderWrapper) {
    if (requestBuilderWrapper.disableCircuitBreaker)
        return Optional.empty();

    // Circuit breaking is enabled for this call. So we return the custom one specified or use the default one if a
    //      custom one is not specified.
    if (requestBuilderWrapper.customCircuitBreaker.isPresent())
        return requestBuilderWrapper.customCircuitBreaker;

    // No custom circuit breaker. Use the default for the given request's host.
    Uri uri = Uri.create(requestBuilderWrapper.url);
    String host = uri.getHost();
    EventLoop nettyEventLoop = requestBuilderWrapper.getCtx() == null
                               ? null
                               : requestBuilderWrapper.getCtx().channel().eventLoop();
    CircuitBreaker<Integer> defaultStatusCodeCircuitBreaker = getDefaultHttpStatusCodeCircuitBreakerForKey(
        host, Optional.ofNullable(nettyEventLoop), Optional.ofNullable(nettyEventLoop)
    );
    return Optional.of(
        new CircuitBreakerDelegate<>(
            defaultStatusCodeCircuitBreaker, response -> (response == null ? null : response.getStatusCode())
        )
    );
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:25,代码来源:AsyncHttpClientHelper.java

示例8: beforeMethod

import io.netty.channel.EventLoop; //导入依赖的package包/类
@Before
public void beforeMethod() {
    helperSpy = spy(new AsyncHttpClientHelper());
    channelMock = mock(Channel.class);
    ctxMock = mock(ChannelHandlerContext.class);
    stateAttributeMock = mock(Attribute.class);
    state = new HttpProcessingState();
    eventLoopMock = mock(EventLoop.class);
    signatureCalculator = mock(SignatureCalculator.class);
    doReturn(channelMock).when(ctxMock).channel();
    doReturn(stateAttributeMock).when(channelMock).attr(ChannelAttributes.HTTP_PROCESSING_STATE_ATTRIBUTE_KEY);
    doReturn(state).when(stateAttributeMock).get();
    doReturn(eventLoopMock).when(channelMock).eventLoop();

    handlerWithTracingAndMdcDummyExample = new AsyncCompletionHandlerWithTracingAndMdcSupport<>(
        null, null, false, null, null, null, null, null
    );

    resetTracingAndMdc();
}
 
开发者ID:Nike-Inc,项目名称:riposte,代码行数:21,代码来源:AsyncHttpClientHelperTest.java

示例9: dispatch

import io.netty.channel.EventLoop; //导入依赖的package包/类
/**
 * Dispatches an AddressedMessage to its target handler using an EventExecutor.
 *
 * @param msg AddressedMessage to dispatch.
 * @return {@code true} if the Message was forwarded to at least one MessageHandler.
 */
public boolean dispatch(final Message.AddressedMessage msg) {
    Set<MessageHandler> handlers = mappings.get(RoutingKey.forMessage(msg));
    final EventLoop executor = getEventLoop();
    Log.v(TAG, "DISPATCH " + msg + " to " + handlers + " using " + executor);
    for (final MessageHandler handler : handlers) {
        executor.submit(new Runnable() {
            @Override
            public void run() {
                try {
                    handler.handle(msg);
                } catch (Exception e) {
                    Log.e(TAG, "Handler " + handler + " crashed while handling message " + msg
                            + " with Exception " + Log.getStackTraceString(e));
                }
            }
        });
    }
    return !handlers.isEmpty();
}
 
开发者ID:SecureSmartHome,项目名称:SecureSmartHome,代码行数:26,代码来源:IncomingDispatcher.java

示例10: channelInactive

import io.netty.channel.EventLoop; //导入依赖的package包/类
@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
    LOG.info(">>> channelUnregistered");
    if (unrecognizedName) {
        LOG.info(">>> unrecognizedName retry");
        final EventLoop loop = ctx.channel().eventLoop();
        loop.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    client.retry(loop);
                } catch (InterruptedException e) {
                    LOG.info(">>> retry interrupted, shutdown");
                    client.stop();
                }
            }
        });
    } else {
        LOG.info(">>> shutdown sucessfully");
        client.stop();
    }
}
 
开发者ID:wxyzZ,项目名称:little_mitm,代码行数:23,代码来源:RetryClient.java

示例11: addAsync

import io.netty.channel.EventLoop; //导入依赖的package包/类
public Future<Boolean> addAsync(final V value) {
    EventLoop loop = commandExecutor.getConnectionManager().getGroup().next();
    final Promise<Boolean> promise = loop.newPromise();

    loop.execute(new Runnable() {
        @Override
        public void run() {
            try {
                boolean result = add(value);
                promise.setSuccess(result);
            } catch (Exception e) {
                promise.setFailure(e);
            }
        }
    });

    return promise;
}
 
开发者ID:rollenholt-SourceReading,项目名称:redisson,代码行数:19,代码来源:RedissonSortedSet.java

示例12: shutdownOutput

import io.netty.channel.EventLoop; //导入依赖的package包/类
@Override
public ChannelFuture shutdownOutput(final ChannelPromise future) {
    EventLoop loop = eventLoop();
    if (loop.inEventLoop()) {
        try {
            socket.shutdownOutput();
            future.setSuccess();
        } catch (Throwable t) {
            future.setFailure(t);
        }
    } else {
        loop.execute(new Runnable() {
            @Override
            public void run() {
                shutdownOutput(future);
            }
        });
    }
    return future;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:21,代码来源:OioSocketChannel.java

示例13: shutdownOutput

import io.netty.channel.EventLoop; //导入依赖的package包/类
@Override
public ChannelFuture shutdownOutput(final ChannelPromise promise) {
    Executor closeExecutor = ((NioSocketChannelUnsafe) unsafe()).closeExecutor();
    if (closeExecutor != null) {
        closeExecutor.execute(new OneTimeTask() {
            @Override
            public void run() {
                shutdownOutput0(promise);
            }
        });
    } else {
        EventLoop loop = eventLoop();
        if (loop.inEventLoop()) {
            shutdownOutput0(promise);
        } else {
            loop.execute(new OneTimeTask() {
                @Override
                public void run() {
                    shutdownOutput0(promise);
                }
            });
        }
    }
    return promise;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:NioSocketChannel.java

示例14: clearEpollIn

import io.netty.channel.EventLoop; //导入依赖的package包/类
final void clearEpollIn() {
    // Only clear if registered with an EventLoop as otherwise
    if (isRegistered()) {
        final EventLoop loop = eventLoop();
        final AbstractEpollUnsafe unsafe = (AbstractEpollUnsafe) unsafe();
        if (loop.inEventLoop()) {
            unsafe.clearEpollIn0();
        } else {
            // schedule a task to clear the EPOLLIN as it is not safe to modify it directly
            loop.execute(new OneTimeTask() {
                @Override
                public void run() {
                    if (!config().isAutoRead() && !unsafe.readPending) {
                        // Still no read triggered so clear it now
                        unsafe.clearEpollIn0();
                    }
                }
            });
        }
    } else  {
        // The EventLoop is not registered atm so just update the flags so the correct value
        // will be used once the channel is registered
        flags &= ~readFlag;
    }
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:AbstractEpollChannel.java

示例15: shutdownOutput

import io.netty.channel.EventLoop; //导入依赖的package包/类
@Override
public ChannelFuture shutdownOutput(final ChannelPromise promise) {
    Executor closeExecutor = ((EpollSocketChannelUnsafe) unsafe()).closeExecutor();
    if (closeExecutor != null) {
        closeExecutor.execute(new OneTimeTask() {
            @Override
            public void run() {
                shutdownOutput0(promise);
            }
        });
    } else {
        EventLoop loop = eventLoop();
        if (loop.inEventLoop()) {
            shutdownOutput0(promise);
        } else {
            loop.execute(new OneTimeTask() {
                @Override
                public void run() {
                    shutdownOutput0(promise);
                }
            });
        }
    }
    return promise;
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:26,代码来源:EpollSocketChannel.java


注:本文中的io.netty.channel.EventLoop类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。