*LinkResourceStore: lock everything until we have optimistick locking, etc. in place
Change-Id: I024f87aa561c1b2bcbf861571f8ebfceff2f9e40
Showing
2 changed files
with
20 additions
and
20 deletions
... | @@ -73,7 +73,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -73,7 +73,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
73 | * @param link the target link | 73 | * @param link the target link |
74 | * @return free resources | 74 | * @return free resources |
75 | */ | 75 | */ |
76 | - private Set<ResourceAllocation> readOriginalFreeResources(Link link) { | 76 | + private synchronized Set<ResourceAllocation> readOriginalFreeResources(Link link) { |
77 | // TODO read capacity and lambda resources from topology | 77 | // TODO read capacity and lambda resources from topology |
78 | Set<ResourceAllocation> allocations = new HashSet<>(); | 78 | Set<ResourceAllocation> allocations = new HashSet<>(); |
79 | for (int i = 1; i <= 100; i++) { | 79 | for (int i = 1; i <= 100; i++) { |
... | @@ -92,7 +92,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -92,7 +92,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
92 | * {@link org.onlab.onos.net.resource.BandwidthResourceAllocation} object with 0 bandwidth | 92 | * {@link org.onlab.onos.net.resource.BandwidthResourceAllocation} object with 0 bandwidth |
93 | * | 93 | * |
94 | */ | 94 | */ |
95 | - private BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) { | 95 | + private synchronized BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) { |
96 | for (ResourceAllocation res : freeRes) { | 96 | for (ResourceAllocation res : freeRes) { |
97 | if (res.type() == ResourceType.BANDWIDTH) { | 97 | if (res.type() == ResourceType.BANDWIDTH) { |
98 | return (BandwidthResourceAllocation) res; | 98 | return (BandwidthResourceAllocation) res; |
... | @@ -107,7 +107,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -107,7 +107,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
107 | * @param link the target link | 107 | * @param link the target link |
108 | * @param allocations the resources to be subtracted | 108 | * @param allocations the resources to be subtracted |
109 | */ | 109 | */ |
110 | - private void subtractFreeResources(Link link, LinkResourceAllocations allocations) { | 110 | + private synchronized void subtractFreeResources(Link link, LinkResourceAllocations allocations) { |
111 | // TODO Use lock or version for updating freeResources. | 111 | // TODO Use lock or version for updating freeResources. |
112 | checkNotNull(link); | 112 | checkNotNull(link); |
113 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); | 113 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); |
... | @@ -141,7 +141,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -141,7 +141,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
141 | * @param link the target link | 141 | * @param link the target link |
142 | * @param allocations the resources to be added | 142 | * @param allocations the resources to be added |
143 | */ | 143 | */ |
144 | - private void addFreeResources(Link link, LinkResourceAllocations allocations) { | 144 | + private synchronized void addFreeResources(Link link, LinkResourceAllocations allocations) { |
145 | // TODO Use lock or version for updating freeResources. | 145 | // TODO Use lock or version for updating freeResources. |
146 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); | 146 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); |
147 | Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link); | 147 | Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link); |
... | @@ -167,7 +167,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -167,7 +167,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
167 | } | 167 | } |
168 | 168 | ||
169 | @Override | 169 | @Override |
170 | - public Set<ResourceAllocation> getFreeResources(Link link) { | 170 | + public synchronized Set<ResourceAllocation> getFreeResources(Link link) { |
171 | checkNotNull(link); | 171 | checkNotNull(link); |
172 | Set<ResourceAllocation> freeRes = freeResources.get(link); | 172 | Set<ResourceAllocation> freeRes = freeResources.get(link); |
173 | if (freeRes == null) { | 173 | if (freeRes == null) { |
... | @@ -178,7 +178,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -178,7 +178,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
178 | } | 178 | } |
179 | 179 | ||
180 | @Override | 180 | @Override |
181 | - public void allocateResources(LinkResourceAllocations allocations) { | 181 | + public synchronized void allocateResources(LinkResourceAllocations allocations) { |
182 | checkNotNull(allocations); | 182 | checkNotNull(allocations); |
183 | linkResourceAllocationsMap.put(allocations.intendId(), allocations); | 183 | linkResourceAllocationsMap.put(allocations.intendId(), allocations); |
184 | for (Link link : allocations.links()) { | 184 | for (Link link : allocations.links()) { |
... | @@ -193,7 +193,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -193,7 +193,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
193 | } | 193 | } |
194 | 194 | ||
195 | @Override | 195 | @Override |
196 | - public void releaseResources(LinkResourceAllocations allocations) { | 196 | + public synchronized void releaseResources(LinkResourceAllocations allocations) { |
197 | checkNotNull(allocations); | 197 | checkNotNull(allocations); |
198 | linkResourceAllocationsMap.remove(allocations.intendId()); | 198 | linkResourceAllocationsMap.remove(allocations.intendId()); |
199 | for (Link link : allocations.links()) { | 199 | for (Link link : allocations.links()) { |
... | @@ -209,13 +209,13 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -209,13 +209,13 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
209 | } | 209 | } |
210 | 210 | ||
211 | @Override | 211 | @Override |
212 | - public LinkResourceAllocations getAllocations(IntentId intentId) { | 212 | + public synchronized LinkResourceAllocations getAllocations(IntentId intentId) { |
213 | checkNotNull(intentId); | 213 | checkNotNull(intentId); |
214 | return linkResourceAllocationsMap.get(intentId); | 214 | return linkResourceAllocationsMap.get(intentId); |
215 | } | 215 | } |
216 | 216 | ||
217 | @Override | 217 | @Override |
218 | - public Iterable<LinkResourceAllocations> getAllocations(Link link) { | 218 | + public synchronized Iterable<LinkResourceAllocations> getAllocations(Link link) { |
219 | checkNotNull(link); | 219 | checkNotNull(link); |
220 | Set<LinkResourceAllocations> result = allocatedResources.get(link); | 220 | Set<LinkResourceAllocations> result = allocatedResources.get(link); |
221 | if (result == null) { | 221 | if (result == null) { |
... | @@ -225,7 +225,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { | ... | @@ -225,7 +225,7 @@ public class DistributedLinkResourceStore implements LinkResourceStore { |
225 | } | 225 | } |
226 | 226 | ||
227 | @Override | 227 | @Override |
228 | - public Iterable<LinkResourceAllocations> getAllocations() { | 228 | + public synchronized Iterable<LinkResourceAllocations> getAllocations() { |
229 | return Collections.unmodifiableCollection(linkResourceAllocationsMap.values()); | 229 | return Collections.unmodifiableCollection(linkResourceAllocationsMap.values()); |
230 | } | 230 | } |
231 | 231 | ... | ... |
... | @@ -73,7 +73,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -73,7 +73,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
73 | * @param link the target link | 73 | * @param link the target link |
74 | * @return free resources | 74 | * @return free resources |
75 | */ | 75 | */ |
76 | - private Set<ResourceAllocation> readOriginalFreeResources(Link link) { | 76 | + private synchronized Set<ResourceAllocation> readOriginalFreeResources(Link link) { |
77 | // TODO read capacity and lambda resources from topology | 77 | // TODO read capacity and lambda resources from topology |
78 | Set<ResourceAllocation> allocations = new HashSet<>(); | 78 | Set<ResourceAllocation> allocations = new HashSet<>(); |
79 | for (int i = 1; i <= 100; i++) { | 79 | for (int i = 1; i <= 100; i++) { |
... | @@ -92,7 +92,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -92,7 +92,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
92 | * {@link BandwidthResourceAllocation} object with 0 bandwidth | 92 | * {@link BandwidthResourceAllocation} object with 0 bandwidth |
93 | * | 93 | * |
94 | */ | 94 | */ |
95 | - private BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) { | 95 | + private synchronized BandwidthResourceAllocation getBandwidth(Set<ResourceAllocation> freeRes) { |
96 | for (ResourceAllocation res : freeRes) { | 96 | for (ResourceAllocation res : freeRes) { |
97 | if (res.type() == ResourceType.BANDWIDTH) { | 97 | if (res.type() == ResourceType.BANDWIDTH) { |
98 | return (BandwidthResourceAllocation) res; | 98 | return (BandwidthResourceAllocation) res; |
... | @@ -107,7 +107,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -107,7 +107,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
107 | * @param link the target link | 107 | * @param link the target link |
108 | * @param allocations the resources to be subtracted | 108 | * @param allocations the resources to be subtracted |
109 | */ | 109 | */ |
110 | - private void subtractFreeResources(Link link, LinkResourceAllocations allocations) { | 110 | + private synchronized void subtractFreeResources(Link link, LinkResourceAllocations allocations) { |
111 | // TODO Use lock or version for updating freeResources. | 111 | // TODO Use lock or version for updating freeResources. |
112 | checkNotNull(link); | 112 | checkNotNull(link); |
113 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); | 113 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); |
... | @@ -141,7 +141,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -141,7 +141,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
141 | * @param link the target link | 141 | * @param link the target link |
142 | * @param allocations the resources to be added | 142 | * @param allocations the resources to be added |
143 | */ | 143 | */ |
144 | - private void addFreeResources(Link link, LinkResourceAllocations allocations) { | 144 | + private synchronized void addFreeResources(Link link, LinkResourceAllocations allocations) { |
145 | // TODO Use lock or version for updating freeResources. | 145 | // TODO Use lock or version for updating freeResources. |
146 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); | 146 | Set<ResourceAllocation> freeRes = new HashSet<>(getFreeResources(link)); |
147 | Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link); | 147 | Set<ResourceAllocation> addRes = allocations.getResourceAllocation(link); |
... | @@ -167,7 +167,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -167,7 +167,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
167 | } | 167 | } |
168 | 168 | ||
169 | @Override | 169 | @Override |
170 | - public Set<ResourceAllocation> getFreeResources(Link link) { | 170 | + public synchronized Set<ResourceAllocation> getFreeResources(Link link) { |
171 | checkNotNull(link); | 171 | checkNotNull(link); |
172 | Set<ResourceAllocation> freeRes = freeResources.get(link); | 172 | Set<ResourceAllocation> freeRes = freeResources.get(link); |
173 | if (freeRes == null) { | 173 | if (freeRes == null) { |
... | @@ -178,7 +178,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -178,7 +178,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
178 | } | 178 | } |
179 | 179 | ||
180 | @Override | 180 | @Override |
181 | - public void allocateResources(LinkResourceAllocations allocations) { | 181 | + public synchronized void allocateResources(LinkResourceAllocations allocations) { |
182 | checkNotNull(allocations); | 182 | checkNotNull(allocations); |
183 | linkResourceAllocationsMap.put(allocations.intendId(), allocations); | 183 | linkResourceAllocationsMap.put(allocations.intendId(), allocations); |
184 | for (Link link : allocations.links()) { | 184 | for (Link link : allocations.links()) { |
... | @@ -193,7 +193,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -193,7 +193,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
193 | } | 193 | } |
194 | 194 | ||
195 | @Override | 195 | @Override |
196 | - public void releaseResources(LinkResourceAllocations allocations) { | 196 | + public synchronized void releaseResources(LinkResourceAllocations allocations) { |
197 | checkNotNull(allocations); | 197 | checkNotNull(allocations); |
198 | linkResourceAllocationsMap.remove(allocations.intendId()); | 198 | linkResourceAllocationsMap.remove(allocations.intendId()); |
199 | for (Link link : allocations.links()) { | 199 | for (Link link : allocations.links()) { |
... | @@ -209,13 +209,13 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -209,13 +209,13 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
209 | } | 209 | } |
210 | 210 | ||
211 | @Override | 211 | @Override |
212 | - public LinkResourceAllocations getAllocations(IntentId intentId) { | 212 | + public synchronized LinkResourceAllocations getAllocations(IntentId intentId) { |
213 | checkNotNull(intentId); | 213 | checkNotNull(intentId); |
214 | return linkResourceAllocationsMap.get(intentId); | 214 | return linkResourceAllocationsMap.get(intentId); |
215 | } | 215 | } |
216 | 216 | ||
217 | @Override | 217 | @Override |
218 | - public Iterable<LinkResourceAllocations> getAllocations(Link link) { | 218 | + public synchronized Iterable<LinkResourceAllocations> getAllocations(Link link) { |
219 | checkNotNull(link); | 219 | checkNotNull(link); |
220 | Set<LinkResourceAllocations> result = allocatedResources.get(link); | 220 | Set<LinkResourceAllocations> result = allocatedResources.get(link); |
221 | if (result == null) { | 221 | if (result == null) { |
... | @@ -225,7 +225,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { | ... | @@ -225,7 +225,7 @@ public class SimpleLinkResourceStore implements LinkResourceStore { |
225 | } | 225 | } |
226 | 226 | ||
227 | @Override | 227 | @Override |
228 | - public Iterable<LinkResourceAllocations> getAllocations() { | 228 | + public synchronized Iterable<LinkResourceAllocations> getAllocations() { |
229 | return Collections.unmodifiableCollection(linkResourceAllocationsMap.values()); | 229 | return Collections.unmodifiableCollection(linkResourceAllocationsMap.values()); |
230 | } | 230 | } |
231 | 231 | ... | ... |
-
Please register or login to post a comment