Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 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 | */ |
Madan Jampani | f4c8850 | 2016-01-21 12:35:36 -0800 | [diff] [blame] | 16 | package org.onosproject.store.primitives.impl; |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 17 | |
Madan Jampani | 1beb60c | 2016-02-03 12:14:57 -0800 | [diff] [blame] | 18 | import java.util.function.Supplier; |
| 19 | |
Madan Jampani | dfde6ba | 2016-01-13 21:36:09 -0800 | [diff] [blame] | 20 | import org.onosproject.store.service.AsyncAtomicValue; |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 21 | import org.onosproject.store.service.AtomicValueBuilder; |
| 22 | import org.onosproject.store.service.ConsistentMapBuilder; |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 23 | |
| 24 | import static com.google.common.base.Preconditions.checkNotNull; |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Default implementation of AtomicValueBuilder. |
| 28 | * |
| 29 | * @param <V> value type |
| 30 | */ |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 31 | public class DefaultAtomicValueBuilder<V> extends AtomicValueBuilder<V> { |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 32 | |
Madan Jampani | 533ef98 | 2016-02-01 00:16:35 -0800 | [diff] [blame] | 33 | private ConsistentMapBuilder<String, byte[]> mapBuilder; |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 34 | |
Madan Jampani | 1beb60c | 2016-02-03 12:14:57 -0800 | [diff] [blame] | 35 | public DefaultAtomicValueBuilder(Supplier<ConsistentMapBuilder<String, byte[]>> mapBuilderSupplier) { |
| 36 | mapBuilder = mapBuilderSupplier.get(); |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 37 | } |
| 38 | |
| 39 | @Override |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 40 | public AsyncAtomicValue<V> build() { |
| 41 | return new DefaultAsyncAtomicValue<>(checkNotNull(name()), |
| 42 | checkNotNull(serializer()), |
| 43 | mapBuilder.buildAsyncMap()); |
Madan Jampani | 762246d | 2015-07-21 15:40:59 -0700 | [diff] [blame] | 44 | } |
Madan Jampani | e17d328 | 2016-02-03 15:30:57 -0800 | [diff] [blame] | 45 | } |