Optimize port status and hello message handling 05/58305/1
authormiroslav.macko <miroslav.macko@pantheon.tech>
Tue, 25 Apr 2017 13:54:24 +0000 (15:54 +0200)
committerJozef Bacigal <jozef.bacigal@pantheon.tech>
Tue, 6 Jun 2017 08:14:06 +0000 (08:14 +0000)
- Reduce number of created threads and close used threads.

Change-Id: Ib37268be5e7982c64b95da9abffa6db78ef4edc1
Signed-off-by: miroslav.macko <miroslav.macko@pantheon.tech>
(cherry picked from commit fad3e013dcc6f2b55b0ffc8ab70b664ed2ddb519)

openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java
openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java

index 3b4d6bafbdef04a1e9514306b9ba149afc645bca..f42b433c9ad085d65d2de722e5e78164945253c6 100644 (file)
@@ -8,11 +8,8 @@
 
 package org.opendaylight.openflowplugin.openflow.md.core;
 
-import com.google.common.annotations.VisibleForTesting;
 import com.google.common.util.concurrent.Futures;
 import java.util.concurrent.Future;
-import java.util.concurrent.LinkedBlockingQueue;
-import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionAdapter;
 import org.opendaylight.openflowjava.protocol.api.connection.ConnectionReadyListener;
@@ -94,7 +91,6 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
 
     private QueueProcessor<OfHeader, DataObject> queueProcessor;
     private QueueKeeper<OfHeader> queue;
-    private ThreadPoolExecutor hsPool;
     private HandshakeManager handshakeManager;
 
     private boolean firstHelloProcessed;
@@ -133,12 +129,6 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
 
     @Override
     public void init() {
-        int handshakeThreadLimit = 1;
-        hsPool = new ThreadPoolLoggingExecutor(handshakeThreadLimit,
-                handshakeThreadLimit, 0L, TimeUnit.MILLISECONDS,
-                new LinkedBlockingQueue<Runnable>(), "OFHandshake-"
-                + conductorId);
-
         connectionAdapter.setMessageListener(this);
         connectionAdapter.setSystemListener(this);
         connectionAdapter.setConnectionReadyListener(this);
@@ -232,7 +222,9 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
         checkState(CONDUCTOR_STATE.HANDSHAKING);
         HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(
                 hello, handshakeManager, connectionAdapter);
-        hsPool.submit(handshakeStepWrapper);
+        Thread t = new Thread(handshakeStepWrapper, "OFHandshake-" + conductorId);
+        t.setDaemon(true);
+        t.start();
     }
 
     /**
@@ -448,7 +440,9 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
             checkState(CONDUCTOR_STATE.HANDSHAKING);
             HandshakeStepWrapper handshakeStepWrapper = new HandshakeStepWrapper(
                     null, handshakeManager, connectionAdapter);
-            hsPool.execute(handshakeStepWrapper);
+            Thread t = new Thread(handshakeStepWrapper, "OFHandshake-" + conductorId);
+            t.setDaemon(true);
+            t.start();
             firstHelloProcessed = true;
         } else {
             LOG.debug("already touched by hello message");
@@ -488,8 +482,6 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
         }
 
         SessionContext sessionContext =  OFSessionUtil.registerSession(this, featureOutput, negotiatedVersion);
-        hsPool.shutdown();
-        hsPool.purge();
         conductorState = CONDUCTOR_STATE.WORKING;
         QueueKeeperFactory.plugQueue(queueProcessor, queue);
     }
@@ -516,26 +508,6 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
                 LOG.warn("Closing handshake context failed: {}", e.getMessage());
                 LOG.debug("Detail in hanshake context close:", e);
             }
-        } else {
-            //This condition will occure when Old Helium openflowplugin implementation will be used.
-            shutdownPoolPolitely();
-        }
-    }
-
-    private void shutdownPoolPolitely() {
-        LOG.debug("Terminating handshake pool for node {}", connectionAdapter.getRemoteAddress());
-        hsPool.shutdown();
-        try {
-            hsPool.awaitTermination(1, TimeUnit.SECONDS);
-        } catch (InterruptedException e) {
-            LOG.debug("Error while awaiting termination of pool. Will force shutdown now.");
-        } finally {
-            hsPool.purge();
-            if (!hsPool.isTerminated()) {
-                hsPool.shutdownNow();
-            }
-            LOG.debug("is handshake pool for node {} is terminated : {}",
-                    connectionAdapter.getRemoteAddress(), hsPool.isTerminated());
         }
     }
 
@@ -543,9 +515,4 @@ public class ConnectionConductorImpl implements OpenflowProtocolListener,
     public void setHandshakeContext(HandshakeContext handshakeContext) {
         this.handshakeContext = handshakeContext;
     }
-
-    @VisibleForTesting
-    ThreadPoolExecutor getHsPool() {
-        return hsPool;
-    }
 }
index 8eb350f358900cfd1cc51805db5fde840b0b2160..dc02a5540bffcf1cb00189e2663f2c40d2381b9c 100644 (file)
@@ -199,7 +199,6 @@ public class ConnectionConductorImplTest {
             libSimulation.join();
         }
         queueProcessor.shutdown();
-        connectionConductor.getHsPool().shutdown();
 
         for (Exception problem : adapter.getOccuredExceptions()) {
             LOG.error("during simulation on adapter side: "
@@ -487,7 +486,6 @@ public class ConnectionConductorImplTest {
      */
     private void executeNow() throws InterruptedException {
         execute(true);
-        connectionConductor.getHsPool().shutdown();
     }
 
     /**