Skip to content

Commit b6b6196

Browse files
author
Marcus Linke
committed
Experiment with jnr-unixsocket and netty
1 parent 72597d7 commit b6b6196

File tree

2 files changed

+50
-15
lines changed

2 files changed

+50
-15
lines changed

pom.xml

Lines changed: 22 additions & 10 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>
@@ -231,6 +232,16 @@
231232
<version>${netty.version}</version>
232233
<classifier>linux-x86_64</classifier>
233234
</dependency>
235+
<dependency>
236+
<groupId>com.github.jnr</groupId>
237+
<artifactId>jnr-unixsocket</artifactId>
238+
<version>0.12</version>
239+
</dependency>
240+
<dependency>
241+
<groupId>me.lessis</groupId>
242+
<artifactId>unisockets-core_2.11</artifactId>
243+
<version>0.1.0</version>
244+
</dependency>
234245
</dependencies>
235246

236247
<distributionManagement>
@@ -245,13 +256,13 @@
245256
</distributionManagement>
246257

247258
<build>
248-
<!-- <extensions> -->
249-
<!-- <extension> -->
250-
<!-- <groupId>kr.motd.maven</groupId> -->
251-
<!-- <artifactId>os-maven-plugin</artifactId> -->
252-
<!-- <version>1.2.3.Final</version> -->
253-
<!-- </extension> -->
254-
<!-- </extensions> -->
259+
<!-- <extensions> -->
260+
<!-- <extension> -->
261+
<!-- <groupId>kr.motd.maven</groupId> -->
262+
<!-- <artifactId>os-maven-plugin</artifactId> -->
263+
<!-- <version>1.2.3.Final</version> -->
264+
<!-- </extension> -->
265+
<!-- </extensions> -->
255266
<pluginManagement>
256267
<plugins>
257268

@@ -392,7 +403,7 @@
392403
</goals>
393404
<configuration>
394405
<groups>integration</groups>
395-
<!-- <excludedGroups>ignoreInCircleCi</excludedGroups> -->
406+
<!-- <excludedGroups>ignoreInCircleCi</excludedGroups> -->
396407
<includes>
397408
<include>**/*Test.java</include>
398409
</includes>
@@ -456,7 +467,8 @@
456467
<failOnViolation>true</failOnViolation>
457468
<logViolationsToConsole>true</logViolationsToConsole>
458469
<linkXRef>false</linkXRef>
459-
<!-- if some IDE has integration and requires other place, propose it -->
470+
<!-- if some IDE has integration and requires other place, propose
471+
it -->
460472
<configLocation>
461473
src/test/resources/checkstyle/checkstyle-config.xml
462474
</configLocation>

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

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@
106106
import com.github.dockerjava.netty.exec.RenameContainerCmdExec;
107107

108108
import io.netty.bootstrap.Bootstrap;
109+
import io.netty.channel.Channel;
110+
import io.netty.channel.ChannelFactory;
109111
import io.netty.channel.ChannelInitializer;
110112
import io.netty.channel.EventLoopGroup;
111113
import io.netty.channel.epoll.EpollDomainSocketChannel;
@@ -131,8 +133,14 @@
131133
import java.net.InetAddress;
132134
import java.net.InetSocketAddress;
133135
import java.net.SocketAddress;
136+
import java.nio.channels.SelectionKey;
137+
import java.nio.channels.Selector;
134138
import java.security.Security;
135139

140+
import jnr.enxio.channels.NativeSelectorProvider;
141+
import jnr.unixsocket.UnixServerSocketChannel;
142+
import jnr.unixsocket.UnixSocketAddress;
143+
import jnr.unixsocket.UnixSocketChannel;
136144
import static com.google.common.base.Preconditions.checkNotNull;
137145

138146
/**
@@ -216,17 +224,32 @@ private interface NettyInitializer {
216224
}
217225

218226
private class UnixDomainSocketInitializer implements NettyInitializer {
227+
228+
final java.io.File path = new java.io.File("/var/run/docker.sock");
229+
219230
@Override
220231
public EventLoopGroup init(Bootstrap bootstrap, DockerClientConfig dockerClientConfig) {
221-
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, new DefaultThreadFactory(threadPrefix));
222-
bootstrap.group(epollEventLoopGroup).channel(EpollDomainSocketChannel.class)
223-
.handler(new ChannelInitializer<UnixChannel>() {
232+
233+
EventLoopGroup nioEventLoopGroup = new NioEventLoopGroup(0, new DefaultThreadFactory(threadPrefix), NativeSelectorProvider.getInstance());
234+
235+
ChannelFactory<NioSocketChannel> factory = new ChannelFactory<NioSocketChannel>() {
236+
237+
@Override
238+
public NioSocketChannel newChannel() {
239+
unisockets.SocketChannel socketChannel = unisockets.SocketChannel.open(path);
240+
return new NioSocketChannel(socketChannel);
241+
}
242+
};
243+
244+
bootstrap.group(nioEventLoopGroup).channelFactory(factory)
245+
.handler(new ChannelInitializer<SocketChannel>() {
224246
@Override
225-
protected void initChannel(final UnixChannel channel) throws Exception {
247+
protected void initChannel(final SocketChannel channel) throws Exception {
226248
channel.pipeline().addLast(new HttpClientCodec());
227249
}
228250
});
229-
return epollEventLoopGroup;
251+
252+
return nioEventLoopGroup;
230253
}
231254

232255
@Override

0 commit comments

Comments
 (0)