|
16 | 16 | import io.netty.channel.epoll.EpollEventLoopGroup;
|
17 | 17 | import io.netty.channel.epoll.EpollServerSocketChannel;
|
18 | 18 | import io.netty.channel.epoll.EpollSocketChannel;
|
| 19 | +import io.netty.channel.kqueue.KQueue; |
| 20 | +import io.netty.channel.kqueue.KQueueEventLoopGroup; |
| 21 | +import io.netty.channel.kqueue.KQueueServerSocketChannel; |
| 22 | +import io.netty.channel.kqueue.KQueueSocketChannel; |
19 | 23 | import io.netty.channel.nio.NioEventLoopGroup;
|
20 | 24 | import io.netty.channel.socket.ServerSocketChannel;
|
21 | 25 | import io.netty.channel.socket.SocketChannel;
|
@@ -62,11 +66,6 @@ private NetworkUtils()
|
62 | 66 | SPACE_STRING = " ",
|
63 | 67 | SLASH_STRING = "/";
|
64 | 68 |
|
65 |
| - public static Class<? extends SocketChannel> socketChannel() |
66 |
| - { |
67 |
| - return EPOLL ? EpollSocketChannel.class : NioSocketChannel.class; |
68 |
| - } |
69 |
| - |
70 | 69 | private static final char[] VALUES = new char[]{
|
71 | 70 | 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I'
|
72 | 71 | , 'J', '1', '2', '3', '4', '5', '6',
|
@@ -106,35 +105,41 @@ public static TypeToken<CloudNetwork> cloudnet()
|
106 | 105 | };
|
107 | 106 | }
|
108 | 107 |
|
| 108 | + public static Class<? extends SocketChannel> socketChannel() |
| 109 | + { |
| 110 | + return EPOLL ? EpollSocketChannel.class : KQueue.isAvailable() ? KQueueSocketChannel.class : NioSocketChannel.class; |
| 111 | + } |
| 112 | + |
109 | 113 | public static Class<? extends ServerSocketChannel> serverSocketChannel()
|
110 | 114 | {
|
111 |
| - return EPOLL ? EpollServerSocketChannel.class : NioServerSocketChannel.class; |
| 115 | + return EPOLL ? EpollServerSocketChannel.class : KQueue.isAvailable() ? KQueueServerSocketChannel.class : NioServerSocketChannel.class; |
112 | 116 | }
|
113 | 117 |
|
114 | 118 | public static EventLoopGroup eventLoopGroup()
|
115 | 119 | {
|
116 |
| - return EPOLL ? new EpollEventLoopGroup() : new NioEventLoopGroup(); |
| 120 | + return eventLoopGroup(Runtime.getRuntime().availableProcessors()); |
117 | 121 | }
|
118 | 122 |
|
119 | 123 | public static EventLoopGroup eventLoopGroup(int threads)
|
120 | 124 | {
|
121 |
| - return EPOLL ? new EpollEventLoopGroup(threads) : new NioEventLoopGroup(threads); |
| 125 | + return EPOLL ? new EpollEventLoopGroup(threads) : KQueue.isAvailable() ? new KQueueEventLoopGroup(threads) : new NioEventLoopGroup(threads); |
122 | 126 | }
|
123 | 127 |
|
124 | 128 | public static EventLoopGroup eventLoopGroup(ThreadFactory threadFactory)
|
125 | 129 | {
|
126 |
| - return EPOLL ? new EpollEventLoopGroup(0, threadFactory) : new NioEventLoopGroup(0, threadFactory); |
| 130 | + return eventLoopGroup(0, threadFactory); |
127 | 131 | }
|
128 | 132 |
|
129 | 133 | public static EventLoopGroup eventLoopGroup(int threads, ThreadFactory threadFactory)
|
130 | 134 | {
|
131 |
| - return EPOLL ? new EpollEventLoopGroup(threads, threadFactory) : new NioEventLoopGroup(threads, threadFactory); |
| 135 | + return EPOLL ? new EpollEventLoopGroup(threads, threadFactory) : KQueue.isAvailable() ? new KQueueEventLoopGroup(threads, threadFactory) : new NioEventLoopGroup(threads, threadFactory); |
132 | 136 | }
|
133 | 137 |
|
134 | 138 | public static <T> void addAll(Collection<T> key, Collection<T> value)
|
135 | 139 | {
|
136 |
| - for (T k : value) |
137 |
| - key.add(k); |
| 140 | + if (key == null || value == null) return; |
| 141 | + |
| 142 | + key.addAll(value); |
138 | 143 | }
|
139 | 144 |
|
140 | 145 | public static <T, V> void addAll(java.util.Map<T, V> key, java.util.Map<T, V> value)
|
|
0 commit comments