blob: d9ab7e5a498fa07b3e10ba095843366e073b62bf [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 Jampanif4c88502016-01-21 12:35:36 -080017package org.onosproject.store.primitives.impl;
Madan Jampani94c23532015-02-05 17:40:01 -080018
Madan Jampani94c23532015-02-05 17:40:01 -080019import net.kuujo.copycat.state.Command;
20import net.kuujo.copycat.state.Initializer;
21import net.kuujo.copycat.state.Query;
22import net.kuujo.copycat.state.StateContext;
Madan Jampanif2f086c2016-01-13 16:15:39 -080023
24import org.onlab.util.Match;
Aaron Kruglikov82fd6322015-10-06 12:02:46 -070025import org.onosproject.store.service.Versioned;
26
27import java.util.Collection;
28import java.util.Map;
29import java.util.Map.Entry;
30import java.util.Set;
Madan Jampani94c23532015-02-05 17:40:01 -080031
32/**
33 * Database state.
34 *
35 */
36public interface DatabaseState<K, V> {
37
38 /**
39 * Initializes the database state.
40 *
41 * @param context The map state context.
42 */
43 @Initializer
Sho SHIMIZU3310a342015-05-13 12:14:05 -070044 void init(StateContext<DatabaseState<K, V>> context);
Madan Jampani94c23532015-02-05 17:40:01 -080045
46 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070047 Set<String> maps();
Madan Jampania89f8f92015-04-01 14:39:54 -070048
49 @Query
Madan Jampanib5d72d52015-04-03 16:53:50 -070050 Map<String, Long> counters();
51
52 @Query
Madan Jampani3ca9cb62015-07-21 11:35:44 -070053 int mapSize(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080054
55 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070056 boolean mapIsEmpty(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080057
58 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070059 boolean mapContainsKey(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080060
61 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070062 boolean mapContainsValue(String mapName, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080063
64 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070065 Versioned<V> mapGet(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080066
67 @Command
Madan Jampani7804c992015-07-20 13:20:19 -070068 Result<UpdateResult<K, V>> mapUpdate(String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080069
70 @Command
Madan Jampani7804c992015-07-20 13:20:19 -070071 Result<Void> mapClear(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080072
73 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070074 Set<K> mapKeySet(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080075
76 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070077 Collection<Versioned<V>> mapValues(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080078
79 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070080 Set<Entry<K, Versioned<V>>> mapEntrySet(String mapName);
Madan Jampani346d4f52015-05-04 11:09:39 -070081
82 @Command
Madan Jampani55ac1342015-05-04 19:05:04 -070083 Long counterAddAndGet(String counterName, long delta);
Madan Jampani04aeb452015-05-02 16:12:24 -070084
85 @Command
Aaron Kruglikov82fd6322015-10-06 12:02:46 -070086 Boolean counterCompareAndSet(String counterName, long expectedValue, long updateValue);
87
88 @Command
Madan Jampani04aeb452015-05-02 16:12:24 -070089 Long counterGetAndAdd(String counterName, long delta);
Madan Jampanib5d72d52015-04-03 16:53:50 -070090
91 @Query
Madan Jampani63c659f2015-06-11 00:52:58 -070092 Long queueSize(String queueName);
93
94 @Query
95 byte[] queuePeek(String queueName);
96
97 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -070098 byte[] queuePop(String queueName);
Madan Jampani63c659f2015-06-11 00:52:58 -070099
100 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -0700101 void queuePush(String queueName, byte[] entry);
Madan Jampani63c659f2015-06-11 00:52:58 -0700102
103 @Query
Madan Jampani04aeb452015-05-02 16:12:24 -0700104 Long counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700105
106 @Command
alshabib6cb86362016-03-03 18:00:58 -0800107 void counterSet(String counterName, long value);
108
109 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700110 CommitResponse prepareAndCommit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700111
112 @Command
113 boolean prepare(Transaction transaction);
114
115 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700116 CommitResponse commit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700117
118 @Command
119 boolean rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800120}