Madan Jampani
Committed by Gerrit Code Review

Refactor set and value builders to remove reference to DatabaseManager

Change-Id: Ia6d012af0766d117ec1baac8652056818b17c8bf
...@@ -30,6 +30,7 @@ import java.util.concurrent.Executors; ...@@ -30,6 +30,7 @@ import java.util.concurrent.Executors;
30 import java.util.concurrent.TimeUnit; 30 import java.util.concurrent.TimeUnit;
31 import java.util.concurrent.TimeoutException; 31 import java.util.concurrent.TimeoutException;
32 import java.util.function.Function; 32 import java.util.function.Function;
33 +import java.util.function.Supplier;
33 import java.util.stream.Collectors; 34 import java.util.stream.Collectors;
34 35
35 import net.kuujo.copycat.CopycatConfig; 36 import net.kuujo.copycat.CopycatConfig;
...@@ -65,6 +66,7 @@ import org.onosproject.core.ApplicationId; ...@@ -65,6 +66,7 @@ import org.onosproject.core.ApplicationId;
65 import org.onosproject.core.IdGenerator; 66 import org.onosproject.core.IdGenerator;
66 import org.onosproject.persistence.PersistenceService; 67 import org.onosproject.persistence.PersistenceService;
67 import org.onosproject.store.cluster.messaging.ClusterCommunicationService; 68 import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
69 +import org.onosproject.store.serializers.KryoNamespaces;
68 import org.onosproject.store.service.AtomicCounterBuilder; 70 import org.onosproject.store.service.AtomicCounterBuilder;
69 import org.onosproject.store.service.AtomicValueBuilder; 71 import org.onosproject.store.service.AtomicValueBuilder;
70 import org.onosproject.store.service.ConsistentMapBuilder; 72 import org.onosproject.store.service.ConsistentMapBuilder;
...@@ -74,6 +76,7 @@ import org.onosproject.store.service.DistributedSetBuilder; ...@@ -74,6 +76,7 @@ import org.onosproject.store.service.DistributedSetBuilder;
74 import org.onosproject.store.service.EventuallyConsistentMapBuilder; 76 import org.onosproject.store.service.EventuallyConsistentMapBuilder;
75 import org.onosproject.store.service.MapInfo; 77 import org.onosproject.store.service.MapInfo;
76 import org.onosproject.store.service.PartitionInfo; 78 import org.onosproject.store.service.PartitionInfo;
79 +import org.onosproject.store.service.Serializer;
77 import org.onosproject.store.service.StorageAdminService; 80 import org.onosproject.store.service.StorageAdminService;
78 import org.onosproject.store.service.StorageService; 81 import org.onosproject.store.service.StorageService;
79 import org.onosproject.store.service.Transaction; 82 import org.onosproject.store.service.Transaction;
...@@ -318,7 +321,7 @@ public class DatabaseManager implements StorageService, StorageAdminService { ...@@ -318,7 +321,7 @@ public class DatabaseManager implements StorageService, StorageAdminService {
318 321
319 @Override 322 @Override
320 public <E> DistributedSetBuilder<E> setBuilder() { 323 public <E> DistributedSetBuilder<E> setBuilder() {
321 - return new DefaultDistributedSetBuilder<>(this); 324 + return new DefaultDistributedSetBuilder<>(() -> this.<E, Boolean>consistentMapBuilder());
322 } 325 }
323 326
324 327
...@@ -334,7 +337,12 @@ public class DatabaseManager implements StorageService, StorageAdminService { ...@@ -334,7 +337,12 @@ public class DatabaseManager implements StorageService, StorageAdminService {
334 337
335 @Override 338 @Override
336 public <V> AtomicValueBuilder<V> atomicValueBuilder() { 339 public <V> AtomicValueBuilder<V> atomicValueBuilder() {
337 - return new DefaultAtomicValueBuilder<>(this); 340 + Supplier<ConsistentMapBuilder<String, byte[]>> mapBuilderSupplier =
341 + () -> this.<String, byte[]>consistentMapBuilder()
342 + .withName("onos-atomic-values")
343 + .withMeteringDisabled()
344 + .withSerializer(Serializer.using(KryoNamespaces.BASIC));
345 + return new DefaultAtomicValueBuilder<>(mapBuilderSupplier);
338 } 346 }
339 347
340 @Override 348 @Override
......
...@@ -15,7 +15,8 @@ ...@@ -15,7 +15,8 @@
15 */ 15 */
16 package org.onosproject.store.primitives.impl; 16 package org.onosproject.store.primitives.impl;
17 17
18 -import org.onosproject.store.serializers.KryoNamespaces; 18 +import java.util.function.Supplier;
19 +
19 import org.onosproject.store.service.AsyncAtomicValue; 20 import org.onosproject.store.service.AsyncAtomicValue;
20 import org.onosproject.store.service.AtomicValue; 21 import org.onosproject.store.service.AtomicValue;
21 import org.onosproject.store.service.AtomicValueBuilder; 22 import org.onosproject.store.service.AtomicValueBuilder;
...@@ -33,11 +34,8 @@ public class DefaultAtomicValueBuilder<V> implements AtomicValueBuilder<V> { ...@@ -33,11 +34,8 @@ public class DefaultAtomicValueBuilder<V> implements AtomicValueBuilder<V> {
33 private Serializer serializer; 34 private Serializer serializer;
34 private ConsistentMapBuilder<String, byte[]> mapBuilder; 35 private ConsistentMapBuilder<String, byte[]> mapBuilder;
35 36
36 - public DefaultAtomicValueBuilder(DatabaseManager manager) { 37 + public DefaultAtomicValueBuilder(Supplier<ConsistentMapBuilder<String, byte[]>> mapBuilderSupplier) {
37 - mapBuilder = manager.<String, byte[]>consistentMapBuilder() 38 + mapBuilder = mapBuilderSupplier.get();
38 - .withName("onos-atomic-values")
39 - .withMeteringDisabled()
40 - .withSerializer(Serializer.using(KryoNamespaces.BASIC));
41 } 39 }
42 40
43 @Override 41 @Override
......
...@@ -15,6 +15,8 @@ ...@@ -15,6 +15,8 @@
15 */ 15 */
16 package org.onosproject.store.primitives.impl; 16 package org.onosproject.store.primitives.impl;
17 17
18 +import java.util.function.Supplier;
19 +
18 import org.onosproject.core.ApplicationId; 20 import org.onosproject.core.ApplicationId;
19 import org.onosproject.store.service.AsyncDistributedSet; 21 import org.onosproject.store.service.AsyncDistributedSet;
20 import org.onosproject.store.service.ConsistentMapBuilder; 22 import org.onosproject.store.service.ConsistentMapBuilder;
...@@ -33,8 +35,8 @@ public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> ...@@ -33,8 +35,8 @@ public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E>
33 private ConsistentMapBuilder<E, Boolean> mapBuilder; 35 private ConsistentMapBuilder<E, Boolean> mapBuilder;
34 private boolean metering = true; 36 private boolean metering = true;
35 37
36 - public DefaultDistributedSetBuilder(DatabaseManager manager) { 38 + public DefaultDistributedSetBuilder(Supplier<ConsistentMapBuilder<E, Boolean>> mapBuilderSupplier) {
37 - this.mapBuilder = manager.consistentMapBuilder(); 39 + this.mapBuilder = mapBuilderSupplier.get();
38 mapBuilder.withMeteringDisabled(); 40 mapBuilder.withMeteringDisabled();
39 } 41 }
40 42
......