Andrea Campanella
Committed by Ray Milkey

Modifying preDeactivate hook in OFControllerImpl to remove double deactivation causing NPE.

The preDeactivate is needed to clean up connections when the app is deactivated but needs
to be called also when the component goes down.
If the two,app and component, go down together we should not trigger the cleaning twice.

Change-Id: I66a40297c78f995c5bcd95226efc33fb135732b3
...@@ -64,7 +64,6 @@ import static org.onosproject.openflow.controller.Dpid.uri; ...@@ -64,7 +64,6 @@ import static org.onosproject.openflow.controller.Dpid.uri;
64 64
65 /** 65 /**
66 * The main controller class. Handles all setup and network listeners 66 * The main controller class. Handles all setup and network listeners
67 - * - Distributed ownership control of switch through IControllerRegistryService
68 */ 67 */
69 public class Controller { 68 public class Controller {
70 69
......
...@@ -155,25 +155,28 @@ public class OpenFlowControllerImpl implements OpenFlowController { ...@@ -155,25 +155,28 @@ public class OpenFlowControllerImpl implements OpenFlowController {
155 155
156 @Activate 156 @Activate
157 public void activate(ComponentContext context) { 157 public void activate(ComponentContext context) {
158 - coreService.registerApplication(APP_ID, this::preDeactivate); 158 + coreService.registerApplication(APP_ID, this::cleanup);
159 cfgService.registerProperties(getClass()); 159 cfgService.registerProperties(getClass());
160 ctrl.setConfigParams(context.getProperties()); 160 ctrl.setConfigParams(context.getProperties());
161 ctrl.start(agent, driverService); 161 ctrl.start(agent, driverService);
162 } 162 }
163 163
164 - private void preDeactivate() { 164 + private void cleanup() {
165 - // Close listening channel and all OF channels before deactivating 165 + // Close listening channel and all OF channels. Clean information about switches
166 + // before deactivating
166 ctrl.stop(); 167 ctrl.stop();
167 connectedSwitches.values().forEach(OpenFlowSwitch::disconnectSwitch); 168 connectedSwitches.values().forEach(OpenFlowSwitch::disconnectSwitch);
169 + connectedSwitches.clear();
170 + activeMasterSwitches.clear();
171 + activeEqualSwitches.clear();
168 } 172 }
169 173
170 @Deactivate 174 @Deactivate
171 public void deactivate() { 175 public void deactivate() {
172 - preDeactivate(); 176 + if (!connectedSwitches.isEmpty()) {
177 + cleanup();
178 + }
173 cfgService.unregisterProperties(getClass(), false); 179 cfgService.unregisterProperties(getClass(), false);
174 - connectedSwitches.clear();
175 - activeMasterSwitches.clear();
176 - activeEqualSwitches.clear();
177 } 180 }
178 181
179 @Modified 182 @Modified
......