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