Madan Jampani | 619453b | 2015-07-22 23:47:09 -0700 | [diff] [blame] | 1 | /* |
| 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 Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 16 | package org.onosproject.store.service; |
| 17 | |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 18 | import org.onosproject.core.ApplicationId; |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 19 | |
| 20 | /** |
Madan Jampani | dfde6ba | 2016-01-13 21:36:09 -0800 | [diff] [blame] | 21 | * Builder for {@link ConsistentMap} instances. |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 22 | * |
| 23 | * @param <K> type for map key |
| 24 | * @param <V> type for map value |
| 25 | */ |
| 26 | public interface ConsistentMapBuilder<K, V> { |
| 27 | |
| 28 | /** |
| 29 | * Sets the name of the map. |
| 30 | * <p> |
Madan Jampani | dfde6ba | 2016-01-13 21:36:09 -0800 | [diff] [blame] | 31 | * 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 Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 33 | * </p> |
| 34 | * <p> |
Madan Jampani | dfde6ba | 2016-01-13 21:36:09 -0800 | [diff] [blame] | 35 | * <b>Note:</b> This is a mandatory parameter. |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 36 | * </p> |
| 37 | * |
Madan Jampani | dfde6ba | 2016-01-13 21:36:09 -0800 | [diff] [blame] | 38 | * @param name name of the map |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 39 | * @return this ConsistentMapBuilder |
| 40 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 41 | ConsistentMapBuilder<K, V> withName(String name); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 42 | |
| 43 | /** |
Madan Jampani | dfde6ba | 2016-01-13 21:36:09 -0800 | [diff] [blame] | 44 | * Sets the identifier of the application that owns this map instance. |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 45 | * <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 Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 56 | * 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 67 | ConsistentMapBuilder<K, V> withSerializer(Serializer serializer); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 68 | |
| 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 85 | ConsistentMapBuilder<K, V> withPartitionsDisabled(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 86 | |
| 87 | /** |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 88 | * Disables map updates. |
| 89 | * <p> |
| 90 | * Attempt to update the built map will throw {@code UnsupportedOperationException}. |
| 91 | * |
| 92 | * @return this ConsistentMapBuilder |
| 93 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 94 | ConsistentMapBuilder<K, V> withUpdatesDisabled(); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 95 | |
| 96 | /** |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 97 | * 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 Castro | 41b1f3a | 2015-07-31 13:51:32 -0700 | [diff] [blame] | 109 | * 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 Jampani | 3d6a2f6 | 2015-08-12 07:19:07 -0700 | [diff] [blame] | 117 | * 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 Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 128 | * 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 134 | ConsistentMap<K, V> build(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 135 | |
| 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 143 | AsyncConsistentMap<K, V> buildAsyncMap(); |
| 144 | } |