blob: b17983c09bce37b3b7c6f91cfd746272fb747f59 [file] [log] [blame]
Madan Jampani762246d2015-07-21 15:40:59 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Madan Jampani762246d2015-07-21 15:40:59 -07003 *
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 */
Madan Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Madan Jampani762246d2015-07-21 15:40:59 -070017
Madan Jampani1beb60c2016-02-03 12:14:57 -080018import java.util.function.Supplier;
19
Madan Jampanidfde6ba2016-01-13 21:36:09 -080020import org.onosproject.store.service.AsyncAtomicValue;
Madan Jampani762246d2015-07-21 15:40:59 -070021import org.onosproject.store.service.AtomicValueBuilder;
22import org.onosproject.store.service.ConsistentMapBuilder;
Madan Jampanie17d3282016-02-03 15:30:57 -080023
24import static com.google.common.base.Preconditions.checkNotNull;
Madan Jampani762246d2015-07-21 15:40:59 -070025
26/**
27 * Default implementation of AtomicValueBuilder.
28 *
29 * @param <V> value type
30 */
Madan Jampanie17d3282016-02-03 15:30:57 -080031public class DefaultAtomicValueBuilder<V> extends AtomicValueBuilder<V> {
Madan Jampani762246d2015-07-21 15:40:59 -070032
Madan Jampani533ef982016-02-01 00:16:35 -080033 private ConsistentMapBuilder<String, byte[]> mapBuilder;
Madan Jampani762246d2015-07-21 15:40:59 -070034
Madan Jampani1beb60c2016-02-03 12:14:57 -080035 public DefaultAtomicValueBuilder(Supplier<ConsistentMapBuilder<String, byte[]>> mapBuilderSupplier) {
36 mapBuilder = mapBuilderSupplier.get();
Madan Jampani762246d2015-07-21 15:40:59 -070037 }
38
39 @Override
Madan Jampanie17d3282016-02-03 15:30:57 -080040 public AsyncAtomicValue<V> build() {
41 return new DefaultAsyncAtomicValue<>(checkNotNull(name()),
42 checkNotNull(serializer()),
43 mapBuilder.buildAsyncMap());
Madan Jampani762246d2015-07-21 15:40:59 -070044 }
Madan Jampanie17d3282016-02-03 15:30:57 -080045}