From: miroslav.macko Date: Tue, 25 Apr 2017 13:54:24 +0000 (+0200) Subject: Optimize port status and hello message handling X-Git-Tag: release/boron-sr4~1 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=c4fe3dd3371abc597bd28ef04d6099c85d297011;p=openflowplugin.git Optimize port status and hello message handling - Reduce number of created threads and close used threads. Change-Id: Ib37268be5e7982c64b95da9abffa6db78ef4edc1 Signed-off-by: miroslav.macko (cherry picked from commit fad3e013dcc6f2b55b0ffc8ab70b664ed2ddb519) --- diff --git a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java index 3b4d6bafbd..f42b433c9a 100644 --- a/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java +++ b/openflowplugin/src/main/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImpl.java @@ -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 queueProcessor; private QueueKeeper 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(), "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; - } } diff --git a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java index 8eb350f358..dc02a5540b 100644 --- a/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java +++ b/openflowplugin/src/test/java/org/opendaylight/openflowplugin/openflow/md/core/ConnectionConductorImplTest.java @@ -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(); } /**