Last active
May 14, 2019 06:52
-
-
Save Hc747/25477646e05e77a861a19bbf7611bece to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.netty.bootstrap.ServerBootstrap | |
import io.netty.channel.EventLoopGroup | |
import io.netty.channel.epoll.Epoll | |
import io.netty.channel.epoll.EpollEventLoopGroup | |
import io.netty.channel.epoll.EpollServerSocketChannel | |
import io.netty.channel.kqueue.KQueue | |
import io.netty.channel.kqueue.KQueueEventLoopGroup | |
import io.netty.channel.kqueue.KQueueServerSocketChannel | |
import io.netty.channel.nio.NioEventLoopGroup | |
import io.netty.channel.socket.ServerSocketChannel | |
import io.netty.channel.socket.nio.NioServerSocketChannel | |
class EventLoopGroupProxy(val channel: KClass<out ServerSocketChannel>, group: EventLoopGroup) : EventLoopGroup by group { | |
companion object { | |
fun create(parallelism: Int): EventLoopGroupProxy { | |
return when { | |
KQueue.isAvailable() -> EventLoopGroupProxy(KQueueServerSocketChannel::class, KQueueEventLoopGroup(parallelism)) | |
Epoll.isAvailable() -> EventLoopGroupProxy(EpollServerSocketChannel::class, EpollEventLoopGroup(parallelism)) | |
else -> EventLoopGroupProxy(NioServerSocketChannel::class, NioEventLoopGroup(parallelism)) | |
} | |
} | |
fun createBootstrap(proxy: EventLoopGroupProxy): ServerBootstrap { | |
return createBootstrap(proxy, proxy) | |
} | |
fun createBootstrap(parent: EventLoopGroupProxy, child: EventLoopGroupProxy): ServerBootstrap { | |
return ServerBootstrap().channel(parent.channel.java).group(parent, child) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment