BUG-633: allow bootstrap customization 29/5929/1
authorRobert Varga <rovarga@cisco.com>
Sun, 6 Apr 2014 16:20:58 +0000 (18:20 +0200)
committerRobert Varga <rovarga@cisco.com>
Sun, 6 Apr 2014 16:20:58 +0000 (18:20 +0200)
Downstream projects may need to customize Bootstrap/ServerBootstrap
instances before they are used. Create two protected methods which
can be overridden to gain access to the instances before they are used.

Change-Id: Ibb45c7b99847cbe2fe8b90e8d1bf125c66a18e0d
Signed-off-by: Robert Varga <rovarga@cisco.com>
opendaylight/commons/protocol-framework/src/main/java/org/opendaylight/protocol/framework/AbstractDispatcher.java

index e90af73785eff5d2027b7f4fad5cd7e4a0105710..5e55cddf8e766509336041264dcecd7af06a2932 100644 (file)
@@ -89,11 +89,23 @@ public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends
         });
         b.childOption(ChannelOption.SO_KEEPALIVE, true);
 
+        customizeBootstrap(b);
+
         // 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 +128,25 @@ public abstract class AbstractDispatcher<S extends ProtocolSession<?>, 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 +164,6 @@ public abstract class AbstractDispatcher<S extends ProtocolSession<?>, L extends
         p.connect();
 
         return p;
-
     }
 
     /**