blob: 83909d843eaf258852a2f88ea01401283ed358ab [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 Jampanibff6d8f2015-03-31 16:53:47 -070024import org.onosproject.store.service.Transaction;
Madan Jampani393e0f02015-02-12 07:35:39 +053025import org.onosproject.store.service.Versioned;
26
Madan Jampani94c23532015-02-05 17:40:01 -080027import net.kuujo.copycat.state.Command;
28import net.kuujo.copycat.state.Initializer;
29import net.kuujo.copycat.state.Query;
30import net.kuujo.copycat.state.StateContext;
31
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 Jampania89f8f92015-04-01 14:39:54 -070047 Set<String> tableNames();
48
49 @Query
Madan Jampanib5d72d52015-04-03 16:53:50 -070050 Map<String, Long> counters();
51
52 @Query
Madan Jampani94c23532015-02-05 17:40:01 -080053 int size(String tableName);
54
55 @Query
56 boolean isEmpty(String tableName);
57
58 @Query
59 boolean containsKey(String tableName, K key);
60
61 @Query
62 boolean containsValue(String tableName, V value);
63
64 @Query
65 Versioned<V> get(String tableName, K key);
66
67 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070068 Result<Versioned<V>> put(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080069
70 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070071 Result<Versioned<V>> remove(String tableName, K key);
Madan Jampani94c23532015-02-05 17:40:01 -080072
73 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070074 Result<Void> clear(String tableName);
Madan Jampani94c23532015-02-05 17:40:01 -080075
76 @Query
77 Set<K> keySet(String tableName);
78
79 @Query
80 Collection<Versioned<V>> values(String tableName);
81
82 @Query
83 Set<Entry<K, Versioned<V>>> entrySet(String tableName);
84
85 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070086 Result<Versioned<V>> putIfAbsent(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080087
88 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070089 Result<Boolean> remove(String tableName, K key, V value);
Madan Jampani94c23532015-02-05 17:40:01 -080090
91 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070092 Result<Boolean> remove(String tableName, K key, long version);
Madan Jampani94c23532015-02-05 17:40:01 -080093
94 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070095 Result<Boolean> replace(String tableName, K key, V oldValue, V newValue);
Madan Jampani94c23532015-02-05 17:40:01 -080096
97 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -070098 Result<Boolean> replace(String tableName, K key, long oldVersion, V newValue);
Madan Jampani94c23532015-02-05 17:40:01 -080099
100 @Command
Madan Jampani55ac1342015-05-04 19:05:04 -0700101 Long counterAddAndGet(String counterName, long delta);
Madan Jampani04aeb452015-05-02 16:12:24 -0700102
103 @Command
104 Long counterGetAndAdd(String counterName, long delta);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700105
106 @Query
Madan Jampani04aeb452015-05-02 16:12:24 -0700107 Long counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700108
109 @Command
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700110 boolean prepareAndCommit(Transaction transaction);
111
112 @Command
113 boolean prepare(Transaction transaction);
114
115 @Command
116 boolean commit(Transaction transaction);
117
118 @Command
119 boolean rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800120}