Aaron Kruglikov
Committed by Gerrit Code Review

Adding asyncConsistentMultimap interface.

Change-Id: I3cd3632e29ff8c5eaf8328a7fdf77ead0b2d9093
1 +/*
2 + * Copyright 2016 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.service;
18 +
19 +import com.google.common.collect.Multimap;
20 +import com.google.common.collect.Multiset;
21 +
22 +import java.util.Collection;
23 +import java.util.Map;
24 +import java.util.Set;
25 +import java.util.concurrent.CompletableFuture;
26 +
27 +/**
28 + * Interface for a distributed multimap.
29 + *
30 + * NOTE: Editing any returned collection will NOT effect the map itself and
31 + * changes in the map will NOT be reflected in the returned collections.
32 + * Certain operations may be too expensive when backed by a distributed data
33 + * structure and have been labeled as such.
34 + */
35 +public interface AsyncConsistentMultimap<K, V> extends DistributedPrimitive {
36 +
37 + @Override
38 + default DistributedPrimitive.Type primitiveType() {
39 + return Type.CONSISTENT_MULTIMAP;
40 + }
41 +
42 + @Override
43 + default CompletableFuture<Void> destroy() {
44 + return clear();
45 + }
46 +
47 + /**
48 + * Returns the number of key-value pairs in this multimap.
49 + * @return the number of key-value pairs
50 + */
51 + CompletableFuture<Integer> size();
52 +
53 + /**
54 + * Returns if this multimap contains no key-value pairs.
55 + * @return completable future that will be true if no key-value pairs
56 + * exist, false otherwise
57 + */
58 + CompletableFuture<Boolean> isEmpty();
59 +
60 + /**
61 + * Returns true if there is at lease one key-value pair with a key equal to
62 + * key.
63 + * @param key the key to query
64 + * @return a future whose value will be true if the map contains a
65 + * key-value pair with key false otherwise
66 + */
67 + CompletableFuture<Boolean> containsKey(K key);
68 +
69 + /**
70 + * Returns true if this map contains at lease one key-value pair with a
71 + * value equal to value.
72 + * @param value the value to query
73 + * @return a future whose value will be true if there is a key-value pair
74 + * with the specified value, false otherwise.
75 + */
76 + CompletableFuture<Boolean> containsValue(V value);
77 +
78 + /**
79 + * Returns true if this map contains at least one key-value pair with key
80 + * and value specified.
81 + * @return a future whose value will be true if there is a key-value pair
82 + * with the specified key and value,
83 + * false otherwise.
84 + */
85 + CompletableFuture<Boolean> containsEntry(K key, V value);
86 +
87 + /**
88 + * If the key-value pair does not already exist adds either the key value
89 + * pair or the value to the set of values associated with the key and
90 + * returns true, if the key-value pair already exists then behavior is
91 + * implementation specific with some implementations allowing duplicates
92 + * and others ignoring put requests for existing entries.
93 + * @param key the key to add
94 + * @param value the value to add
95 + * @return a future whose value will betrue if the map has changed because
96 + * of this call, false otherwise
97 + */
98 + CompletableFuture<Boolean> put(K key, V value);
99 +
100 + /**
101 + * Removes the key-value pair with the specified values if it exists. In
102 + * implementations that allow duplicates which matching entry will be
103 + * removed is undefined.
104 + * @param key the key of the pair to be removed
105 + * @param value the value of the pair to be removed
106 + * @return a future whose value will be true if the map changed because of
107 + * this call, false otherwise.
108 + */
109 + CompletableFuture<Boolean> remove(K key, V value);
110 +
111 + /**
112 + * Adds the set of key-value pairs of the specified key with each of the
113 + * values in the iterable if each key-value pair does not already exist,
114 + * if the pair does exist the behavior is implementation specific.
115 + * (Same as repeated puts but with efficiency gains.)
116 + * @param key the key to use for all pairs to be added
117 + * @param values the set of values to be added in pairs with the key
118 + * @return a future whose value will be true if any change in the map
119 + * results from this call, false otherwise
120 + */
121 + CompletableFuture<Boolean> putAll(K key, Iterable<? extends V> values);
122 +
123 + /**
124 + * Adds all entries from this multimap that are not already present, and
125 + * may or may not add duplicate entries depending on the implementation.
126 + * @param multiMap the map whose entries should be added
127 + * @return a future whose value will be true if any change results from
128 + * this call, false otherwise
129 + */
130 + CompletableFuture<Boolean> putAll(
131 + Multimap<? extends K, ? extends V> multiMap);
132 +
133 + /**
134 + * Stores all the values in values associated with the key specified,
135 + * removes all preexisting values and returns a collection of the removed
136 + * values which may be empty if the entry did not exist.
137 + * @param key the key for all entries to be added
138 + * @param values the values to be associated with the key
139 + * @return a future whose value will be the collection of removed values,
140 + * which may be empty
141 + */
142 + CompletableFuture<Collection<V>> replaceValues(K key, Iterable<V> values);
143 +
144 + /**
145 + * Removes all values associated with the specified key as well as the key
146 + * itself.
147 + * @param key the key whose key-value pairs will be removed
148 + * @return a future whose value is the set of values that were removed,
149 + * which may be empty
150 + */
151 + CompletableFuture<Collection<V>> removeAll(K key);
152 +
153 + /**
154 + * Removes all key-value pairs, after which it will be empty.
155 + * @return a future whose value is irrelevant, simply used to determine if
156 + * the call has completed
157 + */
158 + CompletableFuture<Void> clear();
159 +
160 + /**
161 + * Returns a collection of values associated with the specified key, if the
162 + * key is not in the map it will return an empty collection.
163 + * @param key the key whose associated values will be returned
164 + * @return a future whose value will be the collection of the values
165 + * associated with the specified key, the collection may be empty
166 + */
167 + CompletableFuture<Collection<V>> get(K key);
168 +
169 + /**
170 + * Returns a set of the keys contained in this multimap with one or more
171 + * associated values.
172 + * @return a future whose value will be the collection of all keys with one
173 + * or more associated values, this may be empty
174 + */
175 + CompletableFuture<Set<K>> keySet();
176 +
177 + /**
178 + * Returns a multiset of the keys present in this multimap with one or more
179 + * associated values each. Keys will appear once for each key-value pair
180 + * in which they participate.
181 + * @return a future whose value will be a multiset of the keys, this may
182 + * be empty
183 + */
184 + CompletableFuture<Multiset<K>> keys();
185 +
186 + /**
187 + * Returns a collection of values in the set with duplicates permitted, the
188 + * size of this collection will equal the size of the map at the time of
189 + * creation.
190 + * @return a future whose value will be a collection of values, this may be
191 + * empty
192 + */
193 + CompletableFuture<Collection<V>> values();
194 +
195 + /**
196 + * Returns a collection of each key-value pair in this map.
197 + * @return a future whose value will be a collection of all entries in the
198 + * map, this may be empty
199 + */
200 + CompletableFuture<Collection<Map.Entry<K, V>>> entries();
201 +
202 + /**
203 + * Returns a map of keys to collections of values that reflect the set of
204 + * key-value pairs contained in the multimap, where the key value pairs
205 + * would be the key paired with each of the values in the collection.
206 + * @return a future whose value will be a map of keys to collections of
207 + * values, the returned map may be empty.
208 + */
209 + CompletableFuture<Map<K, Collection<V>>> asMap();
210 +}
...@@ -39,6 +39,11 @@ public interface DistributedPrimitive { ...@@ -39,6 +39,11 @@ public interface DistributedPrimitive {
39 EVENTUALLY_CONSISTENT_MAP, 39 EVENTUALLY_CONSISTENT_MAP,
40 40
41 /** 41 /**
42 + * Consistent Multimap.
43 + */
44 + CONSISTENT_MULTIMAP,
45 +
46 + /**
42 * distributed set. 47 * distributed set.
43 */ 48 */
44 SET, 49 SET,
......