blob: eb2583bdfea457287d7b0aae3916235f4a7d41f3 [file] [log] [blame]
Madan Jampanif1b8e172015-03-23 11:42:02 -07001package org.onosproject.store.service;
2
Madan Jampanie8af1cc2015-06-23 14:23:31 -07003import org.onosproject.core.ApplicationId;
Madan Jampanif1b8e172015-03-23 11:42:02 -07004
5/**
6 * Builder for consistent maps.
7 *
8 * @param <K> type for map key
9 * @param <V> type for map value
10 */
11public interface ConsistentMapBuilder<K, V> {
12
13 /**
14 * Sets the name of the map.
15 * <p>
16 * Each consistent map is identified by a unique map name.
17 * </p>
18 * <p>
19 * Note: This is a mandatory parameter.
20 * </p>
21 *
22 * @param name name of the consistent map
23 * @return this ConsistentMapBuilder
24 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070025 ConsistentMapBuilder<K, V> withName(String name);
Madan Jampanif1b8e172015-03-23 11:42:02 -070026
27 /**
Madan Jampanie8af1cc2015-06-23 14:23:31 -070028 * Sets the owner applicationId for the map.
29 * <p>
30 * Note: If {@code purgeOnUninstall} option is enabled, applicationId
31 * must be specified.
32 * </p>
33 *
34 * @param id applicationId owning the consistent map
35 * @return this ConsistentMapBuilder
36 */
37 ConsistentMapBuilder<K, V> withApplicationId(ApplicationId id);
38
39 /**
Madan Jampanif1b8e172015-03-23 11:42:02 -070040 * Sets a serializer that can be used to serialize
41 * both the keys and values inserted into the map. The serializer
42 * builder should be pre-populated with any classes that will be
43 * put into the map.
44 * <p>
45 * Note: This is a mandatory parameter.
46 * </p>
47 *
48 * @param serializer serializer
49 * @return this ConsistentMapBuilder
50 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070051 ConsistentMapBuilder<K, V> withSerializer(Serializer serializer);
Madan Jampanif1b8e172015-03-23 11:42:02 -070052
53 /**
54 * Disables distribution of map entries across multiple database partitions.
55 * <p>
56 * When partitioning is disabled, the returned map will have a single partition
57 * that spans the entire cluster. Furthermore, the changes made to the map are
58 * ephemeral and do not survive a full cluster restart.
59 * </p>
60 * <p>
61 * Disabling partitions is more appropriate when the returned map is used for
62 * coordination activities such as leader election and not for long term data persistence.
63 * </p>
64 * <p>
65 * Note: By default partitions are enabled and entries in the map are durable.
66 * </p>
67 * @return this ConsistentMapBuilder
68 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070069 ConsistentMapBuilder<K, V> withPartitionsDisabled();
Madan Jampanif1b8e172015-03-23 11:42:02 -070070
71 /**
Madan Jampani02b7fb82015-05-01 13:01:20 -070072 * Disables map updates.
73 * <p>
74 * Attempt to update the built map will throw {@code UnsupportedOperationException}.
75 *
76 * @return this ConsistentMapBuilder
77 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070078 ConsistentMapBuilder<K, V> withUpdatesDisabled();
Madan Jampani02b7fb82015-05-01 13:01:20 -070079
80 /**
Madan Jampanie8af1cc2015-06-23 14:23:31 -070081 * Purges map contents when the application owning the map is uninstalled.
82 * <p>
83 * When this option is enabled, the caller must provide a applicationId via
84 * the {@code withAppliationId} builder method.
85 * <p>
86 * By default map entries will NOT be purged when owning application is uninstalled.
87 *
88 * @return this ConsistentMapBuilder
89 */
90 ConsistentMapBuilder<K, V> withPurgeOnUninstall();
91
92 /**
Madan Jampanif1b8e172015-03-23 11:42:02 -070093 * Builds an consistent map based on the configuration options
94 * supplied to this builder.
95 *
96 * @return new consistent map
97 * @throws java.lang.RuntimeException if a mandatory parameter is missing
98 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -070099 ConsistentMap<K, V> build();
Madan Jampanif1b8e172015-03-23 11:42:02 -0700100
101 /**
102 * Builds an async consistent map based on the configuration options
103 * supplied to this builder.
104 *
105 * @return new async consistent map
106 * @throws java.lang.RuntimeException if a mandatory parameter is missing
107 */
Sho SHIMIZU3310a342015-05-13 12:14:05 -0700108 AsyncConsistentMap<K, V> buildAsyncMap();
109}