Skip to content

Commit 98a414b

Browse files
author
Luc Boutier
committed
Support for KQueue
1 parent e64cb8b commit 98a414b

2 files changed

Lines changed: 62 additions & 23 deletions

File tree

pom.xml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
1+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
2+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23
<modelVersion>4.0.0</modelVersion>
34

45
<parent>
@@ -73,7 +74,7 @@
7374
<!-- test dependencies -->
7475
<logback.version>1.1.7</logback.version>
7576
<testng.version>6.9.10</testng.version>
76-
<netty.version>4.1.3.Final</netty.version>
77+
<netty.version>4.1.10.Final-KQUEUE-SNAPSHOT</netty.version>
7778
<hamcrest.library.version>1.3</hamcrest.library.version>
7879
<hamcrest.jpa-matchers>1.8</hamcrest.jpa-matchers>
7980
<lambdaj.version>2.3.3</lambdaj.version>
@@ -250,6 +251,12 @@
250251
<version>${netty.version}</version>
251252
<classifier>linux-x86_64</classifier>
252253
</dependency>
254+
<dependency>
255+
<groupId>io.netty</groupId>
256+
<artifactId>netty-transport-native-kqueue</artifactId>
257+
<version>${netty.version}</version>
258+
<classifier>osx-x86_64</classifier>
259+
</dependency>
253260
<dependency>
254261
<groupId>junit</groupId>
255262
<artifactId>junit</artifactId>
@@ -468,8 +475,8 @@
468475
<failOnViolation>true</failOnViolation>
469476
<logViolationsToConsole>true</logViolationsToConsole>
470477
<linkXRef>false</linkXRef>
471-
<!-- if some IDE has integration and requires other place, propose
472-
it -->
478+
<!-- if some IDE has integration and requires other place, propose
479+
it -->
473480
<configLocation>
474481
src/test/resources/checkstyle/checkstyle-config.xml
475482
</configLocation>

src/main/java/com/github/dockerjava/netty/NettyDockerCmdExecFactory.java

Lines changed: 51 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,8 @@
115115
import io.netty.channel.EventLoopGroup;
116116
import io.netty.channel.epoll.EpollDomainSocketChannel;
117117
import io.netty.channel.epoll.EpollEventLoopGroup;
118+
import io.netty.channel.kqueue.KQueueDomainSocketChannel;
119+
import io.netty.channel.kqueue.KQueueEventLoopGroup;
118120
import io.netty.channel.nio.NioEventLoopGroup;
119121
import io.netty.channel.socket.DuplexChannel;
120122
import 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

Comments
 (0)