*LinkResourceStore: lock everything until we have optimistick locking, etc. in place
Change-Id: I024f87aa561c1b2bcbf861571f8ebfceff2f9e40
diff --git a/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/DistributedLinkResourceStore.java b/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/DistributedLinkResourceStore.java
index ecccd2b..d05620d 100644
--- a/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/DistributedLinkResourceStore.java
+++ b/core/store/dist/src/main/java/org/onlab/onos/store/resource/impl/DistributedLinkResourceStore.java
@@ -73,7 +73,7 @@
* @param link the target link
* @return free resources
*/
- private Set<ResourceAllocation> readOriginalFreeResources(Link link) {
+ private synchronized Set<ResourceAllocation> readOriginalFreeResources(Link link) {
// TODO read capacity and lambda resources from topology
Set<ResourceAllocation> allocations = new HashSet<>();
for (int i = 1; i <= 100; i++) {
@@ -92,7 +92,7 @@
* {@link org.onlab.onos.net.resource.BandwidthResourceAllocation} object with 0 bandwidth
*
*/
- private BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) {
+ private synchronized BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) {
for (ResourceAllocation res : freeRes) {
if (res.type() == ResourceType.BANDWIDTH) {
return (BandwidthResourceAllocation) res;
@@ -107,7 +107,7 @@
* @param link the target link
* @param allocations the resources to be subtracted
*/
- private void subtractFreeResources(Link link, LinkResourceAllocations allocations) {
+ private synchronized void subtractFreeResources(Link link, LinkResourceAllocations allocations) {
// TODO Use lock or version for updating freeResources.
checkNotNull(link);
Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
@@ -141,7 +141,7 @@
* @param link the target link
* @param allocations the resources to be added
*/
- private void addFreeResources(Link link, LinkResourceAllocations allocations) {
+ private synchronized void addFreeResources(Link link, LinkResourceAllocations allocations) {
// TODO Use lock or version for updating freeResources.
Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link);
@@ -167,7 +167,7 @@
}
@Override
- public Set<ResourceAllocation> getFreeResources(Link link) {
+ public synchronized Set<ResourceAllocation> getFreeResources(Link link) {
checkNotNull(link);
Set<ResourceAllocation> freeRes = freeResources.get(link);
if (freeRes == null) {
@@ -178,7 +178,7 @@
}
@Override
- public void allocateResources(LinkResourceAllocations allocations) {
+ public synchronized void allocateResources(LinkResourceAllocations allocations) {
checkNotNull(allocations);
linkResourceAllocationsMap.put(allocations.intendId(), allocations);
for (Link link : allocations.links()) {
@@ -193,7 +193,7 @@
}
@Override
- public void releaseResources(LinkResourceAllocations allocations) {
+ public synchronized void releaseResources(LinkResourceAllocations allocations) {
checkNotNull(allocations);
linkResourceAllocationsMap.remove(allocations.intendId());
for (Link link : allocations.links()) {
@@ -209,13 +209,13 @@
}
@Override
- public LinkResourceAllocations getAllocations(IntentId intentId) {
+ public synchronized LinkResourceAllocations getAllocations(IntentId intentId) {
checkNotNull(intentId);
return linkResourceAllocationsMap.get(intentId);
}
@Override
- public Iterable<LinkResourceAllocations> getAllocations(Link link) {
+ public synchronized Iterable<LinkResourceAllocations> getAllocations(Link link) {
checkNotNull(link);
Set<LinkResourceAllocations> result = allocatedResources.get(link);
if (result == null) {
@@ -225,7 +225,7 @@
}
@Override
- public Iterable<LinkResourceAllocations> getAllocations() {
+ public synchronized Iterable<LinkResourceAllocations> getAllocations() {
return Collections.unmodifiableCollection(linkResourceAllocationsMap.values());
}
diff --git a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java
index 5369375..78cd341 100644
--- a/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java
+++ b/core/store/trivial/src/main/java/org/onlab/onos/store/trivial/impl/SimpleLinkResourceStore.java
@@ -73,7 +73,7 @@
* @param link the target link
* @return free resources
*/
- private Set<ResourceAllocation> readOriginalFreeResources(Link link) {
+ private synchronized Set<ResourceAllocation> readOriginalFreeResources(Link link) {
// TODO read capacity and lambda resources from topology
Set<ResourceAllocation> allocations = new HashSet<>();
for (int i = 1; i <= 100; i++) {
@@ -92,7 +92,7 @@
* {@link BandwidthResourceAllocation} object with 0 bandwidth
*
*/
- private BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) {
+ private synchronized BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) {
for (ResourceAllocation res : freeRes) {
if (res.type() == ResourceType.BANDWIDTH) {
return (BandwidthResourceAllocation) res;
@@ -107,7 +107,7 @@
* @param link the target link
* @param allocations the resources to be subtracted
*/
- private void subtractFreeResources(Link link, LinkResourceAllocations allocations) {
+ private synchronized void subtractFreeResources(Link link, LinkResourceAllocations allocations) {
// TODO Use lock or version for updating freeResources.
checkNotNull(link);
Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
@@ -141,7 +141,7 @@
* @param link the target link
* @param allocations the resources to be added
*/
- private void addFreeResources(Link link, LinkResourceAllocations allocations) {
+ private synchronized void addFreeResources(Link link, LinkResourceAllocations allocations) {
// TODO Use lock or version for updating freeResources.
Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link));
Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link);
@@ -167,7 +167,7 @@
}
@Override
- public Set<ResourceAllocation> getFreeResources(Link link) {
+ public synchronized Set<ResourceAllocation> getFreeResources(Link link) {
checkNotNull(link);
Set<ResourceAllocation> freeRes = freeResources.get(link);
if (freeRes == null) {
@@ -178,7 +178,7 @@
}
@Override
- public void allocateResources(LinkResourceAllocations allocations) {
+ public synchronized void allocateResources(LinkResourceAllocations allocations) {
checkNotNull(allocations);
linkResourceAllocationsMap.put(allocations.intendId(), allocations);
for (Link link : allocations.links()) {
@@ -193,7 +193,7 @@
}
@Override
- public void releaseResources(LinkResourceAllocations allocations) {
+ public synchronized void releaseResources(LinkResourceAllocations allocations) {
checkNotNull(allocations);
linkResourceAllocationsMap.remove(allocations.intendId());
for (Link link : allocations.links()) {
@@ -209,13 +209,13 @@
}
@Override
- public LinkResourceAllocations getAllocations(IntentId intentId) {
+ public synchronized LinkResourceAllocations getAllocations(IntentId intentId) {
checkNotNull(intentId);
return linkResourceAllocationsMap.get(intentId);
}
@Override
- public Iterable<LinkResourceAllocations> getAllocations(Link link) {
+ public synchronized Iterable<LinkResourceAllocations> getAllocations(Link link) {
checkNotNull(link);
Set<LinkResourceAllocations> result = allocatedResources.get(link);
if (result == null) {
@@ -225,7 +225,7 @@
}
@Override
- public Iterable<LinkResourceAllocations> getAllocations() {
+ public synchronized Iterable<LinkResourceAllocations> getAllocations() {
return Collections.unmodifiableCollection(linkResourceAllocationsMap.values());
}