blob: 0af7f4290f752953ef4e77a93859e6d0d68ef7a4 [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
19import java.util.Collection;
Madan Jampanib5d72d52015-04-03 16:53:50 -070020import java.util.Map;
Madan Jampani94c23532015-02-05 17:40:01 -080021import java.util.Map.Entry;
22import java.util.Set;
23
Madan Jampani63c659f2015-06-11 00:52:58 -070024import org.onosproject.cluster.NodeId;
Madan Jampanibff6d8f2015-03-31 16:53:47 -070025import org.onosproject.store.service.Transaction;
Madan Jampani393e0f02015-02-12 07:35:39 +053026import org.onosproject.store.service.Versioned;
27
Madan Jampani94c23532015-02-05 17:40:01 -080028import net.kuujo.copycat.state.Command;
29import net.kuujo.copycat.state.Initializer;
30import net.kuujo.copycat.state.Query;
31import net.kuujo.copycat.state.StateContext;
32
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 Jampania89f8f92015-04-01 14:39:54 -070048 Set<String> tableNames();
49
50 @Query
Madan Jampanib5d72d52015-04-03 16:53:50 -070051 Map<String, Long> counters();
52
53 @Query
Madan Jampani94c23532015-02-05 17:40:01 -080054 int size(String tableName);
55
56 @Query
57 boolean isEmpty(String tableName);
58
59 @Query
60 boolean containsKey(String tableName, K key);
61
62 @Query
63 boolean containsValue(String tableName, V value);
64
65 @Query
66 Versioned<V> get(String tableName, K key);
67
68 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070069 Result<Versioned<V>> put(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080070
71 @Command
Madan Jampani346d4f52015-05-04 11:09:39 -070072 Result<UpdateResult<Versioned<V>>> putAndGet(String tableName, K key, V value);
73
74 @Command
75 Result<UpdateResult<Versioned<V>>> putIfAbsentAndGet(String tableName, K key, V value);
76
77 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070078 Result<Versioned<V>> remove(String tableName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080079
80 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070081 Result<Void> clear(String tableName);
Madan Jampani94c23532015-02-05 17:40:01 -080082
83 @Query
84 Set<K> keySet(String tableName);
85
86 @Query
87 Collection<Versioned<V>> values(String tableName);
88
89 @Query
90 Set<Entry<K, Versioned<V>>> entrySet(String tableName);
91
92 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070093 Result<Versioned<V>> putIfAbsent(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080094
95 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070096 Result<Boolean> remove(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080097
98 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070099 Result<Boolean> remove(String tableName, K key, long version);
Madan Jampani94c23532015-02-05 17:40:01 -0800100
101 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700102 Result<Boolean> replace(String tableName, K key, V oldValue, V newValue);
Madan Jampani94c23532015-02-05 17:40:01 -0800103
104 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700105 Result<Boolean> replace(String tableName, K key, long oldVersion, V newValue);
Madan Jampani94c23532015-02-05 17:40:01 -0800106
107 @Command
Madan Jampani346d4f52015-05-04 11:09:39 -0700108 Result<UpdateResult<Versioned<V>>> replaceAndGet(String tableName, K key, long oldVersion, V newValue);
109
110 @Command
Madan Jampani55ac1342015-05-04 19:05:04 -0700111 Long counterAddAndGet(String counterName, long delta);
Madan Jampani04aeb452015-05-02 16:12:24 -0700112
113 @Command
114 Long counterGetAndAdd(String counterName, long delta);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700115
116 @Query
Madan Jampani63c659f2015-06-11 00:52:58 -0700117 Long queueSize(String queueName);
118
119 @Query
120 byte[] queuePeek(String queueName);
121
122 @Command
123 byte[] queuePop(String queueName, NodeId requestor);
124
125 @Command
126 Set<NodeId> queuePush(String queueName, byte[] entry);
127
128 @Query
Madan Jampani04aeb452015-05-02 16:12:24 -0700129 Long counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700130
131 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700132 boolean prepareAndCommit(Transaction transaction);
133
134 @Command
135 boolean prepare(Transaction transaction);
136
137 @Command
138 boolean commit(Transaction transaction);
139
140 @Command
141 boolean rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800142}