blob: 6621b4c9fa754b322646c0ad71489546a8454f11 [file] [log] [blame]
Madan Jampani50589ac2015-06-08 11:38:46 -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 */
Madan Jampanif4c88502016-01-21 12:35:36 -080016package org.onosproject.store.primitives.impl;
Madan Jampani50589ac2015-06-08 11:38:46 -070017
Madan Jampani1beb60c2016-02-03 12:14:57 -080018import java.util.function.Supplier;
19
Madan Jampanie8af1cc2015-06-23 14:23:31 -070020import org.onosproject.core.ApplicationId;
Madan Jampania090a112016-01-18 16:38:17 -080021import org.onosproject.store.service.AsyncDistributedSet;
Madan Jampani50589ac2015-06-08 11:38:46 -070022import org.onosproject.store.service.ConsistentMapBuilder;
23import org.onosproject.store.service.DistributedSet;
24import org.onosproject.store.service.Serializer;
25import org.onosproject.store.service.DistributedSetBuilder;
26
27/**
28 * Default distributed set builder.
29 *
30 * @param <E> type for set elements
31 */
32public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> {
33
34 private String name;
35 private ConsistentMapBuilder<E, Boolean> mapBuilder;
Flavio Castro41b1f3a2015-07-31 13:51:32 -070036 private boolean metering = true;
Madan Jampani50589ac2015-06-08 11:38:46 -070037
Madan Jampani1beb60c2016-02-03 12:14:57 -080038 public DefaultDistributedSetBuilder(Supplier<ConsistentMapBuilder<E, Boolean>> mapBuilderSupplier) {
39 this.mapBuilder = mapBuilderSupplier.get();
Flavio Castro41b1f3a2015-07-31 13:51:32 -070040 mapBuilder.withMeteringDisabled();
Madan Jampani50589ac2015-06-08 11:38:46 -070041 }
42
43 @Override
44 public DistributedSetBuilder<E> withName(String name) {
45 mapBuilder.withName(name);
46 this.name = name;
47 return this;
48 }
49
50 @Override
Madan Jampanie8af1cc2015-06-23 14:23:31 -070051 public DistributedSetBuilder<E> withApplicationId(ApplicationId id) {
52 mapBuilder.withApplicationId(id);
53 return this;
54 }
55
56 @Override
57 public DistributedSetBuilder<E> withPurgeOnUninstall() {
58 mapBuilder.withPurgeOnUninstall();
59 return this;
60 }
61
62 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070063 public DistributedSetBuilder<E> withSerializer(Serializer serializer) {
64 mapBuilder.withSerializer(serializer);
65 return this;
66 }
67
68 @Override
69 public DistributedSetBuilder<E> withUpdatesDisabled() {
70 mapBuilder.withUpdatesDisabled();
71 return this;
72 }
73
74 @Override
Madan Jampani216d8d72015-08-26 13:33:36 -070075 public DistributedSetBuilder<E> withRelaxedReadConsistency() {
76 mapBuilder.withRelaxedReadConsistency();
77 return this;
78 }
79
80 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070081 public DistributedSetBuilder<E> withPartitionsDisabled() {
82 mapBuilder.withPartitionsDisabled();
83 return this;
84 }
85
86 @Override
Flavio Castro41b1f3a2015-07-31 13:51:32 -070087 public DistributedSetBuilder<E> withMeteringDisabled() {
88 metering = false;
89 return this;
90 }
91
92 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070093 public DistributedSet<E> build() {
Madan Jampania090a112016-01-18 16:38:17 -080094 return new DefaultDistributedSet<E>(buildAsyncSet());
95 }
96
97 @Override
98 public AsyncDistributedSet<E> buildAsyncSet() {
99 return new DefaultAsyncDistributedSet<E>(mapBuilder.buildAsyncMap(), name, metering);
Madan Jampani50589ac2015-06-08 11:38:46 -0700100 }
101}