blob: b39004b38c744dd786cf513b103c1ec1d6207faf [file] [log] [blame]
Madan Jampani762246d2015-07-21 15:40:59 -07001/*
2 * Copyright 2015 Open Networking Laboratory
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.store.consistent.impl;
17
18import org.onosproject.store.serializers.KryoNamespaces;
19import org.onosproject.store.service.AtomicValue;
20import org.onosproject.store.service.AtomicValueBuilder;
21import org.onosproject.store.service.ConsistentMapBuilder;
22import org.onosproject.store.service.Serializer;
23
24/**
25 * Default implementation of AtomicValueBuilder.
26 *
27 * @param <V> value type
28 */
29public class DefaultAtomicValueBuilder<V> implements AtomicValueBuilder<V> {
30
31 private Serializer serializer;
32 private String name;
33 private ConsistentMapBuilder<String, byte[]> mapBuilder;
Flavio Castro41b1f3a2015-07-31 13:51:32 -070034 private boolean metering = true;
Madan Jampani762246d2015-07-21 15:40:59 -070035
36 public DefaultAtomicValueBuilder(DatabaseManager manager) {
37 mapBuilder = manager.<String, byte[]>consistentMapBuilder()
38 .withName("onos-atomic-values")
Flavio Castro41b1f3a2015-07-31 13:51:32 -070039 .withMeteringDisabled()
Madan Jampani762246d2015-07-21 15:40:59 -070040 .withSerializer(Serializer.using(KryoNamespaces.BASIC));
41 }
42
43 @Override
44 public AtomicValueBuilder<V> withName(String name) {
45 this.name = name;
46 return this;
47 }
48
49 @Override
50 public AtomicValueBuilder<V> withSerializer(Serializer serializer) {
51 this.serializer = serializer;
52 return this;
53 }
54
55 @Override
56 public AtomicValueBuilder<V> withPartitionsDisabled() {
57 mapBuilder.withPartitionsDisabled();
58 return this;
59 }
60
61 @Override
Flavio Castro41b1f3a2015-07-31 13:51:32 -070062 public AtomicValueBuilder<V> withMeteringDisabled() {
63 metering = false;
64 return this;
65 }
66
67 @Override
Madan Jampani762246d2015-07-21 15:40:59 -070068 public AtomicValue<V> build() {
Flavio Castro41b1f3a2015-07-31 13:51:32 -070069 return new DefaultAtomicValue<>(mapBuilder.build(), name, metering, serializer);
Madan Jampani762246d2015-07-21 15:40:59 -070070 }
71}