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 ;
39
53
import com .github .dockerjava .api .command .RemoveImageCmd ;
40
54
import com .github .dockerjava .api .command .RemoveNetworkCmd ;
41
55
import com .github .dockerjava .api .command .RemoveVolumeCmd ;
56
+ import com .github .dockerjava .api .command .RenameContainerCmd ;
42
57
import com .github .dockerjava .api .command .RestartContainerCmd ;
43
58
import com .github .dockerjava .api .command .SaveImageCmd ;
44
59
import com .github .dockerjava .api .command .SearchImagesCmd ;
51
66
import com .github .dockerjava .api .command .UpdateContainerCmd ;
52
67
import com .github .dockerjava .api .command .VersionCmd ;
53
68
import com .github .dockerjava .api .command .WaitContainerCmd ;
54
- import com .github .dockerjava .api .command .RenameContainerCmd ;
55
69
import com .github .dockerjava .core .DockerClientConfig ;
56
70
import com .github .dockerjava .core .DockerClientImpl ;
57
71
import com .github .dockerjava .core .SSLConfig ;
93
107
import com .github .dockerjava .netty .exec .RemoveImageCmdExec ;
94
108
import com .github .dockerjava .netty .exec .RemoveNetworkCmdExec ;
95
109
import com .github .dockerjava .netty .exec .RemoveVolumeCmdExec ;
110
+ import com .github .dockerjava .netty .exec .RenameContainerCmdExec ;
96
111
import com .github .dockerjava .netty .exec .RestartContainerCmdExec ;
97
112
import com .github .dockerjava .netty .exec .SaveImageCmdExec ;
98
113
import com .github .dockerjava .netty .exec .SearchImagesCmdExec ;
105
120
import com .github .dockerjava .netty .exec .UpdateContainerCmdExec ;
106
121
import com .github .dockerjava .netty .exec .VersionCmdExec ;
107
122
import com .github .dockerjava .netty .exec .WaitContainerCmdExec ;
108
- import com .github .dockerjava .netty .exec .RenameContainerCmdExec ;
109
123
110
124
import io .netty .bootstrap .Bootstrap ;
111
125
import io .netty .channel .Channel ;
115
129
import io .netty .channel .EventLoopGroup ;
116
130
import io .netty .channel .epoll .EpollDomainSocketChannel ;
117
131
import io .netty .channel .epoll .EpollEventLoopGroup ;
132
+ import io .netty .channel .kqueue .KQueueDomainSocketChannel ;
133
+ import io .netty .channel .kqueue .KQueueEventLoopGroup ;
118
134
import io .netty .channel .nio .NioEventLoopGroup ;
119
135
import io .netty .channel .socket .DuplexChannel ;
120
136
import io .netty .channel .socket .SocketChannel ;
126
142
import io .netty .handler .ssl .SslHandler ;
127
143
import io .netty .util .concurrent .DefaultThreadFactory ;
128
144
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
-
142
145
/**
143
146
* Experimental implementation of {@link DockerCmdExecFactory} that supports http connection hijacking that is needed to pass STDIN to the
144
147
* container.
@@ -226,6 +229,15 @@ private interface NettyInitializer {
226
229
private class UnixDomainSocketInitializer implements NettyInitializer {
227
230
@ Override
228
231
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 () {
229
241
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup (0 , new DefaultThreadFactory (threadPrefix ));
230
242
231
243
ChannelFactory <EpollDomainSocketChannel > factory = new ChannelFactory <EpollDomainSocketChannel >() {
@@ -235,14 +247,28 @@ public EpollDomainSocketChannel newChannel() {
235
247
}
236
248
};
237
249
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 >() {
240
264
@ 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 ()));
242
267
channel .pipeline ().addLast (new HttpClientCodec ());
243
268
}
244
269
});
245
- return epollEventLoopGroup ;
270
+
271
+ return nioEventLoopGroup ;
246
272
}
247
273
248
274
@ Override
0 commit comments