blob: 466c8f14fb36e2810f35dc53e0a3f716fe50aa46 [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/**
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 */
26public interface ConsistentMapBuilder<K, V> {
27
28 /**
29 * Sets the name of the map.
30 * <p>
Madan Jampanidfde6ba2016-01-13 21:36:09 -080031 * Each map is identified by a unique map name. Different instances with the same name are all backed by the
32 * same backend state.
Madan Jampanif1b8e172015-03-23 11:42:02 -070033 * </p>
34 * <p>
Madan Jampanidfde6ba2016-01-13 21:36:09 -080035 * <b>Note:</b> This is a mandatory parameter.
Madan Jampanif1b8e172015-03-23 11:42:02 -070036 * </p>
37 *
Madan Jampanidfde6ba2016-01-13 21:36:09 -080038 * @param name name of the map
Madan Jampanif1b8e172015-03-23 11:42:02 -070039 * @return this ConsistentMapBuilder
40 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070041 ConsistentMapBuilder<K, V> withName(String name);
Madan Jampanif1b8e172015-03-23 11:42:02 -070042
43 /**
Madan Jampanidfde6ba2016-01-13 21:36:09 -080044 * Sets the identifier of the application that owns this map instance.
Madan Jampanie8af1cc2015-06-23 14:23:31 -070045 * <p>
46 * Note: If {@code purgeOnUninstall} option is enabled, applicationId
47 * must be specified.
48 * </p>
49 *
50 * @param id applicationId owning the consistent map
51 * @return this ConsistentMapBuilder
52 */
53 ConsistentMapBuilder<K, V> withApplicationId(ApplicationId id);
54
55 /**
Madan Jampanif1b8e172015-03-23 11:42:02 -070056 * Sets a serializer that can be used to serialize
57 * both the keys and values inserted into the map. The serializer
58 * builder should be pre-populated with any classes that will be
59 * put into the map.
60 * <p>
61 * Note: This is a mandatory parameter.
62 * </p>
63 *
64 * @param serializer serializer
65 * @return this ConsistentMapBuilder
66 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070067 ConsistentMapBuilder<K, V> withSerializer(Serializer serializer);
Madan Jampanif1b8e172015-03-23 11:42:02 -070068
69 /**
70 * Disables distribution of map entries across multiple database partitions.
71 * <p>
72 * When partitioning is disabled, the returned map will have a single partition
73 * that spans the entire cluster. Furthermore, the changes made to the map are
74 * ephemeral and do not survive a full cluster restart.
75 * </p>
76 * <p>
77 * Disabling partitions is more appropriate when the returned map is used for
78 * coordination activities such as leader election and not for long term data persistence.
79 * </p>
80 * <p>
81 * Note: By default partitions are enabled and entries in the map are durable.
82 * </p>
83 * @return this ConsistentMapBuilder
84 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070085 ConsistentMapBuilder<K, V> withPartitionsDisabled();
Madan Jampanif1b8e172015-03-23 11:42:02 -070086
87 /**
Madan Jampani02b7fb82015-05-01 13:01:20 -070088 * Disables map updates.
89 * <p>
90 * Attempt to update the built map will throw {@code UnsupportedOperationException}.
91 *
92 * @return this ConsistentMapBuilder
93 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070094 ConsistentMapBuilder<K, V> withUpdatesDisabled();
Madan Jampani02b7fb82015-05-01 13:01:20 -070095
96 /**
Madan Jampanie8af1cc2015-06-23 14:23:31 -070097 * Purges map contents when the application owning the map is uninstalled.
98 * <p>
99 * When this option is enabled, the caller must provide a applicationId via
100 * the {@code withAppliationId} builder method.
101 * <p>
102 * By default map entries will NOT be purged when owning application is uninstalled.
103 *
104 * @return this ConsistentMapBuilder
105 */
106 ConsistentMapBuilder<K, V> withPurgeOnUninstall();
107
108 /**
Flavio Castro41b1f3a2015-07-31 13:51:32 -0700109 * Instantiates Metering service to gather usage and performance metrics.
110 * By default, usage data will be stored.
111 *
112 * @return this ConsistentMapBuilder
113 */
114 ConsistentMapBuilder<K, V> withMeteringDisabled();
115
116 /**
Madan Jampani3d6a2f62015-08-12 07:19:07 -0700117 * Provides weak consistency for map gets.
118 * <p>
119 * While this can lead to improved read performance, it can also make the behavior
120 * heard to reason. Only turn this on if you know what you are doing. By default
121 * reads are strongly consistent.
122 *
123 * @return this ConsistentMapBuilder
124 */
125 ConsistentMapBuilder<K, V> withRelaxedReadConsistency();
126
127 /**
Madan Jampanif1b8e172015-03-23 11:42:02 -0700128 * Builds an consistent map based on the configuration options
129 * supplied to this builder.
130 *
131 * @return new consistent map
132 * @throws java.lang.RuntimeException if a mandatory parameter is missing
133 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700134 ConsistentMap<K, V> build();
Madan Jampanif1b8e172015-03-23 11:42:02 -0700135
136 /**
137 * Builds an async consistent map based on the configuration options
138 * supplied to this builder.
139 *
140 * @return new async consistent map
141 * @throws java.lang.RuntimeException if a mandatory parameter is missing
142 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700143 AsyncConsistentMap<K, V> buildAsyncMap();
144}