Merge "Protocol framework: use pooled ByteBuf allocator"
authorTony Tkacik <ttkacik@cisco.com>
Thu, 3 Jul 2014 17:18:52 +0000 (17:18 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 3 Jul 2014 17:18:52 +0000 (17:18 +0000)
1  2 
opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java

index 249513006987eb334b4cd4f4084ce0d08c752713,635bb1076e82aa7b0d33db9f1e2170c4abcedf0a..a62bd7da06501b355c41f36230dbf30a982d61fa
@@@ -8,10 -8,10 +8,11 @@@
  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;
+ import io.netty.buffer.PooledByteBufAllocator;
  import io.netty.channel.ChannelFuture;
  import io.netty.channel.ChannelInitializer;
  import io.netty.channel.ChannelOption;
@@@ -26,11 -26,9 +27,11 @@@ import io.netty.util.concurrent.EventEx
  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;
  
@@@ -97,8 -95,8 +98,8 @@@ public abstract class AbstractDispatche
       *
       * @return ChannelFuture representing the binding process
       */
 -    protected <CH extends Channel> ChannelFuture createServer(SocketAddress address, Class<? extends ServerChannel> channelClass,
 -                                                              final ChannelPipelineInitializer<CH, S> initializer) {
 +    protected <CH extends Channel> ChannelFuture createServer(final SocketAddress address, final Class<? extends ServerChannel> channelClass,
 +            final ChannelPipelineInitializer<CH, S> initializer) {
          final ServerBootstrap b = new ServerBootstrap();
          b.childHandler(new ChannelInitializer<CH>() {
  
              // makes no sense for LocalServer and produces warning
              b.childOption(ChannelOption.SO_KEEPALIVE, true);
          }
+         b.childOption(ChannelOption.ALLOCATOR, PooledByteBufAllocator.DEFAULT);
          customizeBootstrap(b);
  
          if (b.group() == null) {
      protected Future<S> createClient(final InetSocketAddress address, final ReconnectStrategy strategy, final PipelineInitializer<S> initializer) {
          final Bootstrap b = new Bootstrap();
          final ProtocolSessionPromise<S> p = new ProtocolSessionPromise<S>(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<SocketChannel>() {
 -
                      @Override
                      protected void initChannel(final SocketChannel ch) {
                          initializer.initializeChannel(ch, p);
  
          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;