Network Graph Refactoring: WIP: Use the Network Graph locking mechanism
* Renamed NetworkGraph.acquireLock() and releaseLock() to
acquireReadLock() and releaseReadLock()
* Added new methods NetworkGraphImpl.acquireWriteLock() and
releaseWriteLock()
* Use the above two locks inside the TopologyManager for
updating the in-memory Network Topology.
Change-Id: I18d6b65e6c0ad695afb80b0bd469eb96c4f657a6
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraph.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraph.java
index 904e9a5..11f4405 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraph.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraph.java
@@ -84,13 +84,13 @@
/**
* Acquire a read lock on the entire topology. The topology will not
* change while readers have the lock. Must be released using
- * {@link releaseLock()}. This method will block until a read lock is
+ * {@link releaseReadLock()}. This method will block until a read lock is
* available.
*/
- public void acquireLock();
+ public void acquireReadLock();
/**
* Release the read lock on the topology.
*/
- public void releaseLock();
+ public void releaseReadLock();
}
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
index 83fc952..2153905 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/NetworkGraphImpl.java
@@ -142,12 +142,20 @@
}
@Override
- public void acquireLock() {
+ public void acquireReadLock() {
readLock.lock();
}
@Override
- public void releaseLock() {
+ public void releaseReadLock() {
readLock.unlock();
}
+
+ protected void acquireWriteLock() {
+ writeLock.lock();
+ }
+
+ protected void releaseWriteLock() {
+ writeLock.unlock();
+ }
}
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 e484d88..b07b4ff 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/TopologyManager.java
@@ -269,6 +269,11 @@
}
//
+ // Lock the Network Graph while it is modified
+ //
+ networkGraph.acquireWriteLock();
+
+ //
// Apply the classified events.
//
// Apply the "add" events in the proper order:
@@ -302,6 +307,11 @@
! addedPortEvents.isEmpty());
//
+ // Network Graph modifications completed: Release the lock
+ //
+ networkGraph.releaseWriteLock();
+
+ //
// Dispatch the Topology Notification Events to the applications
//
dispatchNetworkGraphEvents();