blob: 5c60b19df535a923d8c3250b99b91e78f27876b0 [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 */
29public 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 Kruglikov3e29f662016-07-13 10:18:10 -070046 * Returns the entry associated with the least key greater than or equal to
47 * the key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070048 *
49 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070050 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070051 */
52 CompletableFuture<Map.Entry<K, Versioned<V>>> ceilingEntry(K key);
53
54 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070055 * Returns the entry associated with the greatest key less than or equal
56 * to key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070057 *
58 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070059 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070060 */
61 CompletableFuture<Map.Entry<K, Versioned<V>>> floorEntry(K key);
62
63 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070064 * Returns the entry associated with the least key greater than key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070065 *
66 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070067 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070068 */
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 Kruglikov3e29f662016-07-13 10:18:10 -070075 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -070076 */
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 Kruglikov3e29f662016-07-13 10:18:10 -070082 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070083 */
84 CompletableFuture<Map.Entry<K, Versioned<V>>> firstEntry();
85
86 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070087 * Return the entry associated with the highest key in the map.
Aaron Kruglikov47047b22016-03-31 16:52:48 -070088 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070089 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070090 */
91 CompletableFuture<Map.Entry<K, Versioned<V>>> lastEntry();
92
93 /**
94 * Return and remove the entry associated with the lowest key.
95 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -070096 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -070097 */
98 CompletableFuture<Map.Entry<K, Versioned<V>>> pollFirstEntry();
99
100 /**
101 * Return and remove the entry associated with the highest key.
102 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700103 * @return the entry or null if none exist
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700104 */
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 Kruglikov3e29f662016-07-13 10:18:10 -0700111 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700112 */
113 CompletableFuture<K> lowerKey(K key);
114
115 /**
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700116 * Return the highest key less than or equal to key.
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700117 *
118 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700119 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700120 */
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 Kruglikov3e29f662016-07-13 10:18:10 -0700127 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700128 */
129 CompletableFuture<K> ceilingKey(K key);
130
131 /**
132 * Return the lowest key greater than key.
133 *
134 * @param key the key
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700135 * @return the entry or null if no suitable key exists
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700136 */
137 CompletableFuture<K> higherKey(K key);
138
139 /**
140 * Returns a navigable set of the keys in this map.
141 *
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700142 * @return a navigable key set (this may be empty)
Aaron Kruglikov47047b22016-03-31 16:52:48 -0700143 */
144 CompletableFuture<NavigableSet<K>> navigableKeySet();
145
Aaron Kruglikov3e29f662016-07-13 10:18:10 -0700146 /**
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 Kruglikov47047b22016-03-31 16:52:48 -0700164 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}