115115import io .netty .channel .EventLoopGroup ;
116116import io .netty .channel .epoll .EpollDomainSocketChannel ;
117117import io .netty .channel .epoll .EpollEventLoopGroup ;
118+ import io .netty .channel .kqueue .KQueueDomainSocketChannel ;
119+ import io .netty .channel .kqueue .KQueueEventLoopGroup ;
118120import io .netty .channel .nio .NioEventLoopGroup ;
119121import io .netty .channel .socket .DuplexChannel ;
120122import io .netty .channel .socket .SocketChannel ;
@@ -193,7 +195,12 @@ public void init(DockerClientConfig dockerClientConfig) {
193195 String scheme = dockerClientConfig .getDockerHost ().getScheme ();
194196
195197 if ("unix" .equals (scheme )) {
196- nettyInitializer = new UnixDomainSocketInitializer ();
198+ String osName = System .getProperty ("os.name" );
199+ if (osName .startsWith ("Mac" )) {
200+ nettyInitializer = new KQueueDomainSocketInitializer ();
201+ } else {
202+ nettyInitializer = new UnixDomainSocketInitializer ();
203+ }
197204 } else if ("tcp" .equals (scheme )) {
198205 nettyInitializer = new InetSocketInitializer ();
199206 }
@@ -231,13 +238,12 @@ public EpollDomainSocketChannel newChannel() {
231238 }
232239 };
233240
234- bootstrap .group (epollEventLoopGroup ).channelFactory (factory )
235- .handler (new ChannelInitializer <UnixChannel >() {
236- @ Override
237- protected void initChannel (final UnixChannel channel ) throws Exception {
238- channel .pipeline ().addLast (new HttpClientCodec ());
239- }
240- });
241+ bootstrap .group (epollEventLoopGroup ).channelFactory (factory ).handler (new ChannelInitializer <UnixChannel >() {
242+ @ Override
243+ protected void initChannel (final UnixChannel channel ) throws Exception {
244+ channel .pipeline ().addLast (new HttpClientCodec ());
245+ }
246+ });
241247 return epollEventLoopGroup ;
242248 }
243249
@@ -247,6 +253,34 @@ public DuplexChannel connect(Bootstrap bootstrap) throws InterruptedException {
247253 }
248254 }
249255
256+ private class KQueueDomainSocketInitializer implements NettyInitializer {
257+ @ Override
258+ public EventLoopGroup init (Bootstrap bootstrap , DockerClientConfig dockerClientConfig ) {
259+
260+ EventLoopGroup kQueueEventLoopGroup = new KQueueEventLoopGroup (0 , new DefaultThreadFactory (threadPrefix ));
261+
262+ ChannelFactory <KQueueDomainSocketChannel > factory = new ChannelFactory <KQueueDomainSocketChannel >() {
263+ @ Override
264+ public KQueueDomainSocketChannel newChannel () {
265+ return configure (new KQueueDomainSocketChannel ());
266+ }
267+ };
268+
269+ bootstrap .group (kQueueEventLoopGroup ).channelFactory (factory ).handler (new ChannelInitializer <UnixChannel >() {
270+ @ Override
271+ protected void initChannel (final UnixChannel channel ) throws Exception {
272+ channel .pipeline ().addLast (new HttpClientCodec ());
273+ }
274+ });
275+ return kQueueEventLoopGroup ;
276+ }
277+
278+ @ Override
279+ public DuplexChannel connect (Bootstrap bootstrap ) throws InterruptedException {
280+ return (DuplexChannel ) bootstrap .connect (new DomainSocketAddress ("/var/run/docker.sock" )).sync ().channel ();
281+ }
282+ }
283+
250284 private class InetSocketInitializer implements NettyInitializer {
251285 @ Override
252286 public EventLoopGroup init (Bootstrap bootstrap , final DockerClientConfig dockerClientConfig ) {
@@ -265,15 +299,14 @@ public NioSocketChannel newChannel() {
265299 }
266300 };
267301
268- bootstrap .group (nioEventLoopGroup ).channelFactory (factory )
269- .handler (new ChannelInitializer <SocketChannel >() {
270- @ Override
271- protected void initChannel (final SocketChannel channel ) throws Exception {
272- // channel.pipeline().addLast(new
273- // HttpProxyHandler(proxyAddress));
274- channel .pipeline ().addLast (new HttpClientCodec ());
275- }
276- });
302+ bootstrap .group (nioEventLoopGroup ).channelFactory (factory ).handler (new ChannelInitializer <SocketChannel >() {
303+ @ Override
304+ protected void initChannel (final SocketChannel channel ) throws Exception {
305+ // channel.pipeline().addLast(new
306+ // HttpProxyHandler(proxyAddress));
307+ channel .pipeline ().addLast (new HttpClientCodec ());
308+ }
309+ });
277310
278311 return nioEventLoopGroup ;
279312 }
@@ -328,8 +361,7 @@ private SslHandler initSsl(DockerClientConfig dockerClientConfig) {
328361 }
329362
330363 protected DockerClientConfig getDockerClientConfig () {
331- checkNotNull (dockerClientConfig ,
332- "Factor not initialized, dockerClientConfig not set. You probably forgot to call init()!" );
364+ checkNotNull (dockerClientConfig , "Factor not initialized, dockerClientConfig not set. You probably forgot to call init()!" );
333365 return dockerClientConfig ;
334366 }
335367
0 commit comments