blob: 07b59ad4f6540365491900cbb92c77f8d016d6f4 [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 */
16package org.onosproject.store.consistent.impl;
17
Madan Jampanie8af1cc2015-06-23 14:23:31 -070018import org.onosproject.core.ApplicationId;
Madan Jampani50589ac2015-06-08 11:38:46 -070019import org.onosproject.store.service.ConsistentMapBuilder;
20import org.onosproject.store.service.DistributedSet;
21import org.onosproject.store.service.Serializer;
22import org.onosproject.store.service.DistributedSetBuilder;
23
24/**
25 * Default distributed set builder.
26 *
27 * @param <E> type for set elements
28 */
29public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> {
30
31 private String name;
32 private ConsistentMapBuilder<E, Boolean> mapBuilder;
Flavio Castro41b1f3a2015-07-31 13:51:32 -070033 private boolean metering = true;
Madan Jampani50589ac2015-06-08 11:38:46 -070034
35 public DefaultDistributedSetBuilder(DatabaseManager manager) {
36 this.mapBuilder = manager.consistentMapBuilder();
Flavio Castro41b1f3a2015-07-31 13:51:32 -070037 mapBuilder.withMeteringDisabled();
Madan Jampani50589ac2015-06-08 11:38:46 -070038 }
39
40 @Override
41 public DistributedSetBuilder<E> withName(String name) {
42 mapBuilder.withName(name);
43 this.name = name;
44 return this;
45 }
46
47 @Override
Madan Jampanie8af1cc2015-06-23 14:23:31 -070048 public DistributedSetBuilder<E> withApplicationId(ApplicationId id) {
49 mapBuilder.withApplicationId(id);
50 return this;
51 }
52
53 @Override
54 public DistributedSetBuilder<E> withPurgeOnUninstall() {
55 mapBuilder.withPurgeOnUninstall();
56 return this;
57 }
58
59 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070060 public DistributedSetBuilder<E> withSerializer(Serializer serializer) {
61 mapBuilder.withSerializer(serializer);
62 return this;
63 }
64
65 @Override
66 public DistributedSetBuilder<E> withUpdatesDisabled() {
67 mapBuilder.withUpdatesDisabled();
68 return this;
69 }
70
71 @Override
72 public DistributedSetBuilder<E> withPartitionsDisabled() {
73 mapBuilder.withPartitionsDisabled();
74 return this;
75 }
76
77 @Override
Flavio Castro41b1f3a2015-07-31 13:51:32 -070078 public DistributedSetBuilder<E> withMeteringDisabled() {
79 metering = false;
80 return this;
81 }
82
83 @Override
Madan Jampani50589ac2015-06-08 11:38:46 -070084 public DistributedSet<E> build() {
Flavio Castro41b1f3a2015-07-31 13:51:32 -070085 return new DefaultDistributedSet<E>(name, metering, mapBuilder.build());
Madan Jampani50589ac2015-06-08 11:38:46 -070086 }
87}