Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 1 | package org.onosproject.store.service; |
| 2 | |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 3 | import org.onosproject.core.ApplicationId; |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 4 | |
| 5 | /** |
| 6 | * Builder for consistent maps. |
| 7 | * |
| 8 | * @param <K> type for map key |
| 9 | * @param <V> type for map value |
| 10 | */ |
| 11 | public 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 25 | ConsistentMapBuilder<K, V> withName(String name); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 26 | |
| 27 | /** |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 28 | * 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 Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 40 | * 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 51 | ConsistentMapBuilder<K, V> withSerializer(Serializer serializer); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 52 | |
| 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 69 | ConsistentMapBuilder<K, V> withPartitionsDisabled(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 72 | * Disables map updates. |
| 73 | * <p> |
| 74 | * Attempt to update the built map will throw {@code UnsupportedOperationException}. |
| 75 | * |
| 76 | * @return this ConsistentMapBuilder |
| 77 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 78 | ConsistentMapBuilder<K, V> withUpdatesDisabled(); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 81 | * 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 Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 93 | * 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 99 | ConsistentMap<K, V> build(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 100 | |
| 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 108 | AsyncConsistentMap<K, V> buildAsyncMap(); |
| 109 | } |