X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fcommons%2Fprotocol-framework%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fprotocol%2Fframework%2FAbstractDispatcher.java;h=916ef9a88befa87ac8b5c17902ec6d970f23807d;hp=e90af73785eff5d2027b7f4fad5cd7e4a0105710;hb=e159106bc148e76fc1e3e3c780bdd740d99e74ed;hpb=391180fcde6a7a2336182e346e24a1ff9f754062 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 e90af73785..916ef9a88b 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 @@ -77,9 +77,6 @@ public abstract class AbstractDispatcher, L extends */ protected ChannelFuture createServer(final InetSocketAddress address, final PipelineInitializer initializer) { final ServerBootstrap b = new ServerBootstrap(); - b.group(this.bossGroup, this.workerGroup); - b.channel(NioServerSocketChannel.class); - b.option(ChannelOption.SO_BACKLOG, 128); b.childHandler(new ChannelInitializer() { @Override @@ -87,13 +84,35 @@ public abstract class AbstractDispatcher, L extends initializer.initializeChannel(ch, new DefaultPromise(executor)); } }); + + b.option(ChannelOption.SO_BACKLOG, 128); b.childOption(ChannelOption.SO_KEEPALIVE, true); + customizeBootstrap(b); + + if (b.group() == null) { + b.group(bossGroup, workerGroup); + } + try { + b.channel(NioServerSocketChannel.class); + } catch (IllegalStateException e) { + LOG.trace("Not overriding channelFactory on bootstrap {}", b, e); + } // Bind and start to accept incoming connections. final ChannelFuture f = b.bind(address); LOG.debug("Initiated server {} at {}.", f, address); return f; + } + /** + * Customize a server bootstrap before the server is created. This allows + * subclasses to assign non-default server options before the server is + * created. + * + * @param b Server bootstrap + */ + protected void customizeBootstrap(final ServerBootstrap b) { + // The default is a no-op } /** @@ -116,11 +135,25 @@ public abstract class AbstractDispatcher, L extends initializer.initializeChannel(ch, p); } }); + + customizeBootstrap(b); + p.connect(); LOG.debug("Client created."); return p; } + /** + * Customize a client bootstrap before the connection is attempted. This + * allows subclasses to assign non-default options before the client is + * created. + * + * @param b Client bootstrap + */ + protected void customizeBootstrap(final Bootstrap b) { + // The default is a no-op + } + /** * Creates a client. * @@ -138,7 +171,6 @@ public abstract class AbstractDispatcher, L extends p.connect(); return p; - } /**