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;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import net.kuujo.copycat.CopycatConfig;
......@@ -65,6 +66,7 @@ import org.onosproject.core.ApplicationId;
import org.onosproject.core.IdGenerator;
import org.onosproject.persistence.PersistenceService;
import org.onosproject.store.cluster.messaging.ClusterCommunicationService;
import org.onosproject.store.serializers.KryoNamespaces;
import org.onosproject.store.service.AtomicCounterBuilder;
import org.onosproject.store.service.AtomicValueBuilder;
import org.onosproject.store.service.ConsistentMapBuilder;
......@@ -74,6 +76,7 @@ import org.onosproject.store.service.DistributedSetBuilder;
import org.onosproject.store.service.EventuallyConsistentMapBuilder;
import org.onosproject.store.service.MapInfo;
import org.onosproject.store.service.PartitionInfo;
import org.onosproject.store.service.Serializer;
import org.onosproject.store.service.StorageAdminService;
import org.onosproject.store.service.StorageService;
import org.onosproject.store.service.Transaction;
......@@ -318,7 +321,7 @@ public class DatabaseManager implements StorageService, StorageAdminService {
@Override
public <E> DistributedSetBuilder<E> setBuilder() {
return new DefaultDistributedSetBuilder<>(this);
return new DefaultDistributedSetBuilder<>(() -> this.<E, Boolean>consistentMapBuilder());
}
......@@ -334,7 +337,12 @@ public class DatabaseManager implements StorageService, StorageAdminService {
@Override
public <V> AtomicValueBuilder<V> atomicValueBuilder() {
return new DefaultAtomicValueBuilder<>(this);
Supplier<ConsistentMapBuilder<String, byte[]>> mapBuilderSupplier =
() -> this.<String, byte[]>consistentMapBuilder()
.withName("onos-atomic-values")
.withMeteringDisabled()
.withSerializer(Serializer.using(KryoNamespaces.BASIC));
return new DefaultAtomicValueBuilder<>(mapBuilderSupplier);
}
@Override
......
......@@ -15,7 +15,8 @@
*/
package org.onosproject.store.primitives.impl;
import org.onosproject.store.serializers.KryoNamespaces;
import java.util.function.Supplier;
import org.onosproject.store.service.AsyncAtomicValue;
import org.onosproject.store.service.AtomicValue;
import org.onosproject.store.service.AtomicValueBuilder;
......@@ -33,11 +34,8 @@ public class DefaultAtomicValueBuilder<V> implements AtomicValueBuilder<V> {
private Serializer serializer;
private ConsistentMapBuilder<String, byte[]> mapBuilder;
public DefaultAtomicValueBuilder(DatabaseManager manager) {
mapBuilder = manager.<String, byte[]>consistentMapBuilder()
.withName("onos-atomic-values")
.withMeteringDisabled()
.withSerializer(Serializer.using(KryoNamespaces.BASIC));
public DefaultAtomicValueBuilder(Supplier<ConsistentMapBuilder<String, byte[]>> mapBuilderSupplier) {
mapBuilder = mapBuilderSupplier.get();
}
@Override
......
......@@ -15,6 +15,8 @@
*/
package org.onosproject.store.primitives.impl;
import java.util.function.Supplier;
import org.onosproject.core.ApplicationId;
import org.onosproject.store.service.AsyncDistributedSet;
import org.onosproject.store.service.ConsistentMapBuilder;
......@@ -33,8 +35,8 @@ public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E>
private ConsistentMapBuilder<E, Boolean> mapBuilder;
private boolean metering = true;
public DefaultDistributedSetBuilder(DatabaseManager manager) {
this.mapBuilder = manager.consistentMapBuilder();
public DefaultDistributedSetBuilder(Supplier<ConsistentMapBuilder<E, Boolean>> mapBuilderSupplier) {
this.mapBuilder = mapBuilderSupplier.get();
mapBuilder.withMeteringDisabled();
}
......