/* * 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 org.onosproject.store.service.Transaction; import org.onosproject.store.service.Versioned; import java.util.Collection; import java.util.Map; import java.util.Set; import java.util.concurrent.CompletableFuture; /** * Database proxy. */ public interface DatabaseProxy { /** * Returns a set of all map names. * * @return A completable future to be completed with the result once complete. */ CompletableFuture> maps(); /** * Returns a mapping from counter name to next value. * * @return A completable future to be completed with the result once complete. */ CompletableFuture> 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 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 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 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 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> 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>> mapUpdate( String mapName, K key, Match valueMatch, Match versionMatch, V value); /** * Clears the map. * * @param mapName map name * @return A completable future to be completed with the result once complete. */ CompletableFuture> 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> 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>> 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>>> 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 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 counterGetAndAdd(String counterName, long delta); /** * Atomically sets the given value to current value of the specified counter. * * @param counterName counter name * @param value value to set * @return void future */ CompletableFuture counterSet(String counterName, long value); /** * Atomically sets the given counter to the specified update value if and only if the current value is equal to the * expected value. * @param counterName counter name * @param expectedValue value to use for equivalence check * @param update value to set if expected value is current value * @return true if an update occurred, false otherwise */ CompletableFuture counterCompareAndSet(String counterName, long expectedValue, long update); /** * Returns the current value of the specified atomic counter. * * @param counterName counter name * @return current value */ CompletableFuture counterGet(String counterName); /** * Returns the size of queue. * * @param queueName queue name * @return queue size */ CompletableFuture queueSize(String queueName); /** * Inserts an entry into the queue. * * @param queueName queue name * @param entry queue entry * @return void future */ CompletableFuture 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 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 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 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 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 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 rollback(Transaction transaction); }