blob: a267de097b36e7a3cb6bd327baca9662380dadc8 [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;
34
35 public DefaultAtomicValueBuilder(DatabaseManager manager) {
36 mapBuilder = manager.<String, byte[]>consistentMapBuilder()
37 .withName("onos-atomic-values")
38 .withSerializer(Serializer.using(KryoNamespaces.BASIC));
39 }
40
41 @Override
42 public AtomicValueBuilder<V> withName(String name) {
43 this.name = name;
44 return this;
45 }
46
47 @Override
48 public AtomicValueBuilder<V> withSerializer(Serializer serializer) {
49 this.serializer = serializer;
50 return this;
51 }
52
53 @Override
54 public AtomicValueBuilder<V> withPartitionsDisabled() {
55 mapBuilder.withPartitionsDisabled();
56 return this;
57 }
58
59 @Override
60 public AtomicValue<V> build() {
61 return new DefaultAtomicValue<>(mapBuilder.build(), name, serializer);
62 }
63}