Allowing component to reattached to previously created map in DatabaseManager
Change-Id: Ie576171392481df726e62365f70d0e934e0ad954
Showing
2 changed files
with
8 additions
and
6 deletions
| ... | @@ -415,16 +415,19 @@ public class DatabaseManager implements StorageService, StorageAdminService { | ... | @@ -415,16 +415,19 @@ public class DatabaseManager implements StorageService, StorageAdminService { |
| 415 | getTransactions().stream().forEach(transactionManager::execute); | 415 | getTransactions().stream().forEach(transactionManager::execute); |
| 416 | } | 416 | } |
| 417 | 417 | ||
| 418 | - protected <K, V> void registerMap(DefaultAsyncConsistentMap<K, V> map) { | 418 | + protected <K, V> DefaultAsyncConsistentMap<K, V> registerMap(DefaultAsyncConsistentMap<K, V> map) { |
| 419 | - // TODO: Support multiple local instances of the same map. | 419 | + DefaultAsyncConsistentMap<K, V> existing = maps.putIfAbsent(map.name(), map); |
| 420 | - if (maps.putIfAbsent(map.name(), map) != null) { | 420 | + if (existing != null) { |
| 421 | - throw new IllegalStateException("Map by name " + map.name() + " already exists"); | 421 | + // FIXME: We need to cleanly support different map instances with same name. |
| 422 | + log.info("Map by name {} already exists", map.name()); | ||
| 423 | + return existing; | ||
| 422 | } | 424 | } |
| 423 | 425 | ||
| 424 | clusterCommunicator.<MapEvent<K, V>>addSubscriber(mapUpdatesSubject(map.name()), | 426 | clusterCommunicator.<MapEvent<K, V>>addSubscriber(mapUpdatesSubject(map.name()), |
| 425 | map.serializer()::decode, | 427 | map.serializer()::decode, |
| 426 | map::notifyLocalListeners, | 428 | map::notifyLocalListeners, |
| 427 | eventDispatcher); | 429 | eventDispatcher); |
| 430 | + return map; | ||
| 428 | } | 431 | } |
| 429 | 432 | ||
| 430 | protected <K, V> void unregisterMap(DefaultAsyncConsistentMap<K, V> map) { | 433 | protected <K, V> void unregisterMap(DefaultAsyncConsistentMap<K, V> map) { | ... | ... |
core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DefaultConsistentMapBuilder.java
| ... | @@ -77,7 +77,6 @@ public class DefaultConsistentMapBuilder<K, V> implements ConsistentMapBuilder<K | ... | @@ -77,7 +77,6 @@ public class DefaultConsistentMapBuilder<K, V> implements ConsistentMapBuilder<K |
| 77 | event -> manager.clusterCommunicator.<MapEvent<K, V>>broadcast(event, | 77 | event -> manager.clusterCommunicator.<MapEvent<K, V>>broadcast(event, |
| 78 | DatabaseManager.mapUpdatesSubject(name), | 78 | DatabaseManager.mapUpdatesSubject(name), |
| 79 | serializer::encode)); | 79 | serializer::encode)); |
| 80 | - manager.registerMap(asyncMap); | 80 | + return manager.registerMap(asyncMap); |
| 81 | - return asyncMap; | ||
| 82 | } | 81 | } |
| 83 | } | 82 | } |
| ... | \ No newline at end of file | ... | \ No newline at end of file | ... | ... |
-
Please register or login to post a comment