blob: 847adaf61558ce3747a984459fd6b27a5e54185d [file] [log] [blame]
Madan Jampani619453b2015-07-22 23:47:09 -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 Jampanif1b8e172015-03-23 11:42:02 -070016package org.onosproject.store.service;
17
Madan Jampanie8af1cc2015-06-23 14:23:31 -070018import org.onosproject.core.ApplicationId;
Madan Jampanif1b8e172015-03-23 11:42:02 -070019
20/**
21 * Builder for consistent maps.
22 *
23 * @param <K> type for map key
24 * @param <V> type for map value
25 */
26public interface ConsistentMapBuilder<K, V> {
27
28 /**
29 * Sets the name of the map.
30 * <p>
31 * Each consistent map is identified by a unique map name.
32 * </p>
33 * <p>
34 * Note: This is a mandatory parameter.
35 * </p>
36 *
37 * @param name name of the consistent map
38 * @return this ConsistentMapBuilder
39 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070040 ConsistentMapBuilder<K, V> withName(String name);
Madan Jampanif1b8e172015-03-23 11:42:02 -070041
42 /**
Madan Jampanie8af1cc2015-06-23 14:23:31 -070043 * Sets the owner applicationId for the map.
44 * <p>
45 * Note: If {@code purgeOnUninstall} option is enabled, applicationId
46 * must be specified.
47 * </p>
48 *
49 * @param id applicationId owning the consistent map
50 * @return this ConsistentMapBuilder
51 */
52 ConsistentMapBuilder<K, V> withApplicationId(ApplicationId id);
53
54 /**
Madan Jampanif1b8e172015-03-23 11:42:02 -070055 * Sets a serializer that can be used to serialize
56 * both the keys and values inserted into the map. The serializer
57 * builder should be pre-populated with any classes that will be
58 * put into the map.
59 * <p>
60 * Note: This is a mandatory parameter.
61 * </p>
62 *
63 * @param serializer serializer
64 * @return this ConsistentMapBuilder
65 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070066 ConsistentMapBuilder<K, V> withSerializer(Serializer serializer);
Madan Jampanif1b8e172015-03-23 11:42:02 -070067
68 /**
69 * Disables distribution of map entries across multiple database partitions.
70 * <p>
71 * When partitioning is disabled, the returned map will have a single partition
72 * that spans the entire cluster. Furthermore, the changes made to the map are
73 * ephemeral and do not survive a full cluster restart.
74 * </p>
75 * <p>
76 * Disabling partitions is more appropriate when the returned map is used for
77 * coordination activities such as leader election and not for long term data persistence.
78 * </p>
79 * <p>
80 * Note: By default partitions are enabled and entries in the map are durable.
81 * </p>
82 * @return this ConsistentMapBuilder
83 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070084 ConsistentMapBuilder<K, V> withPartitionsDisabled();
Madan Jampanif1b8e172015-03-23 11:42:02 -070085
86 /**
Madan Jampani02b7fb82015-05-01 13:01:20 -070087 * Disables map updates.
88 * <p>
89 * Attempt to update the built map will throw {@code UnsupportedOperationException}.
90 *
91 * @return this ConsistentMapBuilder
92 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070093 ConsistentMapBuilder<K, V> withUpdatesDisabled();
Madan Jampani02b7fb82015-05-01 13:01:20 -070094
95 /**
Madan Jampanie8af1cc2015-06-23 14:23:31 -070096 * Purges map contents when the application owning the map is uninstalled.
97 * <p>
98 * When this option is enabled, the caller must provide a applicationId via
99 * the {@code withAppliationId} builder method.
100 * <p>
101 * By default map entries will NOT be purged when owning application is uninstalled.
102 *
103 * @return this ConsistentMapBuilder
104 */
105 ConsistentMapBuilder<K, V> withPurgeOnUninstall();
106
107 /**
Flavio Castro41b1f3a2015-07-31 13:51:32 -0700108 * Instantiates Metering service to gather usage and performance metrics.
109 * By default, usage data will be stored.
110 *
111 * @return this ConsistentMapBuilder
112 */
113 ConsistentMapBuilder<K, V> withMeteringDisabled();
114
115 /**
Madan Jampani3d6a2f62015-08-12 07:19:07 -0700116 * Provides weak consistency for map gets.
117 * <p>
118 * While this can lead to improved read performance, it can also make the behavior
119 * heard to reason. Only turn this on if you know what you are doing. By default
120 * reads are strongly consistent.
121 *
122 * @return this ConsistentMapBuilder
123 */
124 ConsistentMapBuilder<K, V> withRelaxedReadConsistency();
125
126 /**
Madan Jampanif1b8e172015-03-23 11:42:02 -0700127 * Builds an consistent map based on the configuration options
128 * supplied to this builder.
129 *
130 * @return new consistent map
131 * @throws java.lang.RuntimeException if a mandatory parameter is missing
132 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700133 ConsistentMap<K, V> build();
Madan Jampanif1b8e172015-03-23 11:42:02 -0700134
135 /**
136 * Builds an async consistent map based on the configuration options
137 * supplied to this builder.
138 *
139 * @return new async consistent map
140 * @throws java.lang.RuntimeException if a mandatory parameter is missing
141 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700142 AsyncConsistentMap<K, V> buildAsyncMap();
143}