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;
/**
* The main controller class. Handles all setup and network listeners
* - Distributed ownership control of switch through IControllerRegistryService
*/
public class Controller {
......
......@@ -155,25 +155,28 @@ public class OpenFlowControllerImpl implements OpenFlowController {
@Activate
public void activate(ComponentContext context) {
coreService.registerApplication(APP_ID, this::preDeactivate);
coreService.registerApplication(APP_ID, this::cleanup);
cfgService.registerProperties(getClass());
ctrl.setConfigParams(context.getProperties());
ctrl.start(agent, driverService);
}
private void preDeactivate() {
// Close listening channel and all OF channels before deactivating
private void cleanup() {
// Close listening channel and all OF channels. Clean information about switches
// before deactivating
ctrl.stop();
connectedSwitches.values().forEach(OpenFlowSwitch::disconnectSwitch);
connectedSwitches.clear();
activeMasterSwitches.clear();
activeEqualSwitches.clear();
}
@Deactivate
public void deactivate() {
preDeactivate();
if (!connectedSwitches.isEmpty()) {
cleanup();
}
cfgService.unregisterProperties(getClass(), false);
connectedSwitches.clear();
activeMasterSwitches.clear();
activeEqualSwitches.clear();
}
@Modified
......