blob: 68cfe9e4ec9350f46e2d7e2d29433af14ad6fbe5 [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
19import java.util.Collection;
Madan Jampani94c23532015-02-05 17:40:01 -080020import java.util.Map;
21import java.util.Set;
22import java.util.concurrent.CompletableFuture;
23
Madan Jampani63c659f2015-06-11 00:52:58 -070024import org.onosproject.cluster.NodeId;
Madan Jampanibff6d8f2015-03-31 16:53:47 -070025import org.onosproject.store.service.Transaction;
Madan Jampani393e0f02015-02-12 07:35:39 +053026import org.onosproject.store.service.Versioned;
27
Madan Jampani94c23532015-02-05 17:40:01 -080028/**
29 * Database proxy.
30 */
31public interface DatabaseProxy<K, V> {
32
Madan Jampania89f8f92015-04-01 14:39:54 -070033 /**
Madan Jampani7804c992015-07-20 13:20:19 -070034 * Returns a set of all map names.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070035 *
Madan Jampania89f8f92015-04-01 14:39:54 -070036 * @return A completable future to be completed with the result once complete.
37 */
Madan Jampani7804c992015-07-20 13:20:19 -070038 CompletableFuture<Set<String>> maps();
Madan Jampania89f8f92015-04-01 14:39:54 -070039
Madan Jampanib5d72d52015-04-03 16:53:50 -070040 /**
41 * Returns a mapping from counter name to next value.
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070042 *
Madan Jampanib5d72d52015-04-03 16:53:50 -070043 * @return A completable future to be completed with the result once complete.
44 */
45 CompletableFuture<Map<String, Long>> counters();
46
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -070047 /**
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -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
66 * @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
75 * @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
84 * @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 *
Madan Jampani7804c992015-07-20 13:20:19 -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
97 * @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
Madan Jampani7804c992015-07-20 13:20:19 -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
Madan Jampani04aeb452015-05-02 16:12:24 -0700138 * @param delta value to add
139 * @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
Madan Jampani04aeb452015-05-02 16:12:24 -0700147 * @param delta value to add
148 * @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
152 /**
153 * Returns the current value of the specified atomic counter.
154 *
155 * @param counterName counter name
156 * @return current value
157 */
158 CompletableFuture<Long> counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700159
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700160 /**
Madan Jampani63c659f2015-06-11 00:52:58 -0700161 * Returns the size of queue.
162 * @param queueName queue name
163 * @return queue size
164 */
165 CompletableFuture<Long> queueSize(String queueName);
166
167 /**
168 * Inserts an entry into the queue.
169 * @param queueName queue name
170 * @param entry queue entry
171 * @return set of nodes to notify about the queue update
172 */
173 CompletableFuture<Set<NodeId>> queuePush(String queueName, byte[] entry);
174
175 /**
176 * Removes an entry from the queue if the queue is non-empty.
177 * @param queueName queue name
178 * @param nodeId If the queue is empty the identifier of node to notify when an entry becomes available
179 * @return entry. Can be null if queue is empty
180 */
181 CompletableFuture<byte[]> queuePop(String queueName, NodeId nodeId);
182
183 /**
184 * Returns but does not remove an entry from the queue.
185 * @param queueName queue name
186 * @return entry. Can be null if queue is empty
187 */
188 CompletableFuture<byte[]> queuePeek(String queueName);
189
190 /**
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700191 * Prepare and commit the specified transaction.
192 *
193 * @param transaction transaction to commit (after preparation)
194 * @return A completable future to be completed with the result once complete
195 */
196 CompletableFuture<Boolean> prepareAndCommit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700197
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700198 /**
199 * Prepare the specified transaction for commit. A successful prepare implies
200 * all the affected resources are locked thus ensuring no concurrent updates can interfere.
201 *
202 * @param transaction transaction to prepare (for commit)
203 * @return A completable future to be completed with the result once complete. The future is completed
204 * with true if the transaction is successfully prepared i.e. all pre-conditions are met and
205 * applicable resources locked.
206 */
207 CompletableFuture<Boolean> prepare(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700208
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700209 /**
210 * Commit the specified transaction. A successful commit implies
211 * all the updates are applied, are now durable and are now visible externally.
212 *
213 * @param transaction transaction to commit
214 * @return A completable future to be completed with the result once complete
215 */
216 CompletableFuture<Boolean> commit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700217
Sho SHIMIZUd91c4b02015-04-27 20:07:23 -0700218 /**
219 * Rollback the specified transaction. A successful rollback implies
220 * all previously acquired locks for the affected resources are released.
221 *
222 * @param transaction transaction to rollback
223 * @return A completable future to be completed with the result once complete
224 */
225 CompletableFuture<Boolean> rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800226}