Search in sources :

Example 16 with DefaultChannelGroup

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

the class NettyConnector method start.

@Override
public synchronized void start() {
    if (channelClazz != null) {
        return;
    }
    if (remotingThreads == -1) {
        // Default to number of cores * 3
        remotingThreads = Runtime.getRuntime().availableProcessors() * 3;
    }
    String connectorType;
    if (useEpoll && CheckDependencies.isEpollAvailable()) {
        if (useGlobalWorkerPool) {
            group = SharedEventLoopGroup.getInstance((threadFactory -> new EpollEventLoopGroup(remotingThreads, threadFactory)));
        } else {
            group = new EpollEventLoopGroup(remotingThreads);
        }
        connectorType = EPOLL_CONNECTOR_TYPE;
        channelClazz = EpollSocketChannel.class;
        logger.debug("Connector " + this + " using native epoll");
    } else if (useKQueue && CheckDependencies.isKQueueAvailable()) {
        if (useGlobalWorkerPool) {
            group = SharedEventLoopGroup.getInstance((threadFactory -> new KQueueEventLoopGroup(remotingThreads, threadFactory)));
        } else {
            group = new KQueueEventLoopGroup(remotingThreads);
        }
        connectorType = KQUEUE_CONNECTOR_TYPE;
        channelClazz = KQueueSocketChannel.class;
        logger.debug("Connector " + this + " using native kqueue");
    } else {
        if (useGlobalWorkerPool) {
            channelClazz = NioSocketChannel.class;
            group = SharedEventLoopGroup.getInstance((threadFactory -> new NioEventLoopGroup(remotingThreads, threadFactory)));
        } else {
            channelClazz = NioSocketChannel.class;
            group = new NioEventLoopGroup(remotingThreads);
        }
        connectorType = NIO_CONNECTOR_TYPE;
        channelClazz = NioSocketChannel.class;
        logger.debug("Connector + " + this + " using nio");
    }
    // if we are a servlet wrap the socketChannelFactory
    bootstrap = new Bootstrap();
    bootstrap.channel(channelClazz);
    bootstrap.group(group);
    bootstrap.option(ChannelOption.TCP_NODELAY, tcpNoDelay);
    if (connectTimeoutMillis != -1) {
        bootstrap.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, connectTimeoutMillis);
    }
    if (tcpReceiveBufferSize != -1) {
        bootstrap.option(ChannelOption.SO_RCVBUF, tcpReceiveBufferSize);
    }
    if (tcpSendBufferSize != -1) {
        bootstrap.option(ChannelOption.SO_SNDBUF, tcpSendBufferSize);
    }
    final int writeBufferLowWaterMark = this.writeBufferLowWaterMark != -1 ? this.writeBufferLowWaterMark : WriteBufferWaterMark.DEFAULT.low();
    final int writeBufferHighWaterMark = this.writeBufferHighWaterMark != -1 ? this.writeBufferHighWaterMark : WriteBufferWaterMark.DEFAULT.high();
    final WriteBufferWaterMark writeBufferWaterMark = new WriteBufferWaterMark(writeBufferLowWaterMark, writeBufferHighWaterMark);
    bootstrap.option(ChannelOption.WRITE_BUFFER_WATER_MARK, writeBufferWaterMark);
    bootstrap.option(ChannelOption.SO_KEEPALIVE, true);
    bootstrap.option(ChannelOption.SO_REUSEADDR, true);
    channelGroup = new DefaultChannelGroup("activemq-connector", GlobalEventExecutor.INSTANCE);
    final String realKeyStorePath;
    final String realKeyStoreProvider;
    final String realKeyStoreType;
    final String realKeyStorePassword;
    final String realTrustStorePath;
    final String realTrustStoreProvider;
    final String realTrustStoreType;
    final String realTrustStorePassword;
    if (sslEnabled) {
        if (forceSSLParameters) {
            realKeyStorePath = keyStorePath;
            realKeyStoreProvider = keyStoreProvider;
            realKeyStoreType = keyStoreType;
            realKeyStorePassword = keyStorePassword;
            realTrustStorePath = trustStorePath;
            realTrustStoreProvider = trustStoreProvider;
            realTrustStoreType = trustStoreType;
            realTrustStorePassword = trustStorePassword;
        } else {
            realKeyStorePath = Stream.of(System.getProperty(ACTIVEMQ_KEYSTORE_PATH_PROP_NAME), System.getProperty(JAVAX_KEYSTORE_PATH_PROP_NAME), keyStorePath).map(v -> useDefaultSslContext ? keyStorePath : v).filter(Objects::nonNull).findFirst().orElse(null);
            realKeyStorePassword = Stream.of(System.getProperty(ACTIVEMQ_KEYSTORE_PASSWORD_PROP_NAME), System.getProperty(JAVAX_KEYSTORE_PASSWORD_PROP_NAME), keyStorePassword).map(v -> useDefaultSslContext ? keyStorePassword : v).filter(Objects::nonNull).findFirst().orElse(null);
            Pair<String, String> keyStoreCompat = SSLSupport.getValidProviderAndType(Stream.of(System.getProperty(ACTIVEMQ_KEYSTORE_PROVIDER_PROP_NAME), System.getProperty(JAVAX_KEYSTORE_PROVIDER_PROP_NAME), keyStoreProvider).map(v -> useDefaultSslContext ? keyStoreProvider : v).filter(Objects::nonNull).findFirst().orElse(null), Stream.of(System.getProperty(ACTIVEMQ_KEYSTORE_TYPE_PROP_NAME), System.getProperty(JAVAX_KEYSTORE_TYPE_PROP_NAME), keyStoreType).map(v -> useDefaultSslContext ? keyStoreType : v).filter(Objects::nonNull).findFirst().orElse(null));
            realKeyStoreProvider = keyStoreCompat.getA();
            realKeyStoreType = keyStoreCompat.getB();
            realTrustStorePath = Stream.of(System.getProperty(ACTIVEMQ_TRUSTSTORE_PATH_PROP_NAME), System.getProperty(JAVAX_TRUSTSTORE_PATH_PROP_NAME), trustStorePath).map(v -> useDefaultSslContext ? trustStorePath : v).filter(Objects::nonNull).findFirst().orElse(null);
            realTrustStorePassword = Stream.of(System.getProperty(ACTIVEMQ_TRUSTSTORE_PASSWORD_PROP_NAME), System.getProperty(JAVAX_TRUSTSTORE_PASSWORD_PROP_NAME), trustStorePassword).map(v -> useDefaultSslContext ? trustStorePassword : v).filter(Objects::nonNull).findFirst().orElse(null);
            Pair<String, String> trustStoreCompat = SSLSupport.getValidProviderAndType(Stream.of(System.getProperty(ACTIVEMQ_TRUSTSTORE_PROVIDER_PROP_NAME), System.getProperty(JAVAX_TRUSTSTORE_PROVIDER_PROP_NAME), trustStoreProvider).map(v -> useDefaultSslContext ? trustStoreProvider : v).filter(Objects::nonNull).findFirst().orElse(null), Stream.of(System.getProperty(ACTIVEMQ_TRUSTSTORE_TYPE_PROP_NAME), System.getProperty(JAVAX_TRUSTSTORE_TYPE_PROP_NAME), trustStoreType).map(v -> useDefaultSslContext ? trustStoreType : v).filter(Objects::nonNull).findFirst().orElse(null));
            realTrustStoreProvider = trustStoreCompat.getA();
            realTrustStoreType = trustStoreCompat.getB();
        }
    } else {
        realKeyStorePath = null;
        realKeyStoreProvider = null;
        realKeyStoreType = null;
        realKeyStorePassword = null;
        realTrustStorePath = null;
        realTrustStoreProvider = null;
        realTrustStoreType = null;
        realTrustStorePassword = null;
    }
    bootstrap.handler(new ChannelInitializer<Channel>() {

        @Override
        public void initChannel(Channel channel) throws Exception {
            final ChannelPipeline pipeline = channel.pipeline();
            if (proxyEnabled && (proxyRemoteDNS || !isTargetLocalHost())) {
                InetSocketAddress proxyAddress = new InetSocketAddress(proxyHost, proxyPort);
                ProxyHandler proxyHandler;
                switch(proxyVersion) {
                    case SOCKS5:
                        proxyHandler = new Socks5ProxyHandler(proxyAddress, proxyUsername, proxyPassword);
                        break;
                    case SOCKS4a:
                        proxyHandler = new Socks4ProxyHandler(proxyAddress, proxyUsername);
                        break;
                    default:
                        throw new IllegalArgumentException("Unknown SOCKS proxy version");
                }
                channel.pipeline().addLast(proxyHandler);
                logger.debug("Using a SOCKS proxy at " + proxyHost + ":" + proxyPort);
                if (proxyRemoteDNS) {
                    bootstrap.resolver(NoopAddressResolverGroup.INSTANCE);
                }
            }
            if (sslEnabled && !useServlet) {
                final SSLContextConfig sslContextConfig = SSLContextConfig.builder().keystoreProvider(realKeyStoreProvider).keystorePath(realKeyStorePath).keystoreType(realKeyStoreType).keystorePassword(realKeyStorePassword).truststoreProvider(realTrustStoreProvider).truststorePath(realTrustStorePath).truststoreType(realTrustStoreType).truststorePassword(realTrustStorePassword).trustManagerFactoryPlugin(trustManagerFactoryPlugin).crlPath(crlPath).trustAll(trustAll).build();
                final SSLEngine engine;
                if (sslProvider.equals(TransportConstants.OPENSSL_PROVIDER)) {
                    engine = loadOpenSslEngine(channel.alloc(), sslContextConfig);
                } else {
                    engine = loadJdkSslEngine(sslContextConfig);
                }
                engine.setUseClientMode(true);
                engine.setWantClientAuth(true);
                // setting the enabled cipher suites resets the enabled protocols so we need
                // to save the enabled protocols so that after the customer cipher suite is enabled
                // we can reset the enabled protocols if a customer protocol isn't specified
                String[] originalProtocols = engine.getEnabledProtocols();
                if (enabledCipherSuites != null) {
                    try {
                        engine.setEnabledCipherSuites(SSLSupport.parseCommaSeparatedListIntoArray(enabledCipherSuites));
                    } catch (IllegalArgumentException e) {
                        ActiveMQClientLogger.LOGGER.invalidCipherSuite(SSLSupport.parseArrayIntoCommandSeparatedList(engine.getSupportedCipherSuites()));
                        throw e;
                    }
                }
                if (enabledProtocols != null) {
                    try {
                        engine.setEnabledProtocols(SSLSupport.parseCommaSeparatedListIntoArray(enabledProtocols));
                    } catch (IllegalArgumentException e) {
                        ActiveMQClientLogger.LOGGER.invalidProtocol(SSLSupport.parseArrayIntoCommandSeparatedList(engine.getSupportedProtocols()));
                        throw e;
                    }
                } else {
                    engine.setEnabledProtocols(originalProtocols);
                }
                if (verifyHost) {
                    SSLParameters sslParameters = engine.getSSLParameters();
                    sslParameters.setEndpointIdentificationAlgorithm("HTTPS");
                    engine.setSSLParameters(sslParameters);
                }
                if (sniHost != null) {
                    SSLParameters sslParameters = engine.getSSLParameters();
                    sslParameters.setServerNames(Arrays.asList(new SNIHostName(sniHost)));
                    engine.setSSLParameters(sslParameters);
                }
                SslHandler handler = new SslHandler(engine);
                pipeline.addLast("ssl", handler);
            }
            if (httpEnabled) {
                pipeline.addLast(new HttpRequestEncoder());
                pipeline.addLast(new HttpResponseDecoder());
                pipeline.addLast(new HttpObjectAggregator(Integer.MAX_VALUE));
                pipeline.addLast(new HttpHandler());
            }
            if (httpUpgradeEnabled) {
                // prepare to handle a HTTP 101 response to upgrade the protocol.
                final HttpClientCodec httpClientCodec = new HttpClientCodec();
                pipeline.addLast(httpClientCodec);
                pipeline.addLast("http-upgrade", new HttpUpgradeHandler(pipeline, httpClientCodec));
            }
            if (protocolManager != null) {
                protocolManager.addChannelHandlers(pipeline);
            }
            if (handler != null) {
                pipeline.addLast(new ActiveMQClientChannelHandler(channelGroup, handler, new Listener(), closeExecutor));
                logger.debugf("Added ActiveMQClientChannelHandler to Channel with id = %s ", channel.id());
            }
        }
    });
    if (batchDelay > 0) {
        flusher = new BatchFlusher();
        batchFlusherFuture = scheduledThreadPool.scheduleWithFixedDelay(flusher, batchDelay, batchDelay, TimeUnit.MILLISECONDS);
    }
    ActiveMQClientLogger.LOGGER.startedNettyConnector(connectorType, TransportConstants.NETTY_VERSION, host, port);
}
Also used : AttributeKey(io.netty.util.AttributeKey) SSLContext(javax.net.ssl.SSLContext) Arrays(java.util.Arrays) HttpResponseDecoder(io.netty.handler.codec.http.HttpResponseDecoder) SNIHostName(javax.net.ssl.SNIHostName) ProxyHandler(io.netty.handler.proxy.ProxyHandler) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) OpenSSLContextFactoryProvider(org.apache.activemq.artemis.spi.core.remoting.ssl.OpenSSLContextFactoryProvider) HttpObject(io.netty.handler.codec.http.HttpObject) BaseConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener) Base64(io.netty.handler.codec.base64.Base64) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) InetAddress(java.net.InetAddress) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ActiveMQClientProtocolManager(org.apache.activemq.artemis.core.protocol.core.impl.ActiveMQClientProtocolManager) ActiveMQComponent(org.apache.activemq.artemis.core.server.ActiveMQComponent) ActiveMQClientLogger(org.apache.activemq.artemis.core.client.ActiveMQClientLogger) ClientProtocolManager(org.apache.activemq.artemis.spi.core.remoting.ClientProtocolManager) Map(java.util.Map) Level(io.netty.util.ResourceLeakDetector.Level) HttpRequest(io.netty.handler.codec.http.HttpRequest) ChannelPipeline(io.netty.channel.ChannelPipeline) Cookie(io.netty.handler.codec.http.cookie.Cookie) FullHttpRequest(io.netty.handler.codec.http.FullHttpRequest) StandardCharsets(java.nio.charset.StandardCharsets) CountDownLatch(java.util.concurrent.CountDownLatch) Stream(java.util.stream.Stream) SslHandler(io.netty.handler.ssl.SslHandler) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder) ActiveMQClientMessageBundle(org.apache.activemq.artemis.core.client.ActiveMQClientMessageBundle) ActiveMQDefaultConfiguration(org.apache.activemq.artemis.api.config.ActiveMQDefaultConfiguration) ChannelOption(io.netty.channel.ChannelOption) Pair(org.apache.activemq.artemis.api.core.Pair) SSLParameters(javax.net.ssl.SSLParameters) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) KQueueSocketChannel(io.netty.channel.kqueue.KQueueSocketChannel) ConfigurationHelper(org.apache.activemq.artemis.utils.ConfigurationHelper) ScheduledExecutorService(java.util.concurrent.ScheduledExecutorService) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) ConnectException(java.net.ConnectException) SocksVersion(io.netty.handler.codec.socksx.SocksVersion) BufferHandler(org.apache.activemq.artemis.spi.core.remoting.BufferHandler) SslContext(io.netty.handler.ssl.SslContext) Executor(java.util.concurrent.Executor) ClientConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) Channel(io.netty.channel.Channel) Bootstrap(io.netty.bootstrap.Bootstrap) SimpleChannelInboundHandler(io.netty.channel.SimpleChannelInboundHandler) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Future(io.netty.util.concurrent.Future) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) ScheduledFuture(java.util.concurrent.ScheduledFuture) SocketAddress(java.net.SocketAddress) DefaultFullHttpRequest(io.netty.handler.codec.http.DefaultFullHttpRequest) ByteBufAllocator(io.netty.buffer.ByteBufAllocator) URISyntaxException(java.net.URISyntaxException) FutureLatch(org.apache.activemq.artemis.utils.FutureLatch) SSLSupport(org.apache.activemq.artemis.core.remoting.impl.ssl.SSLSupport) Unpooled(io.netty.buffer.Unpooled) GlobalEventExecutor(io.netty.util.concurrent.GlobalEventExecutor) DefaultHttpRequest(io.netty.handler.codec.http.DefaultHttpRequest) ChannelPromise(io.netty.channel.ChannelPromise) URI(java.net.URI) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ChannelGroup(io.netty.channel.group.ChannelGroup) ChannelInitializer(io.netty.channel.ChannelInitializer) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HttpResponseStatus(io.netty.handler.codec.http.HttpResponseStatus) ResourceLeakDetector(io.netty.util.ResourceLeakDetector) InetSocketAddress(java.net.InetSocketAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) Objects(java.util.Objects) AbstractConnector(org.apache.activemq.artemis.spi.core.remoting.AbstractConnector) List(java.util.List) Socks4ProxyHandler(io.netty.handler.proxy.Socks4ProxyHandler) HttpResponse(io.netty.handler.codec.http.HttpResponse) Socks5ProxyHandler(io.netty.handler.proxy.Socks5ProxyHandler) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) WriteBufferWaterMark(io.netty.channel.WriteBufferWaterMark) HttpVersion(io.netty.handler.codec.http.HttpVersion) MessageDigest(java.security.MessageDigest) IPV6Util(org.apache.activemq.artemis.utils.IPV6Util) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) Base64.encodeBytes(org.apache.activemq.artemis.utils.Base64.encodeBytes) SSLEngine(javax.net.ssl.SSLEngine) ConcurrentMap(java.util.concurrent.ConcurrentMap) LastHttpContent(io.netty.handler.codec.http.LastHttpContent) NoopAddressResolverGroup(io.netty.resolver.NoopAddressResolverGroup) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ByteBuf(io.netty.buffer.ByteBuf) Connection(org.apache.activemq.artemis.spi.core.remoting.Connection) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) OpenSSLContextFactory(org.apache.activemq.artemis.spi.core.remoting.ssl.OpenSSLContextFactory) SSLContextConfig(org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig) EventLoopGroup(io.netty.channel.EventLoopGroup) HttpMethod(io.netty.handler.codec.http.HttpMethod) ChannelFuture(io.netty.channel.ChannelFuture) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) FullHttpResponse(io.netty.handler.codec.http.FullHttpResponse) SSLContextFactoryProvider(org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextFactoryProvider) Collections(java.util.Collections) ClientCookieDecoder(io.netty.handler.codec.http.cookie.ClientCookieDecoder) BaseConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.BaseConnectionLifeCycleListener) ClientConnectionLifeCycleListener(org.apache.activemq.artemis.spi.core.remoting.ClientConnectionLifeCycleListener) InetSocketAddress(java.net.InetSocketAddress) SSLEngine(javax.net.ssl.SSLEngine) HttpClientCodec(io.netty.handler.codec.http.HttpClientCodec) KQueueSocketChannel(io.netty.channel.kqueue.KQueueSocketChannel) SSLParameters(javax.net.ssl.SSLParameters) Bootstrap(io.netty.bootstrap.Bootstrap) WriteBufferWaterMark(io.netty.channel.WriteBufferWaterMark) HttpResponseDecoder(io.netty.handler.codec.http.HttpResponseDecoder) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) SSLContextConfig(org.apache.activemq.artemis.spi.core.remoting.ssl.SSLContextConfig) ProxyHandler(io.netty.handler.proxy.ProxyHandler) Socks4ProxyHandler(io.netty.handler.proxy.Socks4ProxyHandler) Socks5ProxyHandler(io.netty.handler.proxy.Socks5ProxyHandler) EpollSocketChannel(io.netty.channel.epoll.EpollSocketChannel) KQueueSocketChannel(io.netty.channel.kqueue.KQueueSocketChannel) Channel(io.netty.channel.Channel) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) Socks4ProxyHandler(io.netty.handler.proxy.Socks4ProxyHandler) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException) URISyntaxException(java.net.URISyntaxException) ChannelPipeline(io.netty.channel.ChannelPipeline) SslHandler(io.netty.handler.ssl.SslHandler) Socks5ProxyHandler(io.netty.handler.proxy.Socks5ProxyHandler) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) KQueueEventLoopGroup(io.netty.channel.kqueue.KQueueEventLoopGroup) SNIHostName(javax.net.ssl.SNIHostName) HttpRequestEncoder(io.netty.handler.codec.http.HttpRequestEncoder)

