blob: b3dd1c447006b290a5aba2c714ebcc77cc118955 [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 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
86 Long counterGetAndAdd(String counterName, long delta);
Madan Jampanib5d72d52015-04-03 16:53:50 -070087
88 @Query
Madan Jampani63c659f2015-06-11 00:52:58 -070089 Long queueSize(String queueName);
90
91 @Query
92 byte[] queuePeek(String queueName);
93
94 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -070095 byte[] queuePop(String queueName);
Madan Jampani63c659f2015-06-11 00:52:58 -070096
97 @Command
Madan Jampania6d787b2015-08-11 11:02:02 -070098 void queuePush(String queueName, byte[] entry);
Madan Jampani63c659f2015-06-11 00:52:58 -070099
100 @Query
Madan Jampani04aeb452015-05-02 16:12:24 -0700101 Long counterGet(String counterName);
Madan Jampanib5d72d52015-04-03 16:53:50 -0700102
103 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700104 CommitResponse prepareAndCommit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700105
106 @Command
107 boolean prepare(Transaction transaction);
108
109 @Command
Madan Jampanibab51a42015-08-10 13:53:35 -0700110 CommitResponse commit(Transaction transaction);
Madan Jampanibff6d8f2015-03-31 16:53:47 -0700111
112 @Command
113 boolean rollback(Transaction transaction);
Madan Jampani94c23532015-02-05 17:40:01 -0800114}