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;
import org.opendaylight.openflowplugin.api.OFConstants;
*/
protected void checkState(CONDUCTOR_STATE expectedState) {
if (!conductorState.equals(expectedState)) {
+ LOG.warn("State of connection to switch {} is not correct, "
+ + "terminating the connection",connectionAdapter.getRemoteAddress() );
throw new IllegalStateException("Expected state: " + expectedState
+ ", actual state:" + conductorState);
}
@Override
public void close() {
conductorState = CONDUCTOR_STATE.RIP;
+ if(handshakeContext != null){
+ try {
+ handshakeContext.close();
+ } catch (Exception e) {
+ 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 {
- handshakeContext.close();
- } catch (Exception e) {
- LOG.warn("Closing handshake context failed: {}", e.getMessage());
- LOG.debug("Detail in hanshake context close:", e);
+ 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());
}
}