b3dd1c447006b290a5aba2c714ebcc77cc118955
[onosfw.git] /
1 /*
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
17 package org.onosproject.store.consistent.impl;
18
19 import java.util.Collection;
20 import java.util.Map;
21 import java.util.Map.Entry;
22 import java.util.Set;
23
24 import org.onosproject.store.service.Transaction;
25 import org.onosproject.store.service.Versioned;
26
27 import net.kuujo.copycat.state.Command;
28 import net.kuujo.copycat.state.Initializer;
29 import net.kuujo.copycat.state.Query;
30 import net.kuujo.copycat.state.StateContext;
31
32 /**
33  * Database state.
34  *
35  */
36 public interface DatabaseState<K, V> {
37
38   /**
39    * Initializes the database state.
40    *
41    * @param context The map state context.
42    */
43   @Initializer
44   void init(StateContext<DatabaseState<K, V>> context);
45
46   @Query
47   Set<String> maps();
48
49   @Query
50   Map<String, Long> counters();
51
52   @Query
53   int mapSize(String mapName);
54
55   @Query
56   boolean mapIsEmpty(String mapName);
57
58   @Query
59   boolean mapContainsKey(String mapName, K key);
60
61   @Query
62   boolean mapContainsValue(String mapName, V value);
63
64   @Query
65   Versioned<V> mapGet(String mapName, K key);
66
67   @Command
68   Result<UpdateResult<K, V>> mapUpdate(String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value);
69
70   @Command
71   Result<Void> mapClear(String mapName);
72
73   @Query
74   Set<K> mapKeySet(String mapName);
75
76   @Query
77   Collection<Versioned<V>> mapValues(String mapName);
78
79   @Query
80   Set<Entry<K, Versioned<V>>> mapEntrySet(String mapName);
81
82   @Command
83   Long counterAddAndGet(String counterName, long delta);
84
85   @Command
86   Long counterGetAndAdd(String counterName, long delta);
87
88   @Query
89   Long queueSize(String queueName);
90
91   @Query
92   byte[] queuePeek(String queueName);
93
94   @Command
95   byte[] queuePop(String queueName);
96
97   @Command
98   void queuePush(String queueName, byte[] entry);
99
100   @Query
101   Long counterGet(String counterName);
102
103   @Command
104   CommitResponse prepareAndCommit(Transaction transaction);
105
106   @Command
107   boolean prepare(Transaction transaction);
108
109   @Command
110   CommitResponse commit(Transaction transaction);
111
112   @Command
113   boolean rollback(Transaction transaction);
114 }