2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.store.consistent.impl;
19 import java.util.Collection;
22 import java.util.concurrent.CompletableFuture;
24 import org.onosproject.store.service.Transaction;
25 import org.onosproject.store.service.Versioned;
30 public interface DatabaseProxy<K, V> {
33 * Returns a set of all map names.
35 * @return A completable future to be completed with the result once complete.
37 CompletableFuture<Set<String>> maps();
40 * Returns a mapping from counter name to next value.
42 * @return A completable future to be completed with the result once complete.
44 CompletableFuture<Map<String, Long>> counters();
47 * Returns the number of entries in map.
48 * @param mapName map name
49 * @return A completable future to be completed with the result once complete.
51 CompletableFuture<Integer> mapSize(String mapName);
54 * Checks whether the map is empty.
56 * @param mapName map name
57 * @return A completable future to be completed with the result once complete.
59 CompletableFuture<Boolean> mapIsEmpty(String mapName);
62 * Checks whether the map contains a key.
64 * @param mapName map name
65 * @param key key to check.
66 * @return A completable future to be completed with the result once complete.
68 CompletableFuture<Boolean> mapContainsKey(String mapName, K key);
71 * Checks whether the map contains a value.
73 * @param mapName map name
74 * @param value The value to check.
75 * @return A completable future to be completed with the result once complete.
77 CompletableFuture<Boolean> mapContainsValue(String mapName, V value);
80 * Gets a value from the map.
82 * @param mapName map name
83 * @param key The key to get.
84 * @return A completable future to be completed with the result once complete.
86 CompletableFuture<Versioned<V>> mapGet(String mapName, K key);
91 * @param mapName map name
92 * @param key The key to set
93 * @param valueMatch match for checking existing value
94 * @param versionMatch match for checking existing version
95 * @param value new value
96 * @return A completable future to be completed with the result once complete
98 CompletableFuture<Result<UpdateResult<K, V>>> mapUpdate(
99 String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);
104 * @param mapName map name
105 * @return A completable future to be completed with the result once complete.
107 CompletableFuture<Result<Void>> mapClear(String mapName);
110 * Gets a set of keys in the map.
112 * @param mapName map name
113 * @return A completable future to be completed with the result once complete.
115 CompletableFuture<Set<K>> mapKeySet(String mapName);
118 * Gets a collection of values in the map.
120 * @param mapName map name
121 * @return A completable future to be completed with the result once complete.
123 CompletableFuture<Collection<Versioned<V>>> mapValues(String mapName);
126 * Gets a set of entries in the map.
128 * @param mapName map name
129 * @return A completable future to be completed with the result once complete.
131 CompletableFuture<Set<Map.Entry<K, Versioned<V>>>> mapEntrySet(String mapName);
134 * Atomically add the given value to current value of the specified counter.
136 * @param counterName counter name
137 * @param delta value to add
138 * @return updated value
140 CompletableFuture<Long> counterAddAndGet(String counterName, long delta);
143 * Atomically add the given value to current value of the specified counter.
145 * @param counterName counter name
146 * @param delta value to add
147 * @return previous value
149 CompletableFuture<Long> counterGetAndAdd(String counterName, long delta);
152 * Returns the current value of the specified atomic counter.
154 * @param counterName counter name
155 * @return current value
157 CompletableFuture<Long> counterGet(String counterName);
160 * Returns the size of queue.
161 * @param queueName queue name
164 CompletableFuture<Long> queueSize(String queueName);
167 * Inserts an entry into the queue.
168 * @param queueName queue name
169 * @param entry queue entry
170 * @return void future
172 CompletableFuture<Void> queuePush(String queueName, byte[] entry);
175 * Removes an entry from the queue if the queue is non-empty.
176 * @param queueName queue name
177 * @return entry future. Can be completed with null if queue is empty
179 CompletableFuture<byte[]> queuePop(String queueName);
182 * Returns but does not remove an entry from the queue.
183 * @param queueName queue name
184 * @return entry. Can be null if queue is empty
186 CompletableFuture<byte[]> queuePeek(String queueName);
189 * Prepare and commit the specified transaction.
191 * @param transaction transaction to commit (after preparation)
192 * @return A completable future to be completed with the result once complete
194 CompletableFuture<CommitResponse> prepareAndCommit(Transaction transaction);
197 * Prepare the specified transaction for commit. A successful prepare implies
198 * all the affected resources are locked thus ensuring no concurrent updates can interfere.
200 * @param transaction transaction to prepare (for commit)
201 * @return A completable future to be completed with the result once complete. The future is completed
202 * with true if the transaction is successfully prepared i.e. all pre-conditions are met and
203 * applicable resources locked.
205 CompletableFuture<Boolean> prepare(Transaction transaction);
208 * Commit the specified transaction. A successful commit implies
209 * all the updates are applied, are now durable and are now visible externally.
211 * @param transaction transaction to commit
212 * @return A completable future to be completed with the result once complete
214 CompletableFuture<CommitResponse> commit(Transaction transaction);
217 * Rollback the specified transaction. A successful rollback implies
218 * all previously acquired locks for the affected resources are released.
220 * @param transaction transaction to rollback
221 * @return A completable future to be completed with the result once complete
223 CompletableFuture<Boolean> rollback(Transaction transaction);