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 ;
3953import com .github .dockerjava .api .command .RemoveImageCmd ;
4054import com .github .dockerjava .api .command .RemoveNetworkCmd ;
4155import com .github .dockerjava .api .command .RemoveVolumeCmd ;
56+ import com .github .dockerjava .api .command .RenameContainerCmd ;
4257import com .github .dockerjava .api .command .RestartContainerCmd ;
4358import com .github .dockerjava .api .command .SaveImageCmd ;
4459import com .github .dockerjava .api .command .SearchImagesCmd ;
5166import com .github .dockerjava .api .command .UpdateContainerCmd ;
5267import com .github .dockerjava .api .command .VersionCmd ;
5368import com .github .dockerjava .api .command .WaitContainerCmd ;
54- import com .github .dockerjava .api .command .RenameContainerCmd ;
5569import com .github .dockerjava .core .DockerClientConfig ;
5670import com .github .dockerjava .core .DockerClientImpl ;
5771import com .github .dockerjava .core .SSLConfig ;
93107import com .github .dockerjava .netty .exec .RemoveImageCmdExec ;
94108import com .github .dockerjava .netty .exec .RemoveNetworkCmdExec ;
95109import com .github .dockerjava .netty .exec .RemoveVolumeCmdExec ;
110+ import com .github .dockerjava .netty .exec .RenameContainerCmdExec ;
96111import com .github .dockerjava .netty .exec .RestartContainerCmdExec ;
97112import com .github .dockerjava .netty .exec .SaveImageCmdExec ;
98113import com .github .dockerjava .netty .exec .SearchImagesCmdExec ;
105120import com .github .dockerjava .netty .exec .UpdateContainerCmdExec ;
106121import com .github .dockerjava .netty .exec .VersionCmdExec ;
107122import com .github .dockerjava .netty .exec .WaitContainerCmdExec ;
108- import com .github .dockerjava .netty .exec .RenameContainerCmdExec ;
109123
110124import io .netty .bootstrap .Bootstrap ;
111125import io .netty .channel .Channel ;
115129import io .netty .channel .EventLoopGroup ;
116130import io .netty .channel .epoll .EpollDomainSocketChannel ;
117131import io .netty .channel .epoll .EpollEventLoopGroup ;
132+ import io .netty .channel .kqueue .KQueueDomainSocketChannel ;
133+ import io .netty .channel .kqueue .KQueueEventLoopGroup ;
118134import io .netty .channel .nio .NioEventLoopGroup ;
119135import io .netty .channel .socket .DuplexChannel ;
120136import io .netty .channel .socket .SocketChannel ;
126142import io .netty .handler .ssl .SslHandler ;
127143import io .netty .util .concurrent .DefaultThreadFactory ;
128144
129- import org .bouncycastle .jce .provider .BouncyCastleProvider ;
130-
131- import javax .net .ssl .SSLEngine ;
132- import javax .net .ssl .SSLParameters ;
133-
134- import java .io .IOException ;
135- import java .net .InetAddress ;
136- import java .net .InetSocketAddress ;
137- import java .net .SocketAddress ;
138- import java .security .Security ;
139-
140- import static com .google .common .base .Preconditions .checkNotNull ;
141-
142145/**
143146 * Experimental implementation of {@link DockerCmdExecFactory} that supports http connection hijacking that is needed to pass STDIN to the
144147 * container.
@@ -226,6 +229,15 @@ private interface NettyInitializer {
226229 private class UnixDomainSocketInitializer implements NettyInitializer {
227230 @ Override
228231 public EventLoopGroup init (Bootstrap bootstrap , DockerClientConfig dockerClientConfig ) {
232+ if (SystemUtils .IS_OS_LINUX ) {
233+ return epollGroup ();
234+ } else if (SystemUtils .IS_OS_MAC_OSX ) {
235+ return kqueueGroup ();
236+ }
237+ throw new RuntimeException ("Unspported OS" );
238+ }
239+
240+ public EventLoopGroup epollGroup () {
229241 EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup (0 , new DefaultThreadFactory (threadPrefix ));
230242
231243 ChannelFactory <EpollDomainSocketChannel > factory = new ChannelFactory <EpollDomainSocketChannel >() {
@@ -235,14 +247,28 @@ public EpollDomainSocketChannel newChannel() {
235247 }
236248 };
237249
238- bootstrap .group (epollEventLoopGroup ).channelFactory (factory )
239- .handler (new ChannelInitializer <UnixChannel >() {
250+ bootstrap .group (epollEventLoopGroup ).channelFactory (factory ).handler (new ChannelInitializer <UnixChannel >() {
251+ @ Override
252+ protected void initChannel (final UnixChannel channel ) throws Exception {
253+ channel .pipeline ().addLast (new HttpClientCodec ());
254+ }
255+ });
256+ return epollEventLoopGroup ;
257+ }
258+
259+ public EventLoopGroup kqueueGroup () {
260+ EventLoopGroup nioEventLoopGroup = new KQueueEventLoopGroup (0 , new DefaultThreadFactory (threadPrefix ));
261+
262+ bootstrap .group (nioEventLoopGroup ).channel (KQueueDomainSocketChannel .class )
263+ .handler (new ChannelInitializer <KQueueDomainSocketChannel >() {
240264 @ Override
241- protected void initChannel (final UnixChannel channel ) throws Exception {
265+ protected void initChannel (final KQueueDomainSocketChannel channel ) throws Exception {
266+ channel .pipeline ().addLast (new LoggingHandler (getClass ()));
242267 channel .pipeline ().addLast (new HttpClientCodec ());
243268 }
244269 });
245- return epollEventLoopGroup ;
270+
271+ return nioEventLoopGroup ;
246272 }
247273
248274 @ Override
0 commit comments