11package com .github .dockerjava .netty ;
22
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+
317import com .github .dockerjava .api .command .AttachContainerCmd ;
418import com .github .dockerjava .api .command .AuthCmd ;
519import com .github .dockerjava .api .command .BuildImageCmd ;
142156import io .netty .channel .EventLoopGroup ;
143157import io .netty .channel .epoll .EpollDomainSocketChannel ;
144158import io .netty .channel .epoll .EpollEventLoopGroup ;
159+ import io .netty .channel .kqueue .KQueueDomainSocketChannel ;
160+ import io .netty .channel .kqueue .KQueueEventLoopGroup ;
145161import io .netty .channel .nio .NioEventLoopGroup ;
146162import io .netty .channel .socket .DuplexChannel ;
147163import io .netty .channel .socket .SocketChannel ;
@@ -249,6 +265,15 @@ private interface NettyInitializer {
249265 private class UnixDomainSocketInitializer implements NettyInitializer {
250266 @ Override
251267 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 () {
252277 EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup (0 , new DefaultThreadFactory (threadPrefix ));
253278
254279 ChannelFactory <EpollDomainSocketChannel > factory = new ChannelFactory <EpollDomainSocketChannel >() {
@@ -258,14 +283,28 @@ public EpollDomainSocketChannel newChannel() {
258283 }
259284 };
260285
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 >() {
263300 @ 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 ()));
265303 channel .pipeline ().addLast (new HttpClientCodec ());
266304 }
267305 });
268- return epollEventLoopGroup ;
306+
307+ return nioEventLoopGroup ;
269308 }
270309
271310 @ Override
0 commit comments