blob: 87386ed8d4e0a0a8ae90bfd611666c331e7d959f [file] [log] [blame]
Aaron Kruglikov47047b22016-03-31 16:52:48 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Aaron Kruglikov47047b22016-03-31 16:52:48 -07003 *
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
17package org.onosproject.store.service;
18
19import org.onosproject.store.primitives.DefaultConsistentTreeMap;
20
21import java.util.Map;
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070022import java.util.NavigableMap;
Aaron Kruglikov47047b22016-03-31 16:52:48 -070023import java.util.NavigableSet;
24import java.util.concurrent.CompletableFuture;
25
Aaron Kruglikov6a164352016-07-25 11:46:17 -070026import static org.onosproject.store.service.DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS;
27
Aaron Kruglikov47047b22016-03-31 16:52:48 -070028/**
29 * API for a distributed tree map implementation.
30 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070031public interface AsyncConsistentTreeMap<V>
32 extends AsyncConsistentMap<String, V> {
Aaron Kruglikov47047b22016-03-31 16:52:48 -070033
34 /**
35 * Return the lowest key in the map.
36 *
37 * @return the key or null if none exist
38 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070039 CompletableFuture<String> firstKey();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070040
41 /**
42 * Return the highest key in the map.
43 *
44 * @return the key or null if none exist
45 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070046 CompletableFuture<String> lastKey();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070047
48 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070049 * Returns the entry associated with the least key greater than or equal to
50 * the key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070051 *
52 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070053 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070054 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070055 CompletableFuture<Map.Entry<String, Versioned<V>>> ceilingEntry(
56 String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070057
58 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070059 * Returns the entry associated with the greatest key less than or equal
60 * to key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070061 *
62 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070063 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070064 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070065 CompletableFuture<Map.Entry<String, Versioned<V>>> floorEntry(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070066
67 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070068 * Returns the entry associated with the least key greater than key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070069 *
70 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070071 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070072 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070073 CompletableFuture<Map.Entry<String, Versioned<V>>> higherEntry(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070074
75 /**
76 * Returns the entry associated with the largest key less than key.
77 *
78 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070079 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070080 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070081 CompletableFuture<Map.Entry<String, Versioned<V>>> lowerEntry(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070082
83 /**
84 * Return the entry associated with the lowest key in the map.
85 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070086 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070087 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070088 CompletableFuture<Map.Entry<String, Versioned<V>>> firstEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070089
90 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070091 * Return the entry associated with the highest key in the map.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070092 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070093 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070094 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070095 CompletableFuture<Map.Entry<String, Versioned<V>>> lastEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070096
97 /**
98 * Return and remove the entry associated with the lowest key.
99 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700100 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700101 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700102 CompletableFuture<Map.Entry<String, Versioned<V>>> pollFirstEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700103
104 /**
105 * Return and remove the entry associated with the highest key.
106 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700107 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700108 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700109 CompletableFuture<Map.Entry<String, Versioned<V>>> pollLastEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700110
111 /**
112 * Return the entry associated with the greatest key less than key.
113 *
114 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700115 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700116 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700117 CompletableFuture<String> lowerKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700118
119 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700120 * Return the highest key less than or equal to key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700121 *
122 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700123 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700124 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700125 CompletableFuture<String> floorKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700126
127 /**
128 * Return the lowest key greater than or equal to key.
129 *
130 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700131 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700132 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700133 CompletableFuture<String> ceilingKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700134
135 /**
136 * Return the lowest key greater than key.
137 *
138 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700139 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700140 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700141 CompletableFuture<String> higherKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700142
143 /**
144 * Returns a navigable set of the keys in this map.
145 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700146 * @return a navigable key set (this may be empty)
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700147 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700148 CompletableFuture<NavigableSet<String>> navigableKeySet();
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700149
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700150 /**
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 Kruglikov6a164352016-07-25 11:46:17 -0700164 CompletableFuture<NavigableMap<String, V>> subMap(String upperKey,
165 String lowerKey,
166 boolean inclusiveUpper,
167 boolean inclusiveLower);
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700168
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700169 default ConsistentTreeMap<V> asTreeMap() {
170 return asTreeMap(DEFAULT_OPERTATION_TIMEOUT_MILLIS);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700171 }
172
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700173 default ConsistentTreeMap<V> asTreeMap(long timeoutMillis) {
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700174 return new DefaultConsistentTreeMap<>(this, timeoutMillis);
175 }
176
177
178}