Fixed a slew of shutdown exceptions that arose due to improper or out-of-order resource clean-up, e.g. listeners, timers, executors.

Change-Id: I37c351c4202b32e92c076d9d566b96d7ff8d313a
diff --git a/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitch.java b/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitch.java
index 65a8c55..50c0351 100644
--- a/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitch.java
+++ b/openflow/api/src/main/java/org/onosproject/openflow/controller/driver/AbstractOpenFlowSwitch.java
@@ -96,14 +96,14 @@
 
     @Override
     public final void sendMsg(OFMessage m) {
-        if (role == RoleState.MASTER) {
+        if (role == RoleState.MASTER && channel.isWritable()) {
             channel.write(Collections.singletonList(m));
         }
     }
 
     @Override
     public final void sendMsg(List<OFMessage> msgs) {
-        if (role == RoleState.MASTER) {
+        if (role == RoleState.MASTER && channel.isWritable()) {
             channel.write(msgs);
         }
     }