Jonathan Hart

Modified GossipIntentStore to use EventuallyConsistentMaps.

All IntentStore operations are now implemented.

ONOS-858

Change-Id: I5081805b61c7e25e28707b90093cae12b5a4374b
...@@ -151,7 +151,7 @@ public interface EventuallyConsistentMap<K, V> { ...@@ -151,7 +151,7 @@ public interface EventuallyConsistentMap<K, V> {
151 * 151 *
152 * @param listener listener to register for events 152 * @param listener listener to register for events
153 */ 153 */
154 - public void addListener(EventuallyConsistentMapListener listener); 154 + public void addListener(EventuallyConsistentMapListener<K, V> listener);
155 155
156 /** 156 /**
157 * Removes the specified listener from the map such that it will no longer 157 * Removes the specified listener from the map such that it will no longer
...@@ -159,7 +159,7 @@ public interface EventuallyConsistentMap<K, V> { ...@@ -159,7 +159,7 @@ public interface EventuallyConsistentMap<K, V> {
159 * 159 *
160 * @param listener listener to deregister for events 160 * @param listener listener to deregister for events
161 */ 161 */
162 - public void removeListener(EventuallyConsistentMapListener listener); 162 + public void removeListener(EventuallyConsistentMapListener<K, V> listener);
163 163
164 /** 164 /**
165 * Shuts down the map and breaks communication between different instances. 165 * Shuts down the map and breaks communication between different instances.
......
...@@ -78,7 +78,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -78,7 +78,7 @@ public class EventuallyConsistentMapImpl<K, V>
78 private final ScheduledExecutorService backgroundExecutor; 78 private final ScheduledExecutorService backgroundExecutor;
79 79
80 private volatile boolean destroyed = false; 80 private volatile boolean destroyed = false;
81 - private static final String ERROR_DESTROYED = " is already destroyed"; 81 + private static final String ERROR_DESTROYED = " map is already destroyed";
82 82
83 // TODO: Make these anti-entropy params configurable 83 // TODO: Make these anti-entropy params configurable
84 private long initialDelaySec = 5; 84 private long initialDelaySec = 5;
...@@ -154,6 +154,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -154,6 +154,7 @@ public class EventuallyConsistentMapImpl<K, V>
154 serializerPool = builder 154 serializerPool = builder
155 .register(WallClockTimestamp.class) 155 .register(WallClockTimestamp.class)
156 .register(PutEntry.class) 156 .register(PutEntry.class)
157 + .register(RemoveEntry.class)
157 .register(ArrayList.class) 158 .register(ArrayList.class)
158 .register(InternalPutEvent.class) 159 .register(InternalPutEvent.class)
159 .register(InternalRemoveEvent.class) 160 .register(InternalRemoveEvent.class)
...@@ -166,25 +167,25 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -166,25 +167,25 @@ public class EventuallyConsistentMapImpl<K, V>
166 167
167 @Override 168 @Override
168 public int size() { 169 public int size() {
169 - checkState(destroyed, mapName + ERROR_DESTROYED); 170 + checkState(!destroyed, mapName + ERROR_DESTROYED);
170 return items.size(); 171 return items.size();
171 } 172 }
172 173
173 @Override 174 @Override
174 public boolean isEmpty() { 175 public boolean isEmpty() {
175 - checkState(destroyed, mapName + ERROR_DESTROYED); 176 + checkState(!destroyed, mapName + ERROR_DESTROYED);
176 return items.isEmpty(); 177 return items.isEmpty();
177 } 178 }
178 179
179 @Override 180 @Override
180 public boolean containsKey(K key) { 181 public boolean containsKey(K key) {
181 - checkState(destroyed, mapName + ERROR_DESTROYED); 182 + checkState(!destroyed, mapName + ERROR_DESTROYED);
182 return items.containsKey(key); 183 return items.containsKey(key);
183 } 184 }
184 185
185 @Override 186 @Override
186 public boolean containsValue(V value) { 187 public boolean containsValue(V value) {
187 - checkState(destroyed, mapName + ERROR_DESTROYED); 188 + checkState(!destroyed, mapName + ERROR_DESTROYED);
188 189
189 return items.values().stream() 190 return items.values().stream()
190 .anyMatch(timestamped -> timestamped.value().equals(value)); 191 .anyMatch(timestamped -> timestamped.value().equals(value));
...@@ -192,7 +193,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -192,7 +193,7 @@ public class EventuallyConsistentMapImpl<K, V>
192 193
193 @Override 194 @Override
194 public V get(K key) { 195 public V get(K key) {
195 - checkState(destroyed, mapName + ERROR_DESTROYED); 196 + checkState(!destroyed, mapName + ERROR_DESTROYED);
196 197
197 Timestamped<V> value = items.get(key); 198 Timestamped<V> value = items.get(key);
198 if (value != null) { 199 if (value != null) {
...@@ -203,7 +204,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -203,7 +204,7 @@ public class EventuallyConsistentMapImpl<K, V>
203 204
204 @Override 205 @Override
205 public void put(K key, V value) { 206 public void put(K key, V value) {
206 - checkState(destroyed, mapName + ERROR_DESTROYED); 207 + checkState(!destroyed, mapName + ERROR_DESTROYED);
207 208
208 Timestamp timestamp = clockService.getTimestamp(key); 209 Timestamp timestamp = clockService.getTimestamp(key);
209 if (putInternal(key, value, timestamp)) { 210 if (putInternal(key, value, timestamp)) {
...@@ -235,7 +236,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -235,7 +236,7 @@ public class EventuallyConsistentMapImpl<K, V>
235 236
236 @Override 237 @Override
237 public void remove(K key) { 238 public void remove(K key) {
238 - checkState(destroyed, mapName + ERROR_DESTROYED); 239 + checkState(!destroyed, mapName + ERROR_DESTROYED);
239 240
240 Timestamp timestamp = clockService.getTimestamp(key); 241 Timestamp timestamp = clockService.getTimestamp(key);
241 if (removeInternal(key, timestamp)) { 242 if (removeInternal(key, timestamp)) {
...@@ -261,7 +262,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -261,7 +262,7 @@ public class EventuallyConsistentMapImpl<K, V>
261 262
262 @Override 263 @Override
263 public void putAll(Map<? extends K, ? extends V> m) { 264 public void putAll(Map<? extends K, ? extends V> m) {
264 - checkState(destroyed, mapName + ERROR_DESTROYED); 265 + checkState(!destroyed, mapName + ERROR_DESTROYED);
265 266
266 List<PutEntry<K, V>> updates = new ArrayList<>(m.size()); 267 List<PutEntry<K, V>> updates = new ArrayList<>(m.size());
267 268
...@@ -287,7 +288,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -287,7 +288,7 @@ public class EventuallyConsistentMapImpl<K, V>
287 288
288 @Override 289 @Override
289 public void clear() { 290 public void clear() {
290 - checkState(destroyed, mapName + ERROR_DESTROYED); 291 + checkState(!destroyed, mapName + ERROR_DESTROYED);
291 292
292 List<RemoveEntry<K>> removed = new ArrayList<>(items.size()); 293 List<RemoveEntry<K>> removed = new ArrayList<>(items.size());
293 294
...@@ -311,14 +312,14 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -311,14 +312,14 @@ public class EventuallyConsistentMapImpl<K, V>
311 312
312 @Override 313 @Override
313 public Set<K> keySet() { 314 public Set<K> keySet() {
314 - checkState(destroyed, mapName + ERROR_DESTROYED); 315 + checkState(!destroyed, mapName + ERROR_DESTROYED);
315 316
316 return items.keySet(); 317 return items.keySet();
317 } 318 }
318 319
319 @Override 320 @Override
320 public Collection<V> values() { 321 public Collection<V> values() {
321 - checkState(destroyed, mapName + ERROR_DESTROYED); 322 + checkState(!destroyed, mapName + ERROR_DESTROYED);
322 323
323 return items.values().stream() 324 return items.values().stream()
324 .map(Timestamped::value) 325 .map(Timestamped::value)
...@@ -327,7 +328,7 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -327,7 +328,7 @@ public class EventuallyConsistentMapImpl<K, V>
327 328
328 @Override 329 @Override
329 public Set<Map.Entry<K, V>> entrySet() { 330 public Set<Map.Entry<K, V>> entrySet() {
330 - checkState(destroyed, mapName + ERROR_DESTROYED); 331 + checkState(!destroyed, mapName + ERROR_DESTROYED);
331 332
332 return items.entrySet().stream() 333 return items.entrySet().stream()
333 .map(e -> new Entry(e.getKey(), e.getValue().value())) 334 .map(e -> new Entry(e.getKey(), e.getValue().value()))
...@@ -335,15 +336,15 @@ public class EventuallyConsistentMapImpl<K, V> ...@@ -335,15 +336,15 @@ public class EventuallyConsistentMapImpl<K, V>
335 } 336 }
336 337
337 @Override 338 @Override
338 - public void addListener(EventuallyConsistentMapListener listener) { 339 + public void addListener(EventuallyConsistentMapListener<K, V> listener) {
339 - checkState(destroyed, mapName + ERROR_DESTROYED); 340 + checkState(!destroyed, mapName + ERROR_DESTROYED);
340 341
341 listeners.add(checkNotNull(listener)); 342 listeners.add(checkNotNull(listener));
342 } 343 }
343 344
344 @Override 345 @Override
345 - public void removeListener(EventuallyConsistentMapListener listener) { 346 + public void removeListener(EventuallyConsistentMapListener<K, V> listener) {
346 - checkState(destroyed, mapName + ERROR_DESTROYED); 347 + checkState(!destroyed, mapName + ERROR_DESTROYED);
347 348
348 listeners.remove(checkNotNull(listener)); 349 listeners.remove(checkNotNull(listener));
349 } 350 }
......
...@@ -19,12 +19,12 @@ package org.onosproject.store.impl; ...@@ -19,12 +19,12 @@ package org.onosproject.store.impl;
19 * Listener interested in receiving modification events for an 19 * Listener interested in receiving modification events for an
20 * EventuallyConsistentMap. 20 * EventuallyConsistentMap.
21 */ 21 */
22 -public interface EventuallyConsistentMapListener { 22 +public interface EventuallyConsistentMapListener<K, V> {
23 23
24 /** 24 /**
25 * Reacts to the specified event. 25 * Reacts to the specified event.
26 * 26 *
27 * @param event the event 27 * @param event the event
28 */ 28 */
29 - public void event(EventuallyConsistentMapEvent event); 29 + public void event(EventuallyConsistentMapEvent<K, V> event);
30 } 30 }
......