blob: d9910722135ef16c56a8e60460f90d6db4d07e14 [file] [log] [blame]
Madan Jampani619453b2015-07-22 23:47:09 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Madan Jampani619453b2015-07-22 23:47:09 -07003 *
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 Jampanif1b8e172015-03-23 11:42:02 -070016package org.onosproject.store.service;
17
Madan Jampani538be742016-02-10 14:55:38 -080018import org.onosproject.store.primitives.DistributedPrimitiveBuilder;
Madan Jampanif1b8e172015-03-23 11:42:02 -070019
20/**
Madan Jampanidfde6ba2016-01-13 21:36:09 -080021 * Builder for {@link ConsistentMap} instances.
Madan Jampanif1b8e172015-03-23 11:42:02 -070022 *
23 * @param <K> type for map key
24 * @param <V> type for map value
25 */
Madan Jampani538be742016-02-10 14:55:38 -080026public abstract class ConsistentMapBuilder<K, V>
27 extends DistributedPrimitiveBuilder<ConsistentMapBuilder<K, V>, ConsistentMap<K, V>> {
28
Jordan Halterman4922a062017-07-31 15:55:36 -070029 private boolean nullValues = false;
Madan Jampani538be742016-02-10 14:55:38 -080030 private boolean purgeOnUninstall = false;
31
32 public ConsistentMapBuilder() {
33 super(DistributedPrimitive.Type.CONSISTENT_MAP);
34 }
Madan Jampanif1b8e172015-03-23 11:42:02 -070035
36 /**
Jordan Halterman4922a062017-07-31 15:55:36 -070037 * Enables null values in the map.
38 *
39 * @return this builder
40 */
41 public ConsistentMapBuilder<K, V> withNullValues() {
42 nullValues = true;
43 return this;
44 }
45
46 /**
Madan Jampani538be742016-02-10 14:55:38 -080047 * Clears map contents when the owning application is uninstalled.
Madan Jampanif1b8e172015-03-23 11:42:02 -070048 *
Thomas Vachuska708d3032016-02-18 11:11:46 -080049 * @return this builder
Madan Jampanif1b8e172015-03-23 11:42:02 -070050 */
Madan Jampani538be742016-02-10 14:55:38 -080051 public ConsistentMapBuilder<K, V> withPurgeOnUninstall() {
52 purgeOnUninstall = true;
53 return this;
54 }
Madan Jampanif1b8e172015-03-23 11:42:02 -070055
56 /**
Jordan Halterman4922a062017-07-31 15:55:36 -070057 * Returns whether null values are supported by the map.
58 *
59 * @return {@code true} if null values are supported; {@code false} otherwise
60 */
61 public boolean nullValues() {
62 return nullValues;
63 }
64
65 /**
Madan Jampani538be742016-02-10 14:55:38 -080066 * Returns if map entries need to be cleared when owning application is uninstalled.
67 * @return {@code true} if yes; {@code false} otherwise.
Madan Jampanie8af1cc2015-06-23 14:23:31 -070068 */
Madan Jampani538be742016-02-10 14:55:38 -080069 public boolean purgeOnUninstall() {
70 return purgeOnUninstall;
71 }
Madan Jampanif1b8e172015-03-23 11:42:02 -070072
73 /**
74 * Builds an async consistent map based on the configuration options
75 * supplied to this builder.
76 *
77 * @return new async consistent map
78 * @throws java.lang.RuntimeException if a mandatory parameter is missing
79 */
Madan Jampani538be742016-02-10 14:55:38 -080080 public abstract AsyncConsistentMap<K, V> buildAsyncMap();
Sho SHIMIZU3310a342015-05-13 12:14:05 -070081}