From: Robert Varga Date: Thu, 3 Jul 2014 16:44:42 +0000 (+0200) Subject: Fix MD5 channel client channel not working X-Git-Tag: release/helium~548 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=commitdiff_plain;h=cf8106c3c3af38102a19ca4fe136f3ba629d24ef Fix MD5 channel client channel not working As it turns out, the client code needs the same fix server-side received, which is to allow customizeBootstrap() to set channel. Change-Id: I5efc541ad27bb3e317348c3bb08b13f3fd4110ed Signed-off-by: Robert Varga --- diff --git a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java index fef2c71969..2495130069 100644 --- a/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java +++ b/opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java @@ -8,6 +8,7 @@ package org.opendaylight.protocol.framework; import com.google.common.base.Preconditions; + import io.netty.bootstrap.Bootstrap; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; @@ -25,9 +26,11 @@ import io.netty.util.concurrent.EventExecutor; import io.netty.util.concurrent.Future; import io.netty.util.concurrent.GlobalEventExecutor; import io.netty.util.concurrent.Promise; + import java.io.Closeable; import java.net.InetSocketAddress; import java.net.SocketAddress; + import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -94,8 +97,8 @@ public abstract class AbstractDispatcher, L extends * * @return ChannelFuture representing the binding process */ - protected ChannelFuture createServer(SocketAddress address, Class channelClass, - final ChannelPipelineInitializer initializer) { + protected ChannelFuture createServer(final SocketAddress address, final Class channelClass, + final ChannelPipelineInitializer initializer) { final ServerBootstrap b = new ServerBootstrap(); b.childHandler(new ChannelInitializer() { @@ -151,9 +154,8 @@ public abstract class AbstractDispatcher, L extends protected Future createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final PipelineInitializer initializer) { final Bootstrap b = new Bootstrap(); final ProtocolSessionPromise p = new ProtocolSessionPromise(executor, address, strategy, b); - b.group(this.workerGroup).channel(NioSocketChannel.class).option(ChannelOption.SO_KEEPALIVE, true).handler( + b.option(ChannelOption.SO_KEEPALIVE, true).handler( new ChannelInitializer() { - @Override protected void initChannel(final SocketChannel ch) { initializer.initializeChannel(ch, p); @@ -162,6 +164,18 @@ public abstract class AbstractDispatcher, L extends customizeBootstrap(b); + if (b.group() == null) { + b.group(workerGroup); + } + + // There is no way to detect if this was already set by + // customizeBootstrap() + try { + b.channel(NioSocketChannel.class); + } catch (IllegalStateException e) { + LOG.trace("Not overriding channelFactory on bootstrap {}", b, e); + } + p.connect(); LOG.debug("Client created."); return p;