blob: 1d81f998693fe09a16c1487890fa3335a37ec577 [file] [log] [blame]
Madan Jampani25461112015-02-17 14:17:29 -08001/*
2 * Copyright 2015 Open Networking Laboratory
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
Madan Jampani94c23532015-02-05 17:40:01 -080017package org.onosproject.store.consistent.impl;
18
Aaron Kruglikov82fd6322015-10-06 12:02:46 -070019import org.onosproject.store.service.Transaction;
20import org.onosproject.store.service.Versioned;
21
Madan Jampani94c23532015-02-05 17:40:01 -080022import java.util.Collection;
Madan Jampani94c23532015-02-05 17:40:01 -080023import java.util.Map;
24import java.util.Set;
25import java.util.concurrent.CompletableFuture;
26
Madan Jampani94c23532015-02-05 17:40:01 -080027/**
28 * Database proxy.
29 */
30public interface DatabaseProxy<K, V> {
31
Madan Jampania89f8f92015-04-01 14:39:54 -070032 /**
Madan Jampani7804c992015-07-20 13:20:19 -070033 * Returns a set of all map names.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070034 *
Madan Jampania89f8f92015-04-01 14:39:54 -070035 * @return A completable future to be completed with the result once complete.
36 */
Madan Jampani7804c992015-07-20 13:20:19 -070037 CompletableFuture<Set<String>> maps();
Madan Jampania89f8f92015-04-01 14:39:54 -070038
Madan Jampanib5d72d52015-04-03 16:53:50 -070039 /**
40 * Returns a mapping from counter name to next value.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070041 *
Madan Jampanib5d72d52015-04-03 16:53:50 -070042 * @return A completable future to be completed with the result once complete.
43 */
44 CompletableFuture<Map<String, Long>> counters();
45
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070046 /**
Madan Jampani3ca9cb62015-07-21 11:35:44 -070047 * Returns the number of entries in map.
andreafd912ac2015-10-02 14:58:35 -070048 *
Madan Jampani7804c992015-07-20 13:20:19 -070049 * @param mapName map name
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070050 * @return A completable future to be completed with the result once complete.
51 */
Madan Jampani7804c992015-07-20 13:20:19 -070052 CompletableFuture<Integer> mapSize(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080053
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070054 /**
Madan Jampani7804c992015-07-20 13:20:19 -070055 * Checks whether the map is empty.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070056 *
Madan Jampani7804c992015-07-20 13:20:19 -070057 * @param mapName map name
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070058 * @return A completable future to be completed with the result once complete.
59 */
Madan Jampani7804c992015-07-20 13:20:19 -070060 CompletableFuture<Boolean> mapIsEmpty(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080061
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070062 /**
Madan Jampani7804c992015-07-20 13:20:19 -070063 * Checks whether the map contains a key.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070064 *
Madan Jampani7804c992015-07-20 13:20:19 -070065 * @param mapName map name
andreafd912ac2015-10-02 14:58:35 -070066 * @param key key to check.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070067 * @return A completable future to be completed with the result once complete.
68 */
Madan Jampani7804c992015-07-20 13:20:19 -070069 CompletableFuture<Boolean> mapContainsKey(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080070
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070071 /**
Madan Jampani7804c992015-07-20 13:20:19 -070072 * Checks whether the map contains a value.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070073 *
Madan Jampani7804c992015-07-20 13:20:19 -070074 * @param mapName map name
andreafd912ac2015-10-02 14:58:35 -070075 * @param value The value to check.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070076 * @return A completable future to be completed with the result once complete.
77 */
Madan Jampani7804c992015-07-20 13:20:19 -070078 CompletableFuture<Boolean> mapContainsValue(String mapName, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080079
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070080 /**
Madan Jampani7804c992015-07-20 13:20:19 -070081 * Gets a value from the map.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070082 *
Madan Jampani7804c992015-07-20 13:20:19 -070083 * @param mapName map name
andreafd912ac2015-10-02 14:58:35 -070084 * @param key The key to get.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070085 * @return A completable future to be completed with the result once complete.
86 */
Madan Jampani7804c992015-07-20 13:20:19 -070087 CompletableFuture<Versioned<V>> mapGet(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080088
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070089 /**
Madan Jampani7804c992015-07-20 13:20:19 -070090 * Updates the map.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070091 *
andreafd912ac2015-10-02 14:58:35 -070092 * @param mapName map name
93 * @param key The key to set
94 * @param valueMatch match for checking existing value
95 * @param versionMatch match for checking existing version
96 * @param value new value
Madan Jampani7804c992015-07-20 13:20:19 -070097 * @return A completable future to be completed with the result once complete
98 */
99 CompletableFuture<Result<UpdateResult<K, V>>> mapUpdate(
100 String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);
101
102 /**
103 * Clears the map.
104 *
105 * @param mapName map name
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700106 * @return A completable future to be completed with the result once complete.
107 */
Madan Jampani7804c992015-07-20 13:20:19 -0700108 CompletableFuture<Result<Void>> mapClear(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -0800109
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700110 /**
Madan Jampani7804c992015-07-20 13:20:19 -0700111 * Gets a set of keys in the map.
Madan Jampani346d4f52015-05-04 11:09:39 -0700112 *
Madan Jampani7804c992015-07-20 13:20:19 -0700113 * @param mapName map name
Madan Jampani346d4f52015-05-04 11:09:39 -0700114 * @return A completable future to be completed with the result once complete.
115 */
Madan Jampani7804c992015-07-20 13:20:19 -0700116 CompletableFuture<Set<K>> mapKeySet(String mapName);
Madan Jampani346d4f52015-05-04 11:09:39 -0700117
118 /**
Madan Jampani7804c992015-07-20 13:20:19 -0700119 * Gets a collection of values in the map.
Madan Jampani346d4f52015-05-04 11:09:39 -0700120 *
Madan Jampani7804c992015-07-20 13:20:19 -0700121 * @param mapName map name
Madan Jampani346d4f52015-05-04 11:09:39 -0700122 * @return A completable future to be completed with the result once complete.
123 */
Madan Jampani7804c992015-07-20 13:20:19 -0700124 CompletableFuture<Collection<Versioned<V>>> mapValues(String mapName);
Madan Jampani346d4f52015-05-04 11:09:39 -0700125
126 /**
Madan Jampani7804c992015-07-20 13:20:19 -0700127 * Gets a set of entries in the map.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700128 *
Madan Jampani7804c992015-07-20 13:20:19 -0700129 * @param mapName map name
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700130 * @return A completable future to be completed with the result once complete.
131 */
Madan Jampani7804c992015-07-20 13:20:19 -0700132 CompletableFuture<Set<Map.Entry<K, Versioned<V>>>> mapEntrySet(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -0800133
andreafd912ac2015-10-02 14:58:35 -0700134 /**
Madan Jampani04aeb452015-05-02 16:12:24 -0700135 * Atomically add the given value to current value of the specified counter.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700136 *
137 * @param counterName counter name
andreafd912ac2015-10-02 14:58:35 -0700138 * @param delta value to add
Madan Jampani04aeb452015-05-02 16:12:24 -0700139 * @return updated value
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700140 */
Madan Jampani04aeb452015-05-02 16:12:24 -0700141 CompletableFuture<Long> counterAddAndGet(String counterName, long delta);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700142
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700143 /**
Madan Jampani04aeb452015-05-02 16:12:24 -0700144 * Atomically add the given value to current value of the specified counter.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700145 *
146 * @param counterName counter name
andreafd912ac2015-10-02 14:58:35 -0700147 * @param delta value to add
Madan Jampani04aeb452015-05-02 16:12:24 -0700148 * @return previous value
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700149 */
Madan Jampani04aeb452015-05-02 16:12:24 -0700150 CompletableFuture<Long> counterGetAndAdd(String counterName, long delta);
151
andreafd912ac2015-10-02 14:58:35 -0700152
153 /**
154 * Atomically sets the given value to current value of the specified counter.
155 *
156 * @param counterName counter name
157 * @param value value to set
158 * @return void future
159 */
160 CompletableFuture<Void> counterSet(String counterName, long value);
161
Madan Jampani04aeb452015-05-02 16:12:24 -0700162 /**
Aaron Kruglikov82fd6322015-10-06 12:02:46 -0700163 * Atomically sets the given counter to the specified update value if and only if the current value is equal to the
164 * expected value.
165 * @param counterName counter name
166 * @param expectedValue value to use for equivalence check
167 * @param update value to set if expected value is current value
168 * @return true if an update occurred, false otherwise
169 */
170 CompletableFuture<Boolean> counterCompareAndSet(String counterName, long expectedValue, long update);
171
172 /**
Madan Jampani04aeb452015-05-02 16:12:24 -0700173 * Returns the current value of the specified atomic counter.
174 *
175 * @param counterName counter name
176 * @return current value
177 */
178 CompletableFuture<Long> counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700179
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700180 /**
Madan Jampani63c659f2015-06-11 00:52:58 -0700181 * Returns the size of queue.
andreafd912ac2015-10-02 14:58:35 -0700182 *
Madan Jampani63c659f2015-06-11 00:52:58 -0700183 * @param queueName queue name
184 * @return queue size
185 */
186 CompletableFuture<Long> queueSize(String queueName);
187
188 /**
189 * Inserts an entry into the queue.
andreafd912ac2015-10-02 14:58:35 -0700190 *
Madan Jampani63c659f2015-06-11 00:52:58 -0700191 * @param queueName queue name
andreafd912ac2015-10-02 14:58:35 -0700192 * @param entry queue entry
Madan Jampania6d787b2015-08-11 11:02:02 -0700193 * @return void future
Madan Jampani63c659f2015-06-11 00:52:58 -0700194 */
Madan Jampania6d787b2015-08-11 11:02:02 -0700195 CompletableFuture<Void> queuePush(String queueName, byte[] entry);
Madan Jampani63c659f2015-06-11 00:52:58 -0700196
197 /**
198 * Removes an entry from the queue if the queue is non-empty.
andreafd912ac2015-10-02 14:58:35 -0700199 *
Madan Jampani63c659f2015-06-11 00:52:58 -0700200 * @param queueName queue name
Madan Jampania6d787b2015-08-11 11:02:02 -0700201 * @return entry future. Can be completed with null if queue is empty
Madan Jampani63c659f2015-06-11 00:52:58 -0700202 */
Madan Jampania6d787b2015-08-11 11:02:02 -0700203 CompletableFuture<byte[]> queuePop(String queueName);
Madan Jampani63c659f2015-06-11 00:52:58 -0700204
205 /**
206 * Returns but does not remove an entry from the queue.
andreafd912ac2015-10-02 14:58:35 -0700207 *
Madan Jampani63c659f2015-06-11 00:52:58 -0700208 * @param queueName queue name
209 * @return entry. Can be null if queue is empty
210 */
211 CompletableFuture<byte[]> queuePeek(String queueName);
212
213 /**
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700214 * Prepare and commit the specified transaction.
215 *
216 * @param transaction transaction to commit (after preparation)
217 * @return A completable future to be completed with the result once complete
218 */
Madan Jampanibab51a42015-08-10 13:53:35 -0700219 CompletableFuture<CommitResponse> prepareAndCommit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700220
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700221 /**
222 * Prepare the specified transaction for commit. A successful prepare implies
223 * all the affected resources are locked thus ensuring no concurrent updates can interfere.
224 *
225 * @param transaction transaction to prepare (for commit)
226 * @return A completable future to be completed with the result once complete. The future is completed
227 * with true if the transaction is successfully prepared i.e. all pre-conditions are met and
228 * applicable resources locked.
229 */
230 CompletableFuture<Boolean> prepare(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700231
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700232 /**
233 * Commit the specified transaction. A successful commit implies
234 * all the updates are applied, are now durable and are now visible externally.
235 *
236 * @param transaction transaction to commit
237 * @return A completable future to be completed with the result once complete
238 */
Madan Jampanibab51a42015-08-10 13:53:35 -0700239 CompletableFuture<CommitResponse> commit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700240
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700241 /**
242 * Rollback the specified transaction. A successful rollback implies
243 * all previously acquired locks for the affected resources are released.
244 *
245 * @param transaction transaction to rollback
246 * @return A completable future to be completed with the result once complete
247 */
248 CompletableFuture<Boolean> rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800249}