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