blob: a63fe4be933ca97370b68852d2cb7b227d9182d1 [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
Jordan Halterman9bdc24f2017-04-19 23:45:12 -070018import java.util.concurrent.Executor;
Madan Jampani1beb60c2016-02-03 12:14:57 -080019import java.util.function.Supplier;
20
Madan Jampanidfde6ba2016-01-13 21:36:09 -080021import org.onosproject.store.service.AsyncAtomicValue;
Madan Jampani762246d2015-07-21 15:40:59 -070022import org.onosproject.store.service.AtomicValueBuilder;
23import org.onosproject.store.service.ConsistentMapBuilder;
Madan Jampanie17d3282016-02-03 15:30:57 -080024
25import static com.google.common.base.Preconditions.checkNotNull;
Madan Jampani762246d2015-07-21 15:40:59 -070026
27/**
28 * Default implementation of AtomicValueBuilder.
29 *
30 * @param <V> value type
31 */
Madan Jampanie17d3282016-02-03 15:30:57 -080032public class DefaultAtomicValueBuilder<V> extends AtomicValueBuilder<V> {
Madan Jampani762246d2015-07-21 15:40:59 -070033
Madan Jampani533ef982016-02-01 00:16:35 -080034 private ConsistentMapBuilder<String, byte[]> mapBuilder;
Madan Jampani762246d2015-07-21 15:40:59 -070035
Madan Jampani1beb60c2016-02-03 12:14:57 -080036 public DefaultAtomicValueBuilder(Supplier<ConsistentMapBuilder<String, byte[]>> mapBuilderSupplier) {
37 mapBuilder = mapBuilderSupplier.get();
Madan Jampani762246d2015-07-21 15:40:59 -070038 }
39
40 @Override
Jordan Halterman9bdc24f2017-04-19 23:45:12 -070041 public AtomicValueBuilder<V> withExecutorSupplier(Supplier<Executor> executorSupplier) {
42 mapBuilder.withExecutorSupplier(executorSupplier);
43 return this;
44 }
45
46 @Override
Madan Jampanie17d3282016-02-03 15:30:57 -080047 public AsyncAtomicValue<V> build() {
48 return new DefaultAsyncAtomicValue<>(checkNotNull(name()),
49 checkNotNull(serializer()),
50 mapBuilder.buildAsyncMap());
Madan Jampani762246d2015-07-21 15:40:59 -070051 }
Madan Jampanie17d3282016-02-03 15:30:57 -080052}