1
1
package com .github .dockerjava .netty ;
2
2
3
+ import static com .google .common .base .Preconditions .checkNotNull ;
4
+
5
+ import java .io .IOException ;
6
+ import java .net .InetAddress ;
7
+ import java .net .InetSocketAddress ;
8
+ import java .net .SocketAddress ;
9
+ import java .security .Security ;
10
+
11
+ import javax .net .ssl .SSLEngine ;
12
+ import javax .net .ssl .SSLParameters ;
13
+
14
+ import org .apache .commons .lang .SystemUtils ;
15
+ import org .bouncycastle .jce .provider .BouncyCastleProvider ;
16
+
3
17
import com .github .dockerjava .api .command .AttachContainerCmd ;
4
18
import com .github .dockerjava .api .command .AuthCmd ;
5
19
import com .github .dockerjava .api .command .BuildImageCmd ;
142
156
import io .netty .channel .EventLoopGroup ;
143
157
import io .netty .channel .epoll .EpollDomainSocketChannel ;
144
158
import io .netty .channel .epoll .EpollEventLoopGroup ;
159
+ import io .netty .channel .kqueue .KQueueDomainSocketChannel ;
160
+ import io .netty .channel .kqueue .KQueueEventLoopGroup ;
145
161
import io .netty .channel .nio .NioEventLoopGroup ;
146
162
import io .netty .channel .socket .DuplexChannel ;
147
163
import io .netty .channel .socket .SocketChannel ;
@@ -249,6 +265,15 @@ private interface NettyInitializer {
249
265
private class UnixDomainSocketInitializer implements NettyInitializer {
250
266
@ Override
251
267
public EventLoopGroup init (Bootstrap bootstrap , DockerClientConfig dockerClientConfig ) {
268
+ if (SystemUtils .IS_OS_LINUX ) {
269
+ return epollGroup ();
270
+ } else if (SystemUtils .IS_OS_MAC_OSX ) {
271
+ return kqueueGroup ();
272
+ }
273
+ throw new RuntimeException ("Unspported OS" );
274
+ }
275
+
276
+ public EventLoopGroup epollGroup () {
252
277
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup (0 , new DefaultThreadFactory (threadPrefix ));
253
278
254
279
ChannelFactory <EpollDomainSocketChannel > factory = new ChannelFactory <EpollDomainSocketChannel >() {
@@ -258,14 +283,28 @@ public EpollDomainSocketChannel newChannel() {
258
283
}
259
284
};
260
285
261
- bootstrap .group (epollEventLoopGroup ).channelFactory (factory )
262
- .handler (new ChannelInitializer <UnixChannel >() {
286
+ bootstrap .group (epollEventLoopGroup ).channelFactory (factory ).handler (new ChannelInitializer <UnixChannel >() {
287
+ @ Override
288
+ protected void initChannel (final UnixChannel channel ) throws Exception {
289
+ channel .pipeline ().addLast (new HttpClientCodec ());
290
+ }
291
+ });
292
+ return epollEventLoopGroup ;
293
+ }
294
+
295
+ public EventLoopGroup kqueueGroup () {
296
+ EventLoopGroup nioEventLoopGroup = new KQueueEventLoopGroup (0 , new DefaultThreadFactory (threadPrefix ));
297
+
298
+ bootstrap .group (nioEventLoopGroup ).channel (KQueueDomainSocketChannel .class )
299
+ .handler (new ChannelInitializer <KQueueDomainSocketChannel >() {
263
300
@ Override
264
- protected void initChannel (final UnixChannel channel ) throws Exception {
301
+ protected void initChannel (final KQueueDomainSocketChannel channel ) throws Exception {
302
+ channel .pipeline ().addLast (new LoggingHandler (getClass ()));
265
303
channel .pipeline ().addLast (new HttpClientCodec ());
266
304
}
267
305
});
268
- return epollEventLoopGroup ;
306
+
307
+ return nioEventLoopGroup ;
269
308
}
270
309
271
310
@ Override
0 commit comments