Use NetworkGraph.acquireReadLock() and releaseReadLock() when
using the REST API to read switches and links from the Network Graph.

Change-Id: I2fd7a874470e349bc236e351f1b84c3386b7f51a
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphLinksResource.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphLinksResource.java
index a244dc1..16da940 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphLinksResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphLinksResource.java
@@ -31,10 +31,13 @@
 		mapper.registerModule(module);
 		
 		try {
+			graph.acquireReadLock();
 			return mapper.writeValueAsString(graph.getLinks());
 		} catch (IOException e) {
 			log.error("Error writing link list to JSON", e);
 			return "";
+		} finally {
+		    graph.releaseReadLock();
 		}
 	}
 }
diff --git a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphSwitchesResource.java b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphSwitchesResource.java
index 92e94f6..3e2a57c 100644
--- a/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphSwitchesResource.java
+++ b/src/main/java/net/onrc/onos/ofcontroller/networkgraph/web/NetworkGraphSwitchesResource.java
@@ -33,11 +33,13 @@
 		mapper.registerModule(module);
 		
 		try {
+			graph.acquireReadLock();
 			return mapper.writeValueAsString(graph.getSwitches());
 		} catch (IOException e) {
 			log.error("Error writing switch list to JSON", e);
 			return "";
+		} finally {
+			graph.releaseReadLock();
 		}
 	}
-
 }