Search in sources :

Example 51 with EventLoop

use of io.netty.channel.EventLoop in project activemq-artemis by apache.

the class NettyConnection method close.

@Override
public final void close() {
    if (closed) {
        return;
    }
    EventLoop eventLoop = channel.eventLoop();
    boolean inEventLoop = eventLoop.inEventLoop();
    // if we are in an event loop we need to close the channel after the writes have finished
    if (!inEventLoop) {
        final SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
        closeSSLAndChannel(sslHandler, channel, false);
    } else {
        eventLoop.execute(() -> {
            final SslHandler sslHandler = (SslHandler) channel.pipeline().get("ssl");
            closeSSLAndChannel(sslHandler, channel, true);
        });
    }
    closed = true;
    listener.connectionDestroyed(getID());
}
Also used : EventLoop(io.netty.channel.EventLoop) SslHandler(io.netty.handler.ssl.SslHandler)

Example 52 with EventLoop

use of io.netty.channel.EventLoop in project activemq-artemis by apache.

the class NettyConnection method pendingWritesOnEventLoop.

public final long pendingWritesOnEventLoop() {
    final EventLoop eventLoop = channel.eventLoop();
    final boolean inEventLoop = eventLoop.inEventLoop();
    final long pendingWritesOnEventLoop;
    if (inEventLoop) {
        pendingWritesOnEventLoop = this.pendingWritesOnEventLoop;
    } else {
        pendingWritesOnEventLoop = pendingWritesOnEventLoopView.get();
    }
    return pendingWritesOnEventLoop;
}
Also used : EventLoop(io.netty.channel.EventLoop)

Example 53 with EventLoop

use of io.netty.channel.EventLoop in project activemq-artemis by apache.

the class NettyConnection method isAllowedToBlock.

private boolean isAllowedToBlock() {
    final EventLoop eventLoop = channel.eventLoop();
    final boolean inEventLoop = eventLoop.inEventLoop();
    return !inEventLoop;
}
Also used : EventLoop(io.netty.channel.EventLoop)

Example 54 with EventLoop

use of io.netty.channel.EventLoop in project ratpack by ratpack.

the class DefaultContext method start.

public static void start(EventLoop eventLoop, final RequestConstants requestConstants, Registry registry, Handler[] handlers, Action<? super Execution> onComplete) {
    ChainIndex index = new ChainIndex(handlers, registry, true);
    requestConstants.indexes.push(index);
    DefaultContext context = new DefaultContext(requestConstants);
    requestConstants.context = context;
    context.pathBindings = new PathBindingStorage(new RootPathBinding(requestConstants.request.getPath()));
    requestConstants.applicationConstants.execController.fork().onError(throwable -> requestConstants.context.error(throwable instanceof HandlerException ? throwable.getCause() : throwable)).onComplete(onComplete).register(s -> s.add(Context.TYPE, context).add(Request.TYPE, requestConstants.request).add(Response.TYPE, requestConstants.response).add(PathBindingStorage.TYPE, context.pathBindings).addLazy(RequestId.TYPE, () -> registry.get(RequestId.Generator.TYPE).generate(requestConstants.request))).eventLoop(eventLoop).onStart(e -> DefaultRequest.setDelegateRegistry(requestConstants.request, e)).start(e -> {
        requestConstants.execution = e;
        context.joinedRegistry = new ContextRegistry(context).join(requestConstants.execution);
        context.next();
    });
}
Also used : RootPathBinding(ratpack.path.internal.RootPathBinding) ClientErrorHandler(ratpack.error.ClientErrorHandler) DirectChannelAccess(ratpack.handling.direct.DirectChannelAccess) java.util(java.util) Types(ratpack.util.Types) FileSystemBinding(ratpack.file.FileSystemBinding) RootPathBinding(ratpack.path.internal.RootPathBinding) Execution(ratpack.exec.Execution) ResponseTransmitter(ratpack.file.internal.ResponseTransmitter) LoggerFactory(org.slf4j.LoggerFactory) Exceptions.uncheck(ratpack.util.Exceptions.uncheck) TypeToken(com.google.common.reflect.TypeToken) Parser(ratpack.parse.Parser) NoSuchParserException(ratpack.parse.NoSuchParserException) Lists(com.google.common.collect.Lists) PathBindingStorage(ratpack.path.internal.PathBindingStorage) NoSuchRendererException(ratpack.render.NoSuchRendererException) ServerConfig(ratpack.server.ServerConfig) Registry(ratpack.registry.Registry) DefaultRequest(ratpack.http.internal.DefaultRequest) Parse(ratpack.parse.Parse) ratpack.handling(ratpack.handling) ratpack.http(ratpack.http) Path(java.nio.file.Path) HttpHeaderConstants(ratpack.http.internal.HttpHeaderConstants) Function(ratpack.func.Function) ServerErrorHandler(ratpack.error.ServerErrorHandler) RenderController(ratpack.render.internal.RenderController) Logger(org.slf4j.Logger) NotInRegistryException(ratpack.registry.NotInRegistryException) Promise(ratpack.exec.Promise) EventLoop(io.netty.channel.EventLoop) Instant(java.time.Instant) InvalidPathEncodingException(ratpack.path.InvalidPathEncodingException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) IF_MODIFIED_SINCE(io.netty.handler.codec.http.HttpHeaderNames.IF_MODIFIED_SINCE) Channel(io.netty.channel.Channel) Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) Action(ratpack.func.Action) Exceptions(ratpack.util.Exceptions) PathBinding(ratpack.path.PathBinding) ExecController(ratpack.exec.ExecController) PathBindingStorage(ratpack.path.internal.PathBindingStorage)

