All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.navercorp.pinpoint.grpc.server.ServerChannelTypeFactory Maven / Gradle / Ivy

There is a newer version: 3.0.0
Show newest version
package com.navercorp.pinpoint.grpc.server;

import com.navercorp.pinpoint.grpc.ChannelTypeEnum;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.ServerChannel;
import io.netty.channel.epoll.Epoll;
import io.netty.channel.epoll.EpollEventLoopGroup;
import io.netty.channel.epoll.EpollServerSocketChannel;
import io.netty.channel.nio.NioEventLoopGroup;
import io.netty.channel.socket.nio.NioServerSocketChannel;

import java.util.Objects;
import java.util.concurrent.Executor;

public class ServerChannelTypeFactory {

    public ServerChannelType newChannelType(ChannelTypeEnum type) {
        Objects.requireNonNull(type, "channelTypeEnum");

        switch (type) {
            case NIO:
                return new NioServerChannelType();
            case EPOLL:
                return newEpollChannelType();
            case AUTO:
            default:
                return newEpollChannelType();
        }
    }

    private ServerChannelType newEpollChannelType() {
        if (Epoll.isAvailable()) {
            return new EpollServerChannelType();
        }
        return new NioServerChannelType();
    }

    public static class EpollServerChannelType implements ServerChannelType {
        @Override
        public Class getChannelType() {
            return EpollServerSocketChannel.class;
        }

        @Override
        public EventLoopGroup newEventLoopGroup(int nThreads, Executor executor) {
            return new EpollEventLoopGroup(nThreads, executor);
        }
    }

    public static class NioServerChannelType implements ServerChannelType {
        @Override
        public Class getChannelType() {
            return NioServerSocketChannel.class;
        }

        @Override
        public EventLoopGroup newEventLoopGroup(int nThreads, Executor executor) {
            return new NioEventLoopGroup(nThreads, executor);
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy