Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
| 16 | package org.onosproject.store.consistent.impl; |
| 17 | |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationId; |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 19 | import org.onosproject.store.service.ConsistentMapBuilder; |
| 20 | import org.onosproject.store.service.DistributedSet; |
| 21 | import org.onosproject.store.service.Serializer; |
| 22 | import org.onosproject.store.service.DistributedSetBuilder; |
| 23 | |
| 24 | /** |
| 25 | * Default distributed set builder. |
| 26 | * |
| 27 | * @param <E> type for set elements |
| 28 | */ |
| 29 | public class DefaultDistributedSetBuilder<E> implements DistributedSetBuilder<E> { |
| 30 | |
| 31 | private String name; |
| 32 | private ConsistentMapBuilder<E, Boolean> mapBuilder; |
Flavio Castro | 41b1f3a | 2015-07-31 13:51:32 -0700 | [diff] [blame] | 33 | private boolean metering = true; |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 34 | |
| 35 | public DefaultDistributedSetBuilder(DatabaseManager manager) { |
| 36 | this.mapBuilder = manager.consistentMapBuilder(); |
Flavio Castro | 41b1f3a | 2015-07-31 13:51:32 -0700 | [diff] [blame] | 37 | mapBuilder.withMeteringDisabled(); |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 38 | } |
| 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 Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 48 | 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 Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 60 | 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 Castro | 41b1f3a | 2015-07-31 13:51:32 -0700 | [diff] [blame] | 78 | public DistributedSetBuilder<E> withMeteringDisabled() { |
| 79 | metering = false; |
| 80 | return this; |
| 81 | } |
| 82 | |
| 83 | @Override |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 84 | public DistributedSet<E> build() { |
Flavio Castro | 41b1f3a | 2015-07-31 13:51:32 -0700 | [diff] [blame] | 85 | return new DefaultDistributedSet<E>(name, metering, mapBuilder.build()); |
Madan Jampani | 50589ac | 2015-06-08 11:38:46 -0700 | [diff] [blame] | 86 | } |
| 87 | } |