Example 55 with EventLoop

use of io.netty.channel.EventLoop in project zuul by Netflix.

the class DefaultClientChannelManagerTest method initializeAndShutdown.

@Test
public void initializeAndShutdown() throws Exception {
    final String appName = "app-" + UUID.randomUUID();
    final ServerSocket serverSocket = new ServerSocket(0);
    final InetSocketAddress serverSocketAddress = (InetSocketAddress) serverSocket.getLocalSocketAddress();
    final String serverHostname = serverSocketAddress.getHostName();
    final int serverPort = serverSocketAddress.getPort();
    final OriginName originName = OriginName.fromVipAndApp("vip", appName);
    final DefaultClientConfigImpl clientConfig = new DefaultClientConfigImpl();
    Server.defaultOutboundChannelType.set(NioSocketChannel.class);
    final InstanceInfo instanceInfo = Builder.newBuilder().setAppName(appName).setHostName(serverHostname).setPort(serverPort).build();
    DiscoveryResult discoveryResult = DiscoveryResult.from(instanceInfo, true);
    final DynamicServerResolver resolver = mock(DynamicServerResolver.class);
    when(resolver.resolve(any())).thenReturn(discoveryResult);
    when(resolver.hasServers()).thenReturn(true);
    final Registry registry = new DefaultRegistry();
    final DefaultClientChannelManager clientChannelManager = new DefaultClientChannelManager(originName, clientConfig, resolver, registry);
    final NioEventLoopGroup eventLoopGroup = new NioEventLoopGroup(10);
    final EventLoop eventLoop = eventLoopGroup.next();
    clientChannelManager.init();
    Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(0);
    final Promise<PooledConnection> promiseConn = clientChannelManager.acquire(eventLoop);
    promiseConn.await(200, TimeUnit.MILLISECONDS);
    assertTrue(promiseConn.isDone());
    assertTrue(promiseConn.isSuccess());
    final PooledConnection connection = promiseConn.get();
    assertTrue(connection.isActive());
    assertFalse(connection.isInPool());
    Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(1);
    final boolean releaseResult = clientChannelManager.release(connection);
    assertTrue(releaseResult);
    assertTrue(connection.isInPool());
    Truth.assertThat(clientChannelManager.getConnsInUse()).isEqualTo(0);
    clientChannelManager.shutdown();
    serverSocket.close();
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ServerSocket(java.net.ServerSocket) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) Registry(com.netflix.spectator.api.Registry) InstanceInfo(com.netflix.appinfo.InstanceInfo) OriginName(com.netflix.zuul.origins.OriginName) DiscoveryResult(com.netflix.zuul.discovery.DiscoveryResult) DefaultEventLoop(io.netty.channel.DefaultEventLoop) EventLoop(io.netty.channel.EventLoop) DefaultRegistry(com.netflix.spectator.api.DefaultRegistry) DynamicServerResolver(com.netflix.zuul.discovery.DynamicServerResolver) DefaultClientConfigImpl(com.netflix.client.config.DefaultClientConfigImpl) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Test(org.junit.Test)

Aggregations

EventLoop (io.netty.channel.EventLoop)77 EventLoopGroup (io.netty.channel.EventLoopGroup)27 Test (org.junit.jupiter.api.Test)27 DefaultEventLoopGroup (io.netty.channel.DefaultEventLoopGroup)18 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)17 Channel (io.netty.channel.Channel)10 InetSocketAddress (java.net.InetSocketAddress)10 Bootstrap (io.netty.bootstrap.Bootstrap)9 InetAddress (java.net.InetAddress)9 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)7 ChannelFuture (io.netty.channel.ChannelFuture)6 ChannelPromise (io.netty.channel.ChannelPromise)6 LocalAddress (io.netty.channel.local.LocalAddress)5 HttpProcessingState (com.nike.riposte.server.http.HttpProcessingState)4 ChannelPipeline (io.netty.channel.ChannelPipeline)4 ClosedChannelException (java.nio.channels.ClosedChannelException)4 SingleThreadEventLoop (io.netty.channel.SingleThreadEventLoop)3 IOException (java.io.IOException)3 UnknownHostException (java.net.UnknownHostException)3 Callable (java.util.concurrent.Callable)3