X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?p=controller.git;a=blobdiff_plain;f=opendaylight%2Fprotocol_plugins%2Fopenflow%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fprotocol_plugin%2Fopenflow%2Fcore%2Finternal%2FSwitchHandler.java;h=78ab3275a4ac674333f8b4cb26464b61488d2cda;hp=45203758bdd45e13486936faab73c27f947f547d;hb=a409fe492f53dd811259c11f0cde4f8771f269ad;hpb=f2344025e13ee3e51561bb171800d240f9f91e9a diff --git a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java index 45203758bd..78ab3275a4 100644 --- a/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java +++ b/opendaylight/protocol_plugins/openflow/src/main/java/org/opendaylight/controller/protocol_plugin/openflow/core/internal/SwitchHandler.java @@ -9,6 +9,7 @@ package org.opendaylight.controller.protocol_plugin.openflow.core.internal; +import java.io.IOException; import java.nio.channels.AsynchronousCloseException; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; @@ -186,17 +187,33 @@ public class SwitchHandler implements ISwitch { } public void stop() { - try { - running = false; - selector.wakeup(); - cancelSwitchTimer(); - this.selector.close(); - this.socket.close(); - executor.shutdown(); - } catch (Exception e) { - // do nothing since we are shutting down. - return; - } + running = false; + cancelSwitchTimer(); + try { + selector.wakeup(); + selector.close(); + } catch (Exception e) { + } + try { + socket.close(); + } catch (Exception e) { + } + try { + msgReadWriteService.stop(); + } catch (Exception e) { + } + executor.shutdown(); + + selector = null; + socket = null; + msgReadWriteService = null; + + if (switchHandlerThread != null) { + switchHandlerThread.interrupt(); + } + if (transmitThread != null) { + transmitThread.interrupt(); + } } @Override @@ -428,7 +445,11 @@ public class SwitchHandler implements ISwitch { } private void reportError(Exception e) { - logger.debug("Caught exception ", e); + if (e instanceof AsynchronousCloseException) { + logger.debug("Caught exception {}", e.getMessage()); + } else { + logger.warn("Caught exception {}", e.getMessage()); + } // notify core of this error event and disconnect the switch ((Controller) core).takeSwitchEventError(this); } @@ -709,7 +730,8 @@ public class SwitchHandler implements ISwitch { */ class PriorityMessageTransmit implements Runnable { public void run() { - while (true) { + running = true; + while (running) { try { if (!transmitQ.isEmpty()) { PriorityMessage pmsg = transmitQ.poll(); @@ -721,6 +743,7 @@ public class SwitchHandler implements ISwitch { reportError(e); } } + transmitQ = null; } } @@ -758,7 +781,7 @@ public class SwitchHandler implements ISwitch { } private IMessageReadWrite getMessageReadWriteService() throws Exception { - String str = System.getProperty("secureChannelEnabled"); + String str = System.getProperty("secureChannelEnabled").trim(); return ((str != null) && (str.equalsIgnoreCase("true"))) ? new SecureMessageReadWriteService(socket, selector) : new MessageReadWriteService(socket, selector);