Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 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 | */ |
| 16 | |
| 17 | package org.onosproject.store.service; |
| 18 | |
| 19 | import org.onosproject.store.primitives.DefaultConsistentTreeMap; |
| 20 | |
| 21 | import java.util.Map; |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 22 | import java.util.NavigableMap; |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 23 | import java.util.NavigableSet; |
| 24 | import java.util.concurrent.CompletableFuture; |
| 25 | |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 26 | import static org.onosproject.store.service.DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS; |
| 27 | |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 28 | /** |
| 29 | * API for a distributed tree map implementation. |
| 30 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 31 | public interface AsyncConsistentTreeMap<V> |
| 32 | extends AsyncConsistentMap<String, V> { |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 33 | |
| 34 | /** |
| 35 | * Return the lowest key in the map. |
| 36 | * |
| 37 | * @return the key or null if none exist |
| 38 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 39 | CompletableFuture<String> firstKey(); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * Return the highest key in the map. |
| 43 | * |
| 44 | * @return the key or null if none exist |
| 45 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 46 | CompletableFuture<String> lastKey(); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 47 | |
| 48 | /** |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 49 | * Returns the entry associated with the least key greater than or equal to |
| 50 | * the key. |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 51 | * |
| 52 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 53 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 54 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 55 | CompletableFuture<Map.Entry<String, Versioned<V>>> ceilingEntry( |
| 56 | String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 57 | |
| 58 | /** |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 59 | * Returns the entry associated with the greatest key less than or equal |
| 60 | * to key. |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 61 | * |
| 62 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 63 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 64 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 65 | CompletableFuture<Map.Entry<String, Versioned<V>>> floorEntry(String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 66 | |
| 67 | /** |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 68 | * Returns the entry associated with the least key greater than key. |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 69 | * |
| 70 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 71 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 72 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 73 | CompletableFuture<Map.Entry<String, Versioned<V>>> higherEntry(String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Returns the entry associated with the largest key less than key. |
| 77 | * |
| 78 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 79 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 80 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 81 | CompletableFuture<Map.Entry<String, Versioned<V>>> lowerEntry(String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 82 | |
| 83 | /** |
| 84 | * Return the entry associated with the lowest key in the map. |
| 85 | * |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 86 | * @return the entry or null if none exist |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 87 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 88 | CompletableFuture<Map.Entry<String, Versioned<V>>> firstEntry(); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 89 | |
| 90 | /** |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 91 | * Return the entry associated with the highest key in the map. |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 92 | * |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 93 | * @return the entry or null if none exist |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 94 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 95 | CompletableFuture<Map.Entry<String, Versioned<V>>> lastEntry(); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 96 | |
| 97 | /** |
| 98 | * Return and remove the entry associated with the lowest key. |
| 99 | * |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 100 | * @return the entry or null if none exist |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 101 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 102 | CompletableFuture<Map.Entry<String, Versioned<V>>> pollFirstEntry(); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 103 | |
| 104 | /** |
| 105 | * Return and remove the entry associated with the highest key. |
| 106 | * |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 107 | * @return the entry or null if none exist |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 108 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 109 | CompletableFuture<Map.Entry<String, Versioned<V>>> pollLastEntry(); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 110 | |
| 111 | /** |
| 112 | * Return the entry associated with the greatest key less than key. |
| 113 | * |
| 114 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 115 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 116 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 117 | CompletableFuture<String> lowerKey(String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 118 | |
| 119 | /** |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 120 | * Return the highest key less than or equal to key. |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 121 | * |
| 122 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 123 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 124 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 125 | CompletableFuture<String> floorKey(String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 126 | |
| 127 | /** |
| 128 | * Return the lowest key greater than or equal to key. |
| 129 | * |
| 130 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 131 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 132 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 133 | CompletableFuture<String> ceilingKey(String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 134 | |
| 135 | /** |
| 136 | * Return the lowest key greater than key. |
| 137 | * |
| 138 | * @param key the key |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 139 | * @return the entry or null if no suitable key exists |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 140 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 141 | CompletableFuture<String> higherKey(String key); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 142 | |
| 143 | /** |
| 144 | * Returns a navigable set of the keys in this map. |
| 145 | * |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 146 | * @return a navigable key set (this may be empty) |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 147 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 148 | CompletableFuture<NavigableSet<String>> navigableKeySet(); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 149 | |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 150 | /** |
| 151 | * Returns a navigable map containing the entries from the original map |
| 152 | * which are larger than (or if specified equal to) {@code lowerKey} AND |
| 153 | * less than (or if specified equal to) {@code upperKey}. |
| 154 | * |
| 155 | * @param upperKey the upper bound for the keys in this map |
| 156 | * @param lowerKey the lower bound for the keys in this map |
| 157 | * @param inclusiveUpper whether keys equal to the upperKey should be |
| 158 | * included |
| 159 | * @param inclusiveLower whether keys equal to the lowerKey should be |
| 160 | * included |
| 161 | * @return a navigable map containing entries in the specified range (this |
| 162 | * may be empty) |
| 163 | */ |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 164 | CompletableFuture<NavigableMap<String, V>> subMap(String upperKey, |
| 165 | String lowerKey, |
| 166 | boolean inclusiveUpper, |
| 167 | boolean inclusiveLower); |
Aaron Kruglikov | 3e29f66 | 2016-07-13 10:18:10 -0700 | [diff] [blame] | 168 | |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 169 | default ConsistentTreeMap<V> asTreeMap() { |
| 170 | return asTreeMap(DEFAULT_OPERTATION_TIMEOUT_MILLIS); |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 171 | } |
| 172 | |
Aaron Kruglikov | 6a16435 | 2016-07-25 11:46:17 -0700 | [diff] [blame] | 173 | default ConsistentTreeMap<V> asTreeMap(long timeoutMillis) { |
Aaron Kruglikov | 47047b2 | 2016-03-31 16:52:48 -0700 | [diff] [blame] | 174 | return new DefaultConsistentTreeMap<>(this, timeoutMillis); |
| 175 | } |
| 176 | |
| 177 | |
| 178 | } |