Madan Jampani | 2546111 | 2015-02-17 14:17:29 -0800 | [diff] [blame] | 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 | |
Madan Jampani | f4c8850 | 2016-01-21 12:35:36 -0800 | [diff] [blame] | 17 | package org.onosproject.store.primitives.impl; |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 18 | |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 19 | import net.kuujo.copycat.state.Command; |
| 20 | import net.kuujo.copycat.state.Initializer; |
| 21 | import net.kuujo.copycat.state.Query; |
| 22 | import net.kuujo.copycat.state.StateContext; |
Madan Jampani | f2f086c | 2016-01-13 16:15:39 -0800 | [diff] [blame] | 23 | |
| 24 | import org.onlab.util.Match; |
Aaron Kruglikov | 82fd632 | 2015-10-06 12:02:46 -0700 | [diff] [blame] | 25 | import org.onosproject.store.service.Versioned; |
| 26 | |
| 27 | import java.util.Collection; |
| 28 | import java.util.Map; |
| 29 | import java.util.Map.Entry; |
| 30 | import java.util.Set; |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 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 |
Sho SHIMIZU | 3310a34 | 2015-05-13 12:14:05 -0700 | [diff] [blame] | 44 | void init(StateContext<DatabaseState<K, V>> context); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 45 | |
| 46 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 47 | Set<String> maps(); |
Madan Jampani | a89f8f9 | 2015-04-01 14:39:54 -0700 | [diff] [blame] | 48 | |
| 49 | @Query |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 50 | Map<String, Long> counters(); |
| 51 | |
| 52 | @Query |
Madan Jampani | 3ca9cb6 | 2015-07-21 11:35:44 -0700 | [diff] [blame] | 53 | int mapSize(String mapName); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 54 | |
| 55 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 56 | boolean mapIsEmpty(String mapName); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 57 | |
| 58 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 59 | boolean mapContainsKey(String mapName, K key); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 60 | |
| 61 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 62 | boolean mapContainsValue(String mapName, V value); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 63 | |
| 64 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 65 | Versioned<V> mapGet(String mapName, K key); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 66 | |
| 67 | @Command |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 68 | Result<UpdateResult<K, V>> mapUpdate(String mapName, K key, Match<V> valueMatch, Match<Long> versionMatch, V value); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 69 | |
| 70 | @Command |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 71 | Result<Void> mapClear(String mapName); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 72 | |
| 73 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 74 | Set<K> mapKeySet(String mapName); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 75 | |
| 76 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 77 | Collection<Versioned<V>> mapValues(String mapName); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 78 | |
| 79 | @Query |
Madan Jampani | 7804c99 | 2015-07-20 13:20:19 -0700 | [diff] [blame] | 80 | Set<Entry<K, Versioned<V>>> mapEntrySet(String mapName); |
Madan Jampani | 346d4f5 | 2015-05-04 11:09:39 -0700 | [diff] [blame] | 81 | |
| 82 | @Command |
Madan Jampani | 55ac134 | 2015-05-04 19:05:04 -0700 | [diff] [blame] | 83 | Long counterAddAndGet(String counterName, long delta); |
Madan Jampani | 04aeb45 | 2015-05-02 16:12:24 -0700 | [diff] [blame] | 84 | |
| 85 | @Command |
Aaron Kruglikov | 82fd632 | 2015-10-06 12:02:46 -0700 | [diff] [blame] | 86 | Boolean counterCompareAndSet(String counterName, long expectedValue, long updateValue); |
| 87 | |
| 88 | @Command |
Madan Jampani | 04aeb45 | 2015-05-02 16:12:24 -0700 | [diff] [blame] | 89 | Long counterGetAndAdd(String counterName, long delta); |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 90 | |
| 91 | @Query |
Madan Jampani | 63c659f | 2015-06-11 00:52:58 -0700 | [diff] [blame] | 92 | Long queueSize(String queueName); |
| 93 | |
| 94 | @Query |
| 95 | byte[] queuePeek(String queueName); |
| 96 | |
| 97 | @Command |
Madan Jampani | a6d787b | 2015-08-11 11:02:02 -0700 | [diff] [blame] | 98 | byte[] queuePop(String queueName); |
Madan Jampani | 63c659f | 2015-06-11 00:52:58 -0700 | [diff] [blame] | 99 | |
| 100 | @Command |
Madan Jampani | a6d787b | 2015-08-11 11:02:02 -0700 | [diff] [blame] | 101 | void queuePush(String queueName, byte[] entry); |
Madan Jampani | 63c659f | 2015-06-11 00:52:58 -0700 | [diff] [blame] | 102 | |
| 103 | @Query |
Madan Jampani | 04aeb45 | 2015-05-02 16:12:24 -0700 | [diff] [blame] | 104 | Long counterGet(String counterName); |
Madan Jampani | b5d72d5 | 2015-04-03 16:53:50 -0700 | [diff] [blame] | 105 | |
| 106 | @Command |
alshabib | 6cb8636 | 2016-03-03 18:00:58 -0800 | [diff] [blame] | 107 | void counterSet(String counterName, long value); |
| 108 | |
| 109 | @Command |
Madan Jampani | bab51a4 | 2015-08-10 13:53:35 -0700 | [diff] [blame] | 110 | CommitResponse prepareAndCommit(Transaction transaction); |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 111 | |
| 112 | @Command |
| 113 | boolean prepare(Transaction transaction); |
| 114 | |
| 115 | @Command |
Madan Jampani | bab51a4 | 2015-08-10 13:53:35 -0700 | [diff] [blame] | 116 | CommitResponse commit(Transaction transaction); |
Madan Jampani | bff6d8f | 2015-03-31 16:53:47 -0700 | [diff] [blame] | 117 | |
| 118 | @Command |
| 119 | boolean rollback(Transaction transaction); |
Madan Jampani | 94c2353 | 2015-02-05 17:40:01 -0800 | [diff] [blame] | 120 | } |