Release the lock inside a finally block to ensure it is released
Change-Id: I522a35000edefd8d1e9829b0ed746fc85b771668
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
index b07b4ff..7fe7955 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
@@ -273,44 +273,48 @@
//
networkGraph.acquireWriteLock();
- //
- // Apply the classified events.
- //
- // Apply the "add" events in the proper order:
- // switch, port, link, device
- //
- for (SwitchEvent switchEvent : addedSwitchEvents.values())
- addSwitch(switchEvent);
- for (PortEvent portEvent : addedPortEvents.values())
- addPort(portEvent);
- for (LinkEvent linkEvent : addedLinkEvents.values())
- addLink(linkEvent);
- for (DeviceEvent deviceEvent : addedDeviceEvents.values())
- addDevice(deviceEvent);
- //
- // Apply the "remove" events in the reverse order:
- // device, link, port, switch
- //
- for (DeviceEvent deviceEvent : removedDeviceEvents.values())
- removeDevice(deviceEvent);
- for (LinkEvent linkEvent : removedLinkEvents.values())
- removeLink(linkEvent);
- for (PortEvent portEvent : removedPortEvents.values())
- removePort(portEvent);
- for (SwitchEvent switchEvent : removedSwitchEvents.values())
- removeSwitch(switchEvent);
-
- //
- // Apply reordered events
- //
- applyReorderedEvents(! addedSwitchEvents.isEmpty(),
- ! addedPortEvents.isEmpty());
-
- //
- // Network Graph modifications completed: Release the lock
- //
- networkGraph.releaseWriteLock();
-
+ try {
+ //
+ // Apply the classified events.
+ //
+ // Apply the "add" events in the proper order:
+ // switch, port, link, device
+ //
+ for (SwitchEvent switchEvent : addedSwitchEvents.values())
+ addSwitch(switchEvent);
+ for (PortEvent portEvent : addedPortEvents.values())
+ addPort(portEvent);
+ for (LinkEvent linkEvent : addedLinkEvents.values())
+ addLink(linkEvent);
+ for (DeviceEvent deviceEvent : addedDeviceEvents.values())
+ addDevice(deviceEvent);
+ //
+ // Apply the "remove" events in the reverse order:
+ // device, link, port, switch
+ //
+ for (DeviceEvent deviceEvent : removedDeviceEvents.values())
+ removeDevice(deviceEvent);
+ for (LinkEvent linkEvent : removedLinkEvents.values())
+ removeLink(linkEvent);
+ for (PortEvent portEvent : removedPortEvents.values())
+ removePort(portEvent);
+ for (SwitchEvent switchEvent : removedSwitchEvents.values())
+ removeSwitch(switchEvent);
+
+ //
+ // Apply reordered events
+ //
+ applyReorderedEvents(! addedSwitchEvents.isEmpty(),
+ ! addedPortEvents.isEmpty());
+
+ }
+ finally {
+ //
+ // Network Graph modifications completed: Release the lock
+ //
+ networkGraph.releaseWriteLock();
+ }
+
//
// Dispatch the Topology Notification Events to the applications
//