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 | /** |
| 21 | * Builder for consistent maps. |
| 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> |
| 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 40 | ConsistentMapBuilder<K, V> withName(String name); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 43 | * 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 Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 55 | * 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 66 | ConsistentMapBuilder<K, V> withSerializer(Serializer serializer); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 67 | |
| 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 SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 84 | ConsistentMapBuilder<K, V> withPartitionsDisabled(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 85 | |
| 86 | /** |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 87 | * Disables map updates. |
| 88 | * <p> |
| 89 | * Attempt to update the built map will throw {@code UnsupportedOperationException}. |
| 90 | * |
| 91 | * @return this ConsistentMapBuilder |
| 92 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 93 | ConsistentMapBuilder<K, V> withUpdatesDisabled(); |
Madan Jampani | 02b7fb8 | 2015-05-01 13:01:20 -0700 | [diff] [blame] | 94 | |
| 95 | /** |
Madan Jampani | e8af1cc | 2015-06-23 14:23:31 -0700 | [diff] [blame] | 96 | * 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 | /** |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 108 | * Builds an consistent map based on the configuration options |
| 109 | * supplied to this builder. |
| 110 | * |
| 111 | * @return new consistent map |
| 112 | * @throws java.lang.RuntimeException if a mandatory parameter is missing |
| 113 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 114 | ConsistentMap<K, V> build(); |
Madan Jampani | f1b8e17 | 2015-03-23 11:42:02 -0700 | [diff] [blame] | 115 | |
| 116 | /** |
| 117 | * Builds an async consistent map based on the configuration options |
| 118 | * supplied to this builder. |
| 119 | * |
| 120 | * @return new async consistent map |
| 121 | * @throws java.lang.RuntimeException if a mandatory parameter is missing |
| 122 | */ |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 123 | AsyncConsistentMap<K, V> buildAsyncMap(); |
| 124 | } |