blob: 304044ce0610c329a4481b4b67d00a5893d4f71b [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 Jampanie8af1cc2015-06-23 14:23:31 -070018import org.onosproject.core.ApplicationId;
Madan Jampania090a112016-01-18 16:38:17 -080019import org.onosproject.store.service.AsyncDistributedSet;
Madan Jampani50589ac2015-06-08 11:38:46 -070020import org.onosproject.store.service.ConsistentMapBuilder;
21import org.onosproject.store.service.DistributedSet;
22import org.onosproject.store.service.Serializer;
23import org.onosproject.store.service.DistributedSetBuilder;
24
25/**
26 * Default distributed set builder.
27 *
28 * @param <E> type for set elements
29 */
30public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> {
31
32 private String name;
33 private ConsistentMapBuilder<E, Boolean> mapBuilder;
Flavio Castro41b1f3a2015-07-31 13:51:32 -070034 private boolean metering = true;
Madan Jampani50589ac2015-06-08 11:38:46 -070035
36 public DefaultDistributedSetBuilder(DatabaseManager manager) {
37 this.mapBuilder = manager.consistentMapBuilder();
Flavio Castro41b1f3a2015-07-31 13:51:32 -070038 mapBuilder.withMeteringDisabled();
Madan Jampani50589ac2015-06-08 11:38:46 -070039 }
40
41 @Override
42 public DistributedSetBuilder<E> withName(String name) {
43 mapBuilder.withName(name);
44 this.name = name;
45 return this;
46 }
47
48 @Override
Madan Jampanie8af1cc2015-06-23 14:23:31 -070049 public DistributedSetBuilder<E> withApplicationId(ApplicationId id) {
50 mapBuilder.withApplicationId(id);
51 return this;
52 }
53
54 @Override
55 public DistributedSetBuilder<E> withPurgeOnUninstall() {
56 mapBuilder.withPurgeOnUninstall();
57 return this;
58 }
59
60 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070061 public DistributedSetBuilder<E> withSerializer(Serializer serializer) {
62 mapBuilder.withSerializer(serializer);
63 return this;
64 }
65
66 @Override
67 public DistributedSetBuilder<E> withUpdatesDisabled() {
68 mapBuilder.withUpdatesDisabled();
69 return this;
70 }
71
72 @Override
Madan Jampani216d8d72015-08-26 13:33:36 -070073 public DistributedSetBuilder<E> withRelaxedReadConsistency() {
74 mapBuilder.withRelaxedReadConsistency();
75 return this;
76 }
77
78 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070079 public DistributedSetBuilder<E> withPartitionsDisabled() {
80 mapBuilder.withPartitionsDisabled();
81 return this;
82 }
83
84 @Override
Flavio Castro41b1f3a2015-07-31 13:51:32 -070085 public DistributedSetBuilder<E> withMeteringDisabled() {
86 metering = false;
87 return this;
88 }
89
90 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070091 public DistributedSet<E> build() {
Madan Jampania090a112016-01-18 16:38:17 -080092 return new DefaultDistributedSet<E>(buildAsyncSet());
93 }
94
95 @Override
96 public AsyncDistributedSet<E> buildAsyncSet() {
97 return new DefaultAsyncDistributedSet<E>(mapBuilder.buildAsyncMap(), name, metering);
Madan Jampani50589ac2015-06-08 11:38:46 -070098 }
99}