initial DistributedDeviceStore
Change-Id: I8730f5c8f7706dafb245ee73d989e7a562d92187
Showing
4 changed files
with
70 additions
and
0 deletions
| ... | @@ -33,6 +33,15 @@ | ... | @@ -33,6 +33,15 @@ |
| 33 | <groupId>org.apache.felix</groupId> | 33 | <groupId>org.apache.felix</groupId> |
| 34 | <artifactId>org.apache.felix.scr.annotations</artifactId> | 34 | <artifactId>org.apache.felix.scr.annotations</artifactId> |
| 35 | </dependency> | 35 | </dependency> |
| 36 | + | ||
| 37 | + <!-- TODO Consider removing store dependency. | ||
| 38 | + Currently required for DistributedDeviceManagerTest. --> | ||
| 39 | + <dependency> | ||
| 40 | + <groupId>org.onlab.onos</groupId> | ||
| 41 | + <artifactId>onos-core-store</artifactId> | ||
| 42 | + <version>${project.version}</version> | ||
| 43 | + <scope>test</scope> | ||
| 44 | + </dependency> | ||
| 36 | </dependencies> | 45 | </dependencies> |
| 37 | 46 | ||
| 38 | <build> | 47 | <build> | ... | ... |
This diff is collapsed. Click to expand it.
core/store/src/main/java/org/onlab/onos/store/device/impl/AbsentInvalidatingLoadingCache.java
0 → 100644
| 1 | +package org.onlab.onos.store.device.impl; | ||
| 2 | + | ||
| 3 | +import java.util.concurrent.Callable; | ||
| 4 | +import java.util.concurrent.ExecutionException; | ||
| 5 | + | ||
| 6 | +import com.google.common.base.Optional; | ||
| 7 | +import com.google.common.cache.ForwardingLoadingCache.SimpleForwardingLoadingCache; | ||
| 8 | +import com.google.common.cache.LoadingCache; | ||
| 9 | + | ||
| 10 | +public class AbsentInvalidatingLoadingCache<K, V> extends | ||
| 11 | + SimpleForwardingLoadingCache<K, Optional<V>> { | ||
| 12 | + | ||
| 13 | + public AbsentInvalidatingLoadingCache(LoadingCache<K, Optional<V>> delegate) { | ||
| 14 | + super(delegate); | ||
| 15 | + } | ||
| 16 | + | ||
| 17 | + @Override | ||
| 18 | + public Optional<V> get(K key) throws ExecutionException { | ||
| 19 | + Optional<V> v = super.get(key); | ||
| 20 | + if (!v.isPresent()) { | ||
| 21 | + invalidate(key); | ||
| 22 | + } | ||
| 23 | + return v; | ||
| 24 | + } | ||
| 25 | + | ||
| 26 | + @Override | ||
| 27 | + public Optional<V> getUnchecked(K key) { | ||
| 28 | + Optional<V> v = super.getUnchecked(key); | ||
| 29 | + if (!v.isPresent()) { | ||
| 30 | + invalidate(key); | ||
| 31 | + } | ||
| 32 | + return v; | ||
| 33 | + } | ||
| 34 | + | ||
| 35 | + @Override | ||
| 36 | + public Optional<V> apply(K key) { | ||
| 37 | + return getUnchecked(key); | ||
| 38 | + } | ||
| 39 | + | ||
| 40 | + @Override | ||
| 41 | + public Optional<V> getIfPresent(Object key) { | ||
| 42 | + Optional<V> v = super.getIfPresent(key); | ||
| 43 | + if (!v.isPresent()) { | ||
| 44 | + invalidate(key); | ||
| 45 | + } | ||
| 46 | + return v; | ||
| 47 | + } | ||
| 48 | + | ||
| 49 | + @Override | ||
| 50 | + public Optional<V> get(K key, Callable<? extends Optional<V>> valueLoader) | ||
| 51 | + throws ExecutionException { | ||
| 52 | + | ||
| 53 | + Optional<V> v = super.get(key, valueLoader); | ||
| 54 | + if (!v.isPresent()) { | ||
| 55 | + invalidate(key); | ||
| 56 | + } | ||
| 57 | + return v; | ||
| 58 | + } | ||
| 59 | + | ||
| 60 | + // TODO should we be also checking getAll, etc. | ||
| 61 | +} |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment