blob: 65ffd922624864db38d7cbe83632a2881a7eff9d [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 Jampani94c23532015-02-05 17:40:01 -080017package org.onosproject.store.consistent.impl;
18
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.Transaction;
26import org.onosproject.store.service.Versioned;
27
28import java.util.Collection;
29import java.util.Map;
30import java.util.Map.Entry;
31import java.util.Set;
Madan Jampani94c23532015-02-05 17:40:01 -080032
33/**
34 * Database state.
35 *
36 */
37public interface DatabaseState<K, V> {
38
39 /**
40 * Initializes the database state.
41 *
42 * @param context The map state context.
43 */
44 @Initializer
Sho SHIMIZU3310a342015-05-13 12:14:05 -070045 void init(StateContext<DatabaseState<K, V>> context);
Madan Jampani94c23532015-02-05 17:40:01 -080046
47 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070048 Set<String> maps();
Madan Jampania89f8f92015-04-01 14:39:54 -070049
50 @Query
Madan Jampanib5d72d52015-04-03 16:53:50 -070051 Map<String, Long> counters();
52
53 @Query
Madan Jampani3ca9cb62015-07-21 11:35:44 -070054 int mapSize(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080055
56 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070057 boolean mapIsEmpty(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080058
59 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070060 boolean mapContainsKey(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080061
62 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070063 boolean mapContainsValue(String mapName, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080064
65 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070066 Versioned<V> mapGet(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080067
68 @Command
Madan Jampani7804c992015-07-20 13:20:19 -070069 Result<UpdateResult<K, V>> mapUpdate(String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080070
71 @Command
Madan Jampani7804c992015-07-20 13:20:19 -070072 Result<Void> mapClear(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080073
74 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070075 Set<K> mapKeySet(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080076
77 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070078 Collection<Versioned<V>> mapValues(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080079
80 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070081 Set<Entry<K, Versioned<V>>> mapEntrySet(String mapName);
Madan Jampani346d4f52015-05-04 11:09:39 -070082
83 @Command
Madan Jampani55ac1342015-05-04 19:05:04 -070084 Long counterAddAndGet(String counterName, long delta);
Madan Jampani04aeb452015-05-02 16:12:24 -070085
86 @Command
Aaron Kruglikov82fd6322015-10-06 12:02:46 -070087 Boolean counterCompareAndSet(String counterName, long expectedValue, long updateValue);
88
89 @Command
Madan Jampani04aeb452015-05-02 16:12:24 -070090 Long counterGetAndAdd(String counterName, long delta);
Madan Jampanib5d72d52015-04-03 16:53:50 -070091
92 @Query
Madan Jampani63c659f2015-06-11 00:52:58 -070093 Long queueSize(String queueName);
94
95 @Query
96 byte[] queuePeek(String queueName);
97
98 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -070099 byte[] queuePop(String queueName);
Madan Jampani63c659f2015-06-11 00:52:58 -0700100
101 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -0700102 void queuePush(String queueName, byte[] entry);
Madan Jampani63c659f2015-06-11 00:52:58 -0700103
104 @Query
Madan Jampani04aeb452015-05-02 16:12:24 -0700105 Long counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700106
107 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700108 CommitResponse prepareAndCommit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700109
110 @Command
111 boolean prepare(Transaction transaction);
112
113 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700114 CommitResponse commit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700115
116 @Command
117 boolean rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800118}