blob: 1136428b0c357b9d7abb488c92a09b546fd51572 [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;
Aaron Kruglikov82fd6322015-10-06 12:02:46 -070023import org.onosproject.store.service.Transaction;
24import org.onosproject.store.service.Versioned;
25
26import java.util.Collection;
27import java.util.Map;
28import java.util.Map.Entry;
29import java.util.Set;
Madan Jampani94c23532015-02-05 17:40:01 -080030
31/**
32 * Database state.
33 *
34 */
35public interface DatabaseState<K, V> {
36
37 /**
38 * Initializes the database state.
39 *
40 * @param context The map state context.
41 */
42 @Initializer
Sho SHIMIZU3310a342015-05-13 12:14:05 -070043 void init(StateContext<DatabaseState<K, V>> context);
Madan Jampani94c23532015-02-05 17:40:01 -080044
45 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070046 Set<String> maps();
Madan Jampania89f8f92015-04-01 14:39:54 -070047
48 @Query
Madan Jampanib5d72d52015-04-03 16:53:50 -070049 Map<String, Long> counters();
50
51 @Query
Madan Jampani3ca9cb62015-07-21 11:35:44 -070052 int mapSize(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080053
54 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070055 boolean mapIsEmpty(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080056
57 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070058 boolean mapContainsKey(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080059
60 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070061 boolean mapContainsValue(String mapName, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080062
63 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070064 Versioned<V> mapGet(String mapName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080065
66 @Command
Madan Jampani7804c992015-07-20 13:20:19 -070067 Result<UpdateResult<K, V>> mapUpdate(String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080068
69 @Command
Madan Jampani7804c992015-07-20 13:20:19 -070070 Result<Void> mapClear(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080071
72 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070073 Set<K> mapKeySet(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080074
75 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070076 Collection<Versioned<V>> mapValues(String mapName);
Madan Jampani94c23532015-02-05 17:40:01 -080077
78 @Query
Madan Jampani7804c992015-07-20 13:20:19 -070079 Set<Entry<K, Versioned<V>>> mapEntrySet(String mapName);
Madan Jampani346d4f52015-05-04 11:09:39 -070080
81 @Command
Madan Jampani55ac1342015-05-04 19:05:04 -070082 Long counterAddAndGet(String counterName, long delta);
Madan Jampani04aeb452015-05-02 16:12:24 -070083
84 @Command
Aaron Kruglikov82fd6322015-10-06 12:02:46 -070085 Boolean counterCompareAndSet(String counterName, long expectedValue, long updateValue);
86
87 @Command
Madan Jampani04aeb452015-05-02 16:12:24 -070088 Long counterGetAndAdd(String counterName, long delta);
Madan Jampanib5d72d52015-04-03 16:53:50 -070089
90 @Query
Madan Jampani63c659f2015-06-11 00:52:58 -070091 Long queueSize(String queueName);
92
93 @Query
94 byte[] queuePeek(String queueName);
95
96 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -070097 byte[] queuePop(String queueName);
Madan Jampani63c659f2015-06-11 00:52:58 -070098
99 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -0700100 void queuePush(String queueName, byte[] entry);
Madan Jampani63c659f2015-06-11 00:52:58 -0700101
102 @Query
Madan Jampani04aeb452015-05-02 16:12:24 -0700103 Long counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700104
105 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700106 CommitResponse prepareAndCommit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700107
108 @Command
109 boolean prepare(Transaction transaction);
110
111 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700112 CommitResponse commit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700113
114 @Command
115 boolean rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800116}