blob: c1bb36da5faacf55939457f379d4cb8bbd64e5e0 [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
26/**
27 * API for a distributed tree map implementation.
28 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070029public interface AsyncConsistentTreeMap<V>
30 extends AsyncConsistentMap<String, V> {
Aaron Kruglikov47047b22016-03-31 16:52:48 -070031
32 /**
33 * Return the lowest key in the map.
34 *
35 * @return the key or null if none exist
36 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070037 CompletableFuture<String> firstKey();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070038
39 /**
40 * Return the highest key in the map.
41 *
42 * @return the key or null if none exist
43 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070044 CompletableFuture<String> lastKey();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070045
46 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070047 * Returns the entry associated with the least key greater than or equal to
48 * the key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070049 *
50 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070051 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070052 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070053 CompletableFuture<Map.Entry<String, Versioned<V>>> ceilingEntry(
54 String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070055
56 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070057 * Returns the entry associated with the greatest key less than or equal
58 * to key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070059 *
60 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070061 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070062 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070063 CompletableFuture<Map.Entry<String, Versioned<V>>> floorEntry(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070064
65 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070066 * Returns the entry associated with the least key greater than key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070067 *
68 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070069 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070070 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070071 CompletableFuture<Map.Entry<String, Versioned<V>>> higherEntry(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070072
73 /**
74 * Returns the entry associated with the largest key less than key.
75 *
76 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070077 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070078 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070079 CompletableFuture<Map.Entry<String, Versioned<V>>> lowerEntry(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -070080
81 /**
82 * Return the entry associated with the lowest key in the map.
83 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070084 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070085 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070086 CompletableFuture<Map.Entry<String, Versioned<V>>> firstEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070087
88 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070089 * Return the entry associated with the highest key in the map.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070090 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070091 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070092 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -070093 CompletableFuture<Map.Entry<String, Versioned<V>>> lastEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -070094
95 /**
96 * Return and remove the entry associated with the lowest key.
97 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070098 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070099 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700100 CompletableFuture<Map.Entry<String, Versioned<V>>> pollFirstEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700101
102 /**
103 * Return and remove the entry associated with the highest key.
104 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700105 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700106 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700107 CompletableFuture<Map.Entry<String, Versioned<V>>> pollLastEntry();
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700108
109 /**
110 * Return the entry associated with the greatest key less than key.
111 *
112 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700113 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700114 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700115 CompletableFuture<String> lowerKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700116
117 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700118 * Return the highest key less than or equal to key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700119 *
120 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700121 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700122 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700123 CompletableFuture<String> floorKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700124
125 /**
126 * Return the lowest key greater than or equal to key.
127 *
128 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700129 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700130 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700131 CompletableFuture<String> ceilingKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700132
133 /**
134 * Return the lowest key greater than key.
135 *
136 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700137 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700138 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700139 CompletableFuture<String> higherKey(String key);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700140
141 /**
142 * Returns a navigable set of the keys in this map.
143 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700144 * @return a navigable key set (this may be empty)
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700145 */
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700146 CompletableFuture<NavigableSet<String>> navigableKeySet();
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700147
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700148 /**
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 Kruglikov6a164352016-07-25 11:46:17 -0700162 CompletableFuture<NavigableMap<String, V>> subMap(String upperKey,
163 String lowerKey,
164 boolean inclusiveUpper,
165 boolean inclusiveLower);
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700166
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700167 default ConsistentTreeMap<V> asTreeMap() {
Jordan Halterman6440b092017-05-24 17:48:08 -0700168 return asTreeMap(DEFAULT_OPERATION_TIMEOUT_MILLIS);
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700169 }
170
Aaron Kruglikov6a164352016-07-25 11:46:17 -0700171 default ConsistentTreeMap<V> asTreeMap(long timeoutMillis) {
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700172 return new DefaultConsistentTreeMap<>(this, timeoutMillis);
173 }
174
175
176}