Instruction experimenterId fix
[openflowjava.git] / openflow-protocol-impl / src / main / java / org / opendaylight / openflowjava / protocol / impl / core / TcpHandler.java
index 77e1bce6ff71e52497b4432177896513912992cb..48d5aa1462d42d0dc33bf96dc76bdd24ba4c9b09 100644 (file)
@@ -21,7 +21,7 @@ import io.netty.util.concurrent.GenericFutureListener;
 import java.net.InetAddress;
 import java.net.InetSocketAddress;
 
-import org.opendaylight.openflowjava.protocol.impl.connection.ServerFacade;
+import org.opendaylight.openflowjava.protocol.api.connection.ThreadConfiguration;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -29,7 +29,7 @@ import com.google.common.util.concurrent.ListenableFuture;
 import com.google.common.util.concurrent.SettableFuture;
 
 /**
- * Class implementing server over TCP for handling incoming connections.
+ * Class implementing server over TCP / TLS for handling incoming connections.
  *
  * @author michal.polkorab
  */
@@ -53,8 +53,9 @@ public class TcpHandler implements ServerFacade {
     private NioEventLoopGroup workerGroup;
     private NioEventLoopGroup bossGroup;
     private final SettableFuture<Boolean> isOnlineFuture;
+    private ThreadConfiguration threadConfig;
 
-    private PublishingChannelInitializer channelInitializer;
+    private TcpChannelInitializer channelInitializer;
 
     /**
      * Constructor of TCPHandler that listens on selected port.
@@ -81,9 +82,6 @@ public class TcpHandler implements ServerFacade {
      */
     @Override
     public void run() {
-        bossGroup = new NioEventLoopGroup();
-        workerGroup = new NioEventLoopGroup();
-
         /*
          * We generally do not perform IO-unrelated tasks, so we want to have
          * all outstanding tasks completed before the executing thread goes
@@ -128,7 +126,7 @@ public class TcpHandler implements ServerFacade {
 
             LOGGER.debug("address from tcphandler: {}", address);
             isOnlineFuture.set(true);
-            LOGGER.info("Switch listener started and ready to accept incoming connections on port: {}", port);
+            LOGGER.info("Switch listener started and ready to accept incoming tcp/tls connections on port: {}", port);
             f.channel().closeFuture().sync();
         } catch (InterruptedException e) {
             LOGGER.error("Interrupted while waiting for port {} shutdown", port, e);
@@ -190,8 +188,34 @@ public class TcpHandler implements ServerFacade {
     /**
      * @param channelInitializer
      */
-    public void setChannelInitializer(PublishingChannelInitializer channelInitializer) {
+    public void setChannelInitializer(TcpChannelInitializer channelInitializer) {
         this.channelInitializer = channelInitializer;
     }
 
+    @Override
+    public void setThreadConfig(ThreadConfiguration threadConfig) {
+        this.threadConfig = threadConfig;
+    }
+
+    /**
+     * Initiate event loop groups
+     * @param threadConfiguration number of threads to be created, if not specified in threadConfig
+     */
+    public void initiateEventLoopGroups(ThreadConfiguration threadConfiguration) {
+        if (threadConfiguration != null) {
+            bossGroup = new NioEventLoopGroup(threadConfiguration.getBossThreadCount());
+            workerGroup = new NioEventLoopGroup(threadConfiguration.getWorkerThreadCount());
+        } else {
+            bossGroup = new NioEventLoopGroup();
+            workerGroup = new NioEventLoopGroup();
+        }
+    }
+
+    /**
+     * @return workerGroup
+     */
+    public NioEventLoopGroup getWorkerGroup() {
+        return workerGroup;
+    }
+
 }