Example 17 with DefaultChannelGroup

use of io.netty.channel.group.DefaultChannelGroup in project nomulus by google.

the class FrontendMetrics method registerActiveConnection.

@NonFinalForTesting
public void registerActiveConnection(String protocol, String certHash, Channel channel) {
    totalConnectionsCounter.increment(protocol, certHash);
    ImmutableList<String> labels = ImmutableList.of(protocol, certHash);
    ChannelGroup channelGroup;
    if (activeConnections.containsKey(labels)) {
        channelGroup = activeConnections.get(labels);
    } else {
        channelGroup = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
        activeConnections.put(labels, channelGroup);
    }
    channelGroup.add(channel);
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) ChannelGroup(io.netty.channel.group.ChannelGroup) DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) NonFinalForTesting(google.registry.util.NonFinalForTesting)

Example 18 with DefaultChannelGroup

use of io.netty.channel.group.DefaultChannelGroup in project onos by opennetworkinglab.

the class Controller method init.

/**
 * Initialize internal data structures.
 */
public void init() {
    // These data structures are initialized here because other
    // module's startUp() might be called before ours
    this.controllerNodeIPsCache = new HashMap<>();
    this.systemStartTime = System.currentTimeMillis();
    cg = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    if (tlsParams.isTlsEnabled()) {
        initSsl();
    }
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup)

Example 19 with DefaultChannelGroup

use of io.netty.channel.group.DefaultChannelGroup in project djl-serving by deepjavalibrary.

the class ServerGroups method reset.

/**
 * Resets the {@code ServerGroups}.
 */
public final void reset() {
    allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE);
    serverGroup = Connector.newEventLoopGroup(2);
    childGroup = Connector.newEventLoopGroup(configManager.getNettyThreads());
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup)

Example 20 with DefaultChannelGroup

use of io.netty.channel.group.DefaultChannelGroup in project cdap by cdapio.

the class ServiceSocksProxy method startUp.

@Override
protected void startUp() throws Exception {
    ServerBootstrap bootstrap = new ServerBootstrap();
    // We don't perform any blocking task in the proxy, only IO relying, hence doesn't need large amount of threads.
    eventLoopGroup = new NioEventLoopGroup(10, Threads.createDaemonThreadFactory("service-socks-proxy-%d"));
    bootstrap.group(eventLoopGroup).channel(NioServerSocketChannel.class).childHandler(new ChannelInitializer<SocketChannel>() {

        @Override
        protected void initChannel(SocketChannel ch) {
            channelGroup.add(ch);
            ch.pipeline().addLast(new SocksPortUnificationServerHandler()).addLast(new ServiceSocksServerHandler(discoveryServiceClient, authenticator));
        }
    });
    Channel serverChannel = bootstrap.bind(InetAddress.getLoopbackAddress(), 0).sync().channel();
    bindAddress = (InetSocketAddress) serverChannel.localAddress();
    channelGroup = new DefaultChannelGroup(ImmediateEventExecutor.INSTANCE);
    channelGroup.add(serverChannel);
    LOG.info("Runtime service socks proxy started on {}", bindAddress);
}
Also used : DefaultChannelGroup(io.netty.channel.group.DefaultChannelGroup) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) SocketChannel(io.netty.channel.socket.SocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) NioServerSocketChannel(io.netty.channel.socket.nio.NioServerSocketChannel) Channel(io.netty.channel.Channel) SocketChannel(io.netty.channel.socket.SocketChannel) SocksPortUnificationServerHandler(io.netty.handler.codec.socksx.SocksPortUnificationServerHandler) ServerBootstrap(io.netty.bootstrap.ServerBootstrap) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup)

Aggregations

DefaultChannelGroup (io.netty.channel.group.DefaultChannelGroup)39 ChannelGroup (io.netty.channel.group.ChannelGroup)24 Channel (io.netty.channel.Channel)19 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)12 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)10 InetSocketAddress (java.net.InetSocketAddress)10 Test (org.junit.jupiter.api.Test)9 List (java.util.List)8 CountDownLatch (java.util.concurrent.CountDownLatch)8 ChannelOption (io.netty.channel.ChannelOption)7 Test (org.junit.Test)7 ChannelInitializer (io.netty.channel.ChannelInitializer)6 GlobalEventExecutor (io.netty.util.concurrent.GlobalEventExecutor)6 NoopRegistry (com.netflix.spectator.api.NoopRegistry)5 ByteBuf (io.netty.buffer.ByteBuf)5 ByteBufAllocator (io.netty.buffer.ByteBufAllocator)5 Unpooled (io.netty.buffer.Unpooled)5 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)5 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)5 HttpMethod (io.netty.handler.codec.http.HttpMethod)5