Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,9 @@
import com.github.dockerjava.netty.exec.RenameContainerCmdExec;

import io.netty.bootstrap.Bootstrap;
import io.netty.channel.Channel;
import io.netty.channel.ChannelConfig;
import io.netty.channel.ChannelFactory;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.EventLoopGroup;
import io.netty.channel.epoll.EpollDomainSocketChannel;
Expand Down Expand Up @@ -178,6 +181,8 @@ public DuplexChannel getChannel() {
}
};

private Integer connectTimeout = null;

@Override
public void init(DockerClientConfig dockerClientConfig) {
checkNotNull(dockerClientConfig, "config was not specified");
Expand Down Expand Up @@ -218,7 +223,15 @@ private class UnixDomainSocketInitializer implements NettyInitializer {
@Override
public EventLoopGroup init(Bootstrap bootstrap, DockerClientConfig dockerClientConfig) {
EventLoopGroup epollEventLoopGroup = new EpollEventLoopGroup(0, new DefaultThreadFactory(threadPrefix));
bootstrap.group(epollEventLoopGroup).channel(EpollDomainSocketChannel.class)

ChannelFactory<EpollDomainSocketChannel> factory = new ChannelFactory<EpollDomainSocketChannel>() {
@Override
public EpollDomainSocketChannel newChannel() {
return configure(new EpollDomainSocketChannel());
}
};

bootstrap.group(epollEventLoopGroup).channelFactory(factory)
.handler(new ChannelInitializer<UnixChannel>() {
@Override
protected void initChannel(final UnixChannel channel) throws Exception {
Expand All @@ -245,7 +258,14 @@ public EventLoopGroup init(Bootstrap bootstrap, final DockerClientConfig dockerC

Security.addProvider(new BouncyCastleProvider());

bootstrap.group(nioEventLoopGroup).channel(NioSocketChannel.class)
ChannelFactory<NioSocketChannel> factory = new ChannelFactory<NioSocketChannel>() {
@Override
public NioSocketChannel newChannel() {
return configure(new NioSocketChannel());
}
};

bootstrap.group(nioEventLoopGroup).channelFactory(factory)
.handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(final SocketChannel channel) throws Exception {
Expand Down Expand Up @@ -580,6 +600,24 @@ public void close() throws IOException {
eventLoopGroup.shutdownGracefully();
}

/**
* Configure connection timeout in milliseconds
*/
public NettyDockerCmdExecFactory withConnectTimeout(Integer connectTimeout) {
Copy link
Member

@KostyaSha KostyaSha Oct 13, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Jersey has com.github.dockerjava.jaxrs.JerseyDockerCmdExecFactory#withConnectTimeout(Integer connectTimeout) so move method to DockerCmdExecFactory ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if we should do that. Consider a new DockerCmdExecFactory implementation where this can't be configured...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this option is must have for any remote connection and we can remove it any time later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally I don't see any advantage to do so. A user is working against a concrete implementation for sure and internally we don't need this option. All these options (connect timeout, read timeout...) were moved from DockerConfig to concrete DockerCmdExecFactory implementation sometimes ago as these are highly implementation specific options.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because netty impl is buggy i keep NETTY/JERSEY choose. Connect timeout seems reasonable for any impl. But i can configure it in conditionals on my side of course.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As its not usual to support multiple implementations I think its OK to do so in your case.

this.connectTimeout = connectTimeout;
return this;
}

private <T extends Channel> T configure(T channel) {
ChannelConfig channelConfig = channel.config();

if (connectTimeout != null) {
channelConfig.setConnectTimeoutMillis(connectTimeout);
}

return channel;
}

private WebTarget getBaseResource() {
return new WebTarget(channelProvider);
}
Expand Down