Madan Jampani | 2546111 | 2015-02-17 14:17:29 -0800 | [diff] [blame] | 1 | /* |
| 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 Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 17 | package org.onosproject.store.consistent.impl; |
| 18 | |
| 19 | import java.util.Collection; |
| 20 | import java.util.List; |
| 21 | import java.util.Map; |
| 22 | import java.util.Set; |
| 23 | import java.util.concurrent.CompletableFuture; |
| 24 | |
Madan Jampani | 393e0f0 | 2015-02-12 07:35:39 +0530 | [diff] [blame] | 25 | import org.onosproject.store.service.UpdateOperation; |
| 26 | import org.onosproject.store.service.Versioned; |
| 27 | |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 28 | /** |
| 29 | * Database proxy. |
| 30 | */ |
| 31 | public interface DatabaseProxy<K, V> { |
| 32 | |
| 33 | /** |
| 34 | * Gets the table size. |
| 35 | * |
| 36 | * @param tableName table name |
| 37 | * @return A completable future to be completed with the result once complete. |
| 38 | */ |
| 39 | CompletableFuture<Integer> size(String tableName); |
| 40 | |
| 41 | /** |
| 42 | * Checks whether the table is empty. |
| 43 | * |
| 44 | * @param tableName table name |
| 45 | * @return A completable future to be completed with the result once complete. |
| 46 | */ |
| 47 | CompletableFuture<Boolean> isEmpty(String tableName); |
| 48 | |
| 49 | /** |
| 50 | * Checks whether the table contains a key. |
| 51 | * |
| 52 | * @param tableName table name |
| 53 | * @param key The key to check. |
| 54 | * @return A completable future to be completed with the result once complete. |
| 55 | */ |
| 56 | CompletableFuture<Boolean> containsKey(String tableName, K key); |
| 57 | |
| 58 | /** |
| 59 | * Checks whether the table contains a value. |
| 60 | * |
| 61 | * @param tableName table name |
| 62 | * @param value The value to check. |
| 63 | * @return A completable future to be completed with the result once complete. |
| 64 | */ |
| 65 | CompletableFuture<Boolean> containsValue(String tableName, V value); |
| 66 | |
| 67 | /** |
| 68 | * Gets a value from the table. |
| 69 | * |
| 70 | * @param tableName table name |
| 71 | * @param key The key to get. |
| 72 | * @return A completable future to be completed with the result once complete. |
| 73 | */ |
| 74 | CompletableFuture<Versioned<V>> get(String tableName, K key); |
| 75 | |
| 76 | /** |
| 77 | * Puts a value in the table. |
| 78 | * |
| 79 | * @param tableName table name |
| 80 | * @param key The key to set. |
| 81 | * @param value The value to set. |
| 82 | * @return A completable future to be completed with the result once complete. |
| 83 | */ |
| 84 | CompletableFuture<Versioned<V>> put(String tableName, K key, V value); |
| 85 | |
| 86 | /** |
| 87 | * Removes a value from the table. |
| 88 | * |
| 89 | * @param tableName table name |
| 90 | * @param key The key to remove. |
| 91 | * @return A completable future to be completed with the result once complete. |
| 92 | */ |
| 93 | CompletableFuture<Versioned<V>> remove(String tableName, K key); |
| 94 | |
| 95 | /** |
| 96 | * Clears the table. |
| 97 | * |
| 98 | * @param tableName table name |
| 99 | * @return A completable future to be completed with the result once complete. |
| 100 | */ |
| 101 | CompletableFuture<Void> clear(String tableName); |
| 102 | |
| 103 | /** |
| 104 | * Gets a set of keys in the table. |
| 105 | * |
| 106 | * @param tableName table name |
| 107 | * @return A completable future to be completed with the result once complete. |
| 108 | */ |
| 109 | CompletableFuture<Set<K>> keySet(String tableName); |
| 110 | |
| 111 | /** |
| 112 | * Gets a collection of values in the table. |
| 113 | * |
| 114 | * @param tableName table name |
| 115 | * @return A completable future to be completed with the result once complete. |
| 116 | */ |
| 117 | CompletableFuture<Collection<Versioned<V>>> values(String tableName); |
| 118 | |
| 119 | /** |
| 120 | * Gets a set of entries in the table. |
| 121 | * |
| 122 | * @param tableName table name |
| 123 | * @return A completable future to be completed with the result once complete. |
| 124 | */ |
| 125 | CompletableFuture<Set<Map.Entry<K, Versioned<V>>>> entrySet(String tableName); |
| 126 | |
| 127 | /** |
| 128 | * Puts a value in the table if the given key does not exist. |
| 129 | * |
| 130 | * @param tableName table name |
| 131 | * @param key The key to set. |
| 132 | * @param value The value to set if the given key does not exist. |
| 133 | * @return A completable future to be completed with the result once complete. |
| 134 | */ |
| 135 | CompletableFuture<Versioned<V>> putIfAbsent(String tableName, K key, V value); |
| 136 | |
| 137 | /** |
| 138 | * Removes a key and if the existing value for that key matches the specified value. |
| 139 | * |
| 140 | * @param tableName table name |
| 141 | * @param key The key to remove. |
| 142 | * @param value The value to remove. |
| 143 | * @return A completable future to be completed with the result once complete. |
| 144 | */ |
| 145 | CompletableFuture<Boolean> remove(String tableName, K key, V value); |
| 146 | |
| 147 | /** |
| 148 | * Removes a key and if the existing version for that key matches the specified version. |
| 149 | * |
| 150 | * @param tableName table name |
| 151 | * @param key The key to remove. |
| 152 | * @param version The expected version. |
| 153 | * @return A completable future to be completed with the result once complete. |
| 154 | */ |
| 155 | CompletableFuture<Boolean> remove(String tableName, K key, long version); |
| 156 | |
| 157 | /** |
| 158 | * Replaces the entry for the specified key only if currently mapped to the specified value. |
| 159 | * |
| 160 | * @param tableName table name |
| 161 | * @param key The key to replace. |
| 162 | * @param oldValue The value to replace. |
| 163 | * @param newValue The value with which to replace the given key and value. |
| 164 | * @return A completable future to be completed with the result once complete. |
| 165 | */ |
| 166 | CompletableFuture<Boolean> replace(String tableName, K key, V oldValue, V newValue); |
| 167 | |
| 168 | /** |
| 169 | * Replaces the entry for the specified key only if currently mapped to the specified version. |
| 170 | * |
| 171 | * @param tableName table name |
| 172 | * @param key The key to update |
| 173 | * @param oldVersion existing version in the map for this replace to succeed. |
| 174 | * @param newValue The value with which to replace the given key and version. |
| 175 | * @return A completable future to be completed with the result once complete. |
| 176 | */ |
| 177 | CompletableFuture<Boolean> replace(String tableName, K key, long oldVersion, V newValue); |
| 178 | |
| 179 | /** |
| 180 | * Perform a atomic batch update operation i.e. either all operations in batch succeed or |
| 181 | * none do and no state changes are made. |
| 182 | * |
| 183 | * @param updates list of updates to apply atomically. |
| 184 | * @return A completable future to be completed with the result once complete. |
| 185 | */ |
| 186 | CompletableFuture<Boolean> atomicBatchUpdate(List<UpdateOperation<K, V>> updates); |
| 187 | } |