blob: 50b3fea0780b1fc871b462f7432587f55e696d07 [file] [log] [blame]
Madan Jampani7e55c662016-02-15 21:13:53 -08001/*
2 * Copyright 2016 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.primitives.impl;
17
18import org.onosproject.store.primitives.DistributedPrimitiveCreator;
19import org.onosproject.store.service.AsyncConsistentMap;
20import org.onosproject.store.service.ConsistentMap;
21import org.onosproject.store.service.ConsistentMapBuilder;
22
23/**
24 * Default {@link AsyncConsistentMap} builder.
25 *
26 * @param <K> type for map key
27 * @param <V> type for map value
28 */
29public class NewDefaultConsistentMapBuilder<K, V> extends ConsistentMapBuilder<K, V> {
30
31 private final DistributedPrimitiveCreator base;
32 private final DistributedPrimitiveCreator federated;
33
34 public NewDefaultConsistentMapBuilder(DistributedPrimitiveCreator base, DistributedPrimitiveCreator federated) {
35 this.base = base;
36 this.federated = federated;
37 }
38
39 @Override
40 public ConsistentMap<K, V> build() {
41 return buildAsyncMap().asConsistentMap();
42 }
43
44 @Override
45 public AsyncConsistentMap<K, V> buildAsyncMap() {
46 DistributedPrimitiveCreator creator = partitionsDisabled() ? base : federated;
47 AsyncConsistentMap<K, V> map = creator.newAsyncConsistentMap(name(), serializer());
48 map = relaxedReadConsistency() ? DistributedPrimitives.newCachingMap(map) : map;
49 map = readOnly() ? DistributedPrimitives.newUnmodifiableMap(map) : map;
50 return meteringEnabled() ? DistributedPrimitives.newMeteredMap(map) : map;
51 }
52}