io.netty.channel.kqueue.KQueueServerSocketChannel Java Examples

The following examples show how to use io.netty.channel.kqueue.KQueueServerSocketChannel. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultLoopKQueue.java    From reactor-netty with Apache License 2.0 6 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <CHANNEL extends Channel> CHANNEL getChannel(Class<CHANNEL> channelClass) {
	if (channelClass.equals(SocketChannel.class)) {
		return (CHANNEL) new KQueueSocketChannel();
	}
	if (channelClass.equals(ServerSocketChannel.class)) {
		return (CHANNEL) new KQueueServerSocketChannel();
	}
	if (channelClass.equals(DatagramChannel.class)) {
		return (CHANNEL) new KQueueDatagramChannel();
	}
	if (channelClass.equals(DomainSocketChannel.class)) {
		return (CHANNEL) new KQueueDomainSocketChannel();
	}
	if (channelClass.equals(ServerDomainSocketChannel.class)) {
		return (CHANNEL) new KQueueServerDomainSocketChannel();
	}
	throw new IllegalArgumentException("Unsupported channel type: " + channelClass.getSimpleName());
}
 
Example #2
Source File: Connector.java    From serve with Apache License 2.0 5 votes vote down vote up
public Class<? extends ServerChannel> getServerChannel() {
    if (useNativeIo && Epoll.isAvailable()) {
        return uds ? EpollServerDomainSocketChannel.class : EpollServerSocketChannel.class;
    } else if (useNativeIo && KQueue.isAvailable()) {
        return uds ? KQueueServerDomainSocketChannel.class : KQueueServerSocketChannel.class;
    }

    return NioServerSocketChannel.class;
}
 
Example #3
Source File: BuilderUtils.java    From servicetalk with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the correct {@link Class} to use with the given {@link EventLoopGroup}.
 *
 * @param group        the {@link EventLoopGroup} for which the class is needed
 * @param addressClass The class of the address that the server socket will be bound to.
 * @return the class that should be used for bootstrapping
 */
public static Class<? extends ServerChannel> serverChannel(EventLoopGroup group,
                                                           Class<? extends SocketAddress> addressClass) {
    if (useEpoll(group)) {
        return DomainSocketAddress.class.isAssignableFrom(addressClass) ? EpollServerDomainSocketChannel.class :
                EpollServerSocketChannel.class;
    } else if (useKQueue(group)) {
        return DomainSocketAddress.class.isAssignableFrom(addressClass) ? KQueueServerDomainSocketChannel.class :
                KQueueServerSocketChannel.class;
    } else {
        return NioServerSocketChannel.class;
    }
}
 
Example #4
Source File: Connector.java    From multi-model-server with Apache License 2.0 5 votes vote down vote up
public Class<? extends ServerChannel> getServerChannel() {
    if (useNativeIo && Epoll.isAvailable()) {
        return uds ? EpollServerDomainSocketChannel.class : EpollServerSocketChannel.class;
    } else if (useNativeIo && KQueue.isAvailable()) {
        return uds ? KQueueServerDomainSocketChannel.class : KQueueServerSocketChannel.class;
    }

    return NioServerSocketChannel.class;
}
 
Example #5
Source File: DefaultLoopKQueue.java    From reactor-netty with Apache License 2.0 5 votes vote down vote up
@Override
@SuppressWarnings("unchecked")
public <CHANNEL extends Channel> Class<? extends CHANNEL> getChannelClass(Class<CHANNEL> channelClass) {
	if (channelClass.equals(SocketChannel.class)) {
		return (Class<? extends CHANNEL>) KQueueSocketChannel.class;
	}
	if (channelClass.equals(ServerSocketChannel.class)) {
		return (Class<? extends CHANNEL>) KQueueServerSocketChannel.class;
	}
	if (channelClass.equals(DatagramChannel.class)) {
		return (Class<? extends CHANNEL>) KQueueDatagramChannel.class;
	}
	throw new IllegalArgumentException("Unsupported channel type: " + channelClass.getSimpleName());
}
 
Example #6
Source File: SocketChannelProvider.java    From Jupiter with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public T newChannel() {
    switch (channelType) {
        case ACCEPTOR:
            switch (socketType) {
                case JAVA_NIO:
                    return (T) new NioServerSocketChannel();
                case NATIVE_EPOLL:
                    return (T) new EpollServerSocketChannel();
                case NATIVE_KQUEUE:
                    return (T) new KQueueServerSocketChannel();
                case NATIVE_EPOLL_DOMAIN:
                    return (T) new EpollServerDomainSocketChannel();
                case NATIVE_KQUEUE_DOMAIN:
                    return (T) new KQueueServerDomainSocketChannel();
                default:
                    throw new IllegalStateException("Invalid socket type: " + socketType);
            }
        case CONNECTOR:
            switch (socketType) {
                case JAVA_NIO:
                    return (T) new NioSocketChannel();
                case NATIVE_EPOLL:
                    return (T) new EpollSocketChannel();
                case NATIVE_KQUEUE:
                    return (T) new KQueueSocketChannel();
                case NATIVE_EPOLL_DOMAIN:
                    return (T) new EpollDomainSocketChannel();
                case NATIVE_KQUEUE_DOMAIN:
                    return (T) new KQueueDomainSocketChannel();
                default:
                    throw new IllegalStateException("Invalid socket type: " + socketType);
            }
        default:
            throw new IllegalStateException("Invalid channel type: " + channelType);
    }
}
 
Example #7
Source File: HelloWebServer.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void run() throws Exception {
	// Configure the server.

	if (Epoll.isAvailable()) {
		doRun(new EpollEventLoopGroup(), EpollServerSocketChannel.class, IoMultiplexer.EPOLL);
	} else if (KQueue.isAvailable()) {
		doRun(new EpollEventLoopGroup(), KQueueServerSocketChannel.class, IoMultiplexer.KQUEUE);
	} else {
		doRun(new NioEventLoopGroup(), NioServerSocketChannel.class, IoMultiplexer.JDK);
	}
}
 
Example #8
Source File: NetworkUtils.java    From CloudNet with Apache License 2.0 4 votes vote down vote up
public static Class<? extends ServerSocketChannel> serverSocketChannel() {
    return EPOLL ? EpollServerSocketChannel.class : KQueue.isAvailable() ? KQueueServerSocketChannel.class : NioServerSocketChannel.class;
}
 
Example #9
Source File: GrpcStartable.java    From servicecomb-pack with Apache License 2.0 3 votes vote down vote up
/**
 * https://netty.io/wiki/native-transports.html
 *
 * RHEL/CentOS/Fedora:
 * sudo yum install autoconf automake libtool make tar \
 *                  glibc-devel libaio-devel \
 *                  libgcc.i686 glibc-devel.i686
 * Debian/Ubuntu:
 * sudo apt-get install autoconf automake libtool make tar \
 *                      gcc-multilib libaio-dev
 *
 * brew install autoconf automake libtool
 * */
private Class<? extends ServerChannel> selectorServerChannel() {
  Class<? extends ServerChannel> channel = NioServerSocketChannel.class;
  if (serverConfig.isNativeTransport()) {
    if (OSInfo.isLinux()) {
      channel = EpollServerSocketChannel.class;
    } else if (OSInfo.isMacOS()) {
      channel = KQueueServerSocketChannel.class;
    }
  }
  LOG.info("Netty channel type is " + channel.getSimpleName());
  return channel;
}