Search in sources :

Example 1 with RequestThreadPoolExecutor

use of org.apache.cassandra.transport.RequestThreadPoolExecutor in project cassandra by apache.

the class NativeTransportService method initialize.

/**
     * Creates netty thread pools and event loops.
     */
@VisibleForTesting
synchronized void initialize() {
    if (initialized)
        return;
    // prepare netty resources
    eventExecutorGroup = new RequestThreadPoolExecutor();
    if (useEpoll()) {
        workerGroup = new EpollEventLoopGroup();
        logger.info("Netty using native Epoll event loop");
    } else {
        workerGroup = new NioEventLoopGroup();
        logger.info("Netty using Java NIO event loop");
    }
    int nativePort = DatabaseDescriptor.getNativeTransportPort();
    int nativePortSSL = DatabaseDescriptor.getNativeTransportPortSSL();
    InetAddress nativeAddr = DatabaseDescriptor.getRpcAddress();
    org.apache.cassandra.transport.Server.Builder builder = new org.apache.cassandra.transport.Server.Builder().withEventExecutor(eventExecutorGroup).withEventLoopGroup(workerGroup).withHost(nativeAddr);
    if (!DatabaseDescriptor.getClientEncryptionOptions().enabled) {
        servers = Collections.singleton(builder.withSSL(false).withPort(nativePort).build());
    } else {
        if (nativePort != nativePortSSL) {
            // user asked for dedicated ssl port for supporting both non-ssl and ssl connections
            servers = Collections.unmodifiableList(Arrays.asList(builder.withSSL(false).withPort(nativePort).build(), builder.withSSL(true).withPort(nativePortSSL).build()));
        } else {
            // ssl only mode using configured native port
            servers = Collections.singleton(builder.withSSL(true).withPort(nativePort).build());
        }
    }
    // register metrics
    ClientMetrics.instance.addCounter("connectedNativeClients", () -> {
        int ret = 0;
        for (Server server : servers) ret += server.getConnectedClients();
        return ret;
    });
    AuthMetrics.init();
    initialized = true;
}
Also used : RequestThreadPoolExecutor(org.apache.cassandra.transport.RequestThreadPoolExecutor) Server(org.apache.cassandra.transport.Server) EpollEventLoopGroup(io.netty.channel.epoll.EpollEventLoopGroup) InetAddress(java.net.InetAddress) NioEventLoopGroup(io.netty.channel.nio.NioEventLoopGroup) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Aggregations

VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 EpollEventLoopGroup (io.netty.channel.epoll.EpollEventLoopGroup)1 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)1 InetAddress (java.net.InetAddress)1 RequestThreadPoolExecutor (org.apache.cassandra.transport.RequestThreadPoolExecutor)1 Server (org.apache.cassandra.transport.Server)1