aboutsummaryrefslogtreecommitdiffstats
path: root/framework/src/onos/core/store/dist/src/main/java/org/onosproject/store/consistent/impl/DatabaseProxy.java
blob: 95f9e39a9a5c9cacdff80ddfbce47cd92b442cc4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
/*
 * Copyright 2015 Open Networking Laboratory
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.onosproject.store.consistent.impl;

import java.util.Collection;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.CompletableFuture;

import org.onosproject.store.service.Transaction;
import org.onosproject.store.service.Versioned;

/**
 * Database proxy.
 */
public interface DatabaseProxy<K, V> {

    /**
     * Returns a set of all map names.
     *
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Set<String>> maps();

    /**
     * Returns a mapping from counter name to next value.
     *
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Map<String, Long>> counters();

    /**
     * Returns the number of entries in map.
     * @param mapName map name
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Integer> mapSize(String mapName);

    /**
     * Checks whether the map is empty.
     *
     * @param mapName map name
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Boolean> mapIsEmpty(String mapName);

    /**
     * Checks whether the map contains a key.
     *
     * @param mapName map name
     * @param key key to check.
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Boolean> mapContainsKey(String mapName, K key);

    /**
     * Checks whether the map contains a value.
     *
     * @param mapName map name
     * @param value The value to check.
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Boolean> mapContainsValue(String mapName, V value);

    /**
     * Gets a value from the map.
     *
     * @param mapName map name
     * @param key The key to get.
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Versioned<V>> mapGet(String mapName, K key);

    /**
     * Updates the map.
     *
     * @param mapName map name
     * @param key           The key to set
     * @param valueMatch    match for checking existing value
     * @param versionMatch  match for checking existing version
     * @param value         new value
     * @return A completable future to be completed with the result once complete
     */
    CompletableFuture<Result<UpdateResult<K, V>>> mapUpdate(
            String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);

    /**
     * Clears the map.
     *
     * @param mapName map name
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Result<Void>> mapClear(String mapName);

    /**
     * Gets a set of keys in the map.
     *
     * @param mapName map name
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Set<K>> mapKeySet(String mapName);

    /**
     * Gets a collection of values in the map.
     *
     * @param mapName map name
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Collection<Versioned<V>>> mapValues(String mapName);

    /**
     * Gets a set of entries in the map.
     *
     * @param mapName map name
     * @return A completable future to be completed with the result once complete.
     */
    CompletableFuture<Set<Map.Entry<K, Versioned<V>>>> mapEntrySet(String mapName);

     /**
     * Atomically add the given value to current value of the specified counter.
     *
     * @param counterName counter name
     * @param delta value to add
     * @return updated value
     */
    CompletableFuture<Long> counterAddAndGet(String counterName, long delta);

    /**
     * Atomically add the given value to current value of the specified counter.
     *
     * @param counterName counter name
     * @param delta value to add
     * @return previous value
     */
    CompletableFuture<Long> counterGetAndAdd(String counterName, long delta);

    /**
     * Returns the current value of the specified atomic counter.
     *
     * @param counterName counter name
     * @return current value
     */
    CompletableFuture<Long> counterGet(String counterName);

    /**
     * Returns the size of queue.
     * @param queueName queue name
     * @return queue size
     */
    CompletableFuture<Long> queueSize(String queueName);

    /**
     * Inserts an entry into the queue.
     * @param queueName queue name
     * @param entry queue entry
     * @return void future
     */
    CompletableFuture<Void> queuePush(String queueName, byte[] entry);

    /**
     * Removes an entry from the queue if the queue is non-empty.
     * @param queueName queue name
     * @return entry future. Can be completed with null if queue is empty
     */
    CompletableFuture<byte[]> queuePop(String queueName);

    /**
     * Returns but does not remove an entry from the queue.
     * @param queueName queue name
     * @return entry. Can be null if queue is empty
     */
    CompletableFuture<byte[]> queuePeek(String queueName);

    /**
     * Prepare and commit the specified transaction.
     *
     * @param transaction transaction to commit (after preparation)
     * @return A completable future to be completed with the result once complete
     */
    CompletableFuture<CommitResponse> prepareAndCommit(Transaction transaction);

    /**
     * Prepare the specified transaction for commit. A successful prepare implies
     * all the affected resources are locked thus ensuring no concurrent updates can interfere.
     *
     * @param transaction transaction to prepare (for commit)
     * @return A completable future to be completed with the result once complete. The future is completed
     * with true if the transaction is successfully prepared i.e. all pre-conditions are met and
     * applicable resources locked.
     */
    CompletableFuture<Boolean> prepare(Transaction transaction);

    /**
     * Commit the specified transaction. A successful commit implies
     * all the updates are applied, are now durable and are now visible externally.
     *
     * @param transaction transaction to commit
     * @return A completable future to be completed with the result once complete
     */
    CompletableFuture<CommitResponse> commit(Transaction transaction);

    /**
     * Rollback the specified transaction. A successful rollback implies
     * all previously acquired locks for the affected resources are released.
     *
     * @param transaction transaction to rollback
     * @return A completable future to be completed with the result once complete
     */
    CompletableFuture<Boolean> rollback(Transaction transaction);
}