Committed by
Gerrit Code Review
Adding additional TreeMap resources
Change-Id: I103a8c5e6fb1c5e7a6ae0942e0b746367da18736
Showing
8 changed files
with
88 additions
and
22 deletions
... | @@ -243,8 +243,9 @@ public interface AsyncConsistentMap<K, V> extends DistributedPrimitive { | ... | @@ -243,8 +243,9 @@ public interface AsyncConsistentMap<K, V> extends DistributedPrimitive { |
243 | CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet(); | 243 | CompletableFuture<Set<Entry<K, Versioned<V>>>> entrySet(); |
244 | 244 | ||
245 | /** | 245 | /** |
246 | - * If the specified key is not already associated with a value | 246 | + * If the specified key is not already associated with a value associates |
247 | - * associates it with the given value and returns null, else returns the current value. | 247 | + * it with the given value and returns null, else behaves as a get |
248 | + * returning the existing mapping without making any changes. | ||
248 | * | 249 | * |
249 | * @param key key with which the specified value is to be associated | 250 | * @param key key with which the specified value is to be associated |
250 | * @param value value to be associated with the specified key | 251 | * @param value value to be associated with the specified key | ... | ... |
... | @@ -19,6 +19,7 @@ package org.onosproject.store.service; | ... | @@ -19,6 +19,7 @@ package org.onosproject.store.service; |
19 | import org.onosproject.store.primitives.DefaultConsistentTreeMap; | 19 | import org.onosproject.store.primitives.DefaultConsistentTreeMap; |
20 | 20 | ||
21 | import java.util.Map; | 21 | import java.util.Map; |
22 | +import java.util.NavigableMap; | ||
22 | import java.util.NavigableSet; | 23 | import java.util.NavigableSet; |
23 | import java.util.concurrent.CompletableFuture; | 24 | import java.util.concurrent.CompletableFuture; |
24 | 25 | ||
... | @@ -42,26 +43,28 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -42,26 +43,28 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
42 | CompletableFuture<K> lastKey(); | 43 | CompletableFuture<K> lastKey(); |
43 | 44 | ||
44 | /** | 45 | /** |
45 | - * Returns the entry associated with the least key greater than or equal to the key. | 46 | + * Returns the entry associated with the least key greater than or equal to |
47 | + * the key. | ||
46 | * | 48 | * |
47 | * @param key the key | 49 | * @param key the key |
48 | - * @return the entry or null | 50 | + * @return the entry or null if no suitable key exists |
49 | */ | 51 | */ |
50 | CompletableFuture<Map.Entry<K, Versioned<V>>> ceilingEntry(K key); | 52 | CompletableFuture<Map.Entry<K, Versioned<V>>> ceilingEntry(K key); |
51 | 53 | ||
52 | /** | 54 | /** |
53 | - * Returns the entry associated with the greatest key less than or equal to key. | 55 | + * Returns the entry associated with the greatest key less than or equal |
56 | + * to key. | ||
54 | * | 57 | * |
55 | * @param key the key | 58 | * @param key the key |
56 | - * @return the entry or null | 59 | + * @return the entry or null if no suitable key exists |
57 | */ | 60 | */ |
58 | CompletableFuture<Map.Entry<K, Versioned<V>>> floorEntry(K key); | 61 | CompletableFuture<Map.Entry<K, Versioned<V>>> floorEntry(K key); |
59 | 62 | ||
60 | /** | 63 | /** |
61 | - * Returns the entry associated with the lest key greater than key. | 64 | + * Returns the entry associated with the least key greater than key. |
62 | * | 65 | * |
63 | * @param key the key | 66 | * @param key the key |
64 | - * @return the entry or null | 67 | + * @return the entry or null if no suitable key exists |
65 | */ | 68 | */ |
66 | CompletableFuture<Map.Entry<K, Versioned<V>>> higherEntry(K key); | 69 | CompletableFuture<Map.Entry<K, Versioned<V>>> higherEntry(K key); |
67 | 70 | ||
... | @@ -69,35 +72,35 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -69,35 +72,35 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
69 | * Returns the entry associated with the largest key less than key. | 72 | * Returns the entry associated with the largest key less than key. |
70 | * | 73 | * |
71 | * @param key the key | 74 | * @param key the key |
72 | - * @return the entry or null | 75 | + * @return the entry or null if no suitable key exists |
73 | */ | 76 | */ |
74 | CompletableFuture<Map.Entry<K, Versioned<V>>> lowerEntry(K key); | 77 | CompletableFuture<Map.Entry<K, Versioned<V>>> lowerEntry(K key); |
75 | 78 | ||
76 | /** | 79 | /** |
77 | * Return the entry associated with the lowest key in the map. | 80 | * Return the entry associated with the lowest key in the map. |
78 | * | 81 | * |
79 | - * @return the entry or null | 82 | + * @return the entry or null if none exist |
80 | */ | 83 | */ |
81 | CompletableFuture<Map.Entry<K, Versioned<V>>> firstEntry(); | 84 | CompletableFuture<Map.Entry<K, Versioned<V>>> firstEntry(); |
82 | 85 | ||
83 | /** | 86 | /** |
84 | - * Return the entry assocaited with the highest key in the map. | 87 | + * Return the entry associated with the highest key in the map. |
85 | * | 88 | * |
86 | - * @return the entry or null | 89 | + * @return the entry or null if none exist |
87 | */ | 90 | */ |
88 | CompletableFuture<Map.Entry<K, Versioned<V>>> lastEntry(); | 91 | CompletableFuture<Map.Entry<K, Versioned<V>>> lastEntry(); |
89 | 92 | ||
90 | /** | 93 | /** |
91 | * Return and remove the entry associated with the lowest key. | 94 | * Return and remove the entry associated with the lowest key. |
92 | * | 95 | * |
93 | - * @return the entry or null | 96 | + * @return the entry or null if none exist |
94 | */ | 97 | */ |
95 | CompletableFuture<Map.Entry<K, Versioned<V>>> pollFirstEntry(); | 98 | CompletableFuture<Map.Entry<K, Versioned<V>>> pollFirstEntry(); |
96 | 99 | ||
97 | /** | 100 | /** |
98 | * Return and remove the entry associated with the highest key. | 101 | * Return and remove the entry associated with the highest key. |
99 | * | 102 | * |
100 | - * @return the entry or null | 103 | + * @return the entry or null if none exist |
101 | */ | 104 | */ |
102 | CompletableFuture<Map.Entry<K, Versioned<V>>> pollLastEntry(); | 105 | CompletableFuture<Map.Entry<K, Versioned<V>>> pollLastEntry(); |
103 | 106 | ||
... | @@ -105,15 +108,15 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -105,15 +108,15 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
105 | * Return the entry associated with the greatest key less than key. | 108 | * Return the entry associated with the greatest key less than key. |
106 | * | 109 | * |
107 | * @param key the key | 110 | * @param key the key |
108 | - * @return the entry or null | 111 | + * @return the entry or null if no suitable key exists |
109 | */ | 112 | */ |
110 | CompletableFuture<K> lowerKey(K key); | 113 | CompletableFuture<K> lowerKey(K key); |
111 | 114 | ||
112 | /** | 115 | /** |
113 | - * Return the entry associated with the highest key less than or equal to key. | 116 | + * Return the highest key less than or equal to key. |
114 | * | 117 | * |
115 | * @param key the key | 118 | * @param key the key |
116 | - * @return the entry or null | 119 | + * @return the entry or null if no suitable key exists |
117 | */ | 120 | */ |
118 | CompletableFuture<K> floorKey(K key); | 121 | CompletableFuture<K> floorKey(K key); |
119 | 122 | ||
... | @@ -121,7 +124,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -121,7 +124,7 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
121 | * Return the lowest key greater than or equal to key. | 124 | * Return the lowest key greater than or equal to key. |
122 | * | 125 | * |
123 | * @param key the key | 126 | * @param key the key |
124 | - * @return the key or null | 127 | + * @return the entry or null if no suitable key exists |
125 | */ | 128 | */ |
126 | CompletableFuture<K> ceilingKey(K key); | 129 | CompletableFuture<K> ceilingKey(K key); |
127 | 130 | ||
... | @@ -129,17 +132,35 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { | ... | @@ -129,17 +132,35 @@ public interface AsyncConsistentTreeMap<K, V> extends AsyncConsistentMap<K, V> { |
129 | * Return the lowest key greater than key. | 132 | * Return the lowest key greater than key. |
130 | * | 133 | * |
131 | * @param key the key | 134 | * @param key the key |
132 | - * @return the key or null | 135 | + * @return the entry or null if no suitable key exists |
133 | */ | 136 | */ |
134 | CompletableFuture<K> higherKey(K key); | 137 | CompletableFuture<K> higherKey(K key); |
135 | 138 | ||
136 | /** | 139 | /** |
137 | * Returns a navigable set of the keys in this map. | 140 | * Returns a navigable set of the keys in this map. |
138 | * | 141 | * |
139 | - * @return a navigable key set | 142 | + * @return a navigable key set (this may be empty) |
140 | */ | 143 | */ |
141 | CompletableFuture<NavigableSet<K>> navigableKeySet(); | 144 | CompletableFuture<NavigableSet<K>> navigableKeySet(); |
142 | 145 | ||
146 | + /** | ||
147 | + * Returns a navigable map containing the entries from the original map | ||
148 | + * which are larger than (or if specified equal to) {@code lowerKey} AND | ||
149 | + * less than (or if specified equal to) {@code upperKey}. | ||
150 | + * | ||
151 | + * @param upperKey the upper bound for the keys in this map | ||
152 | + * @param lowerKey the lower bound for the keys in this map | ||
153 | + * @param inclusiveUpper whether keys equal to the upperKey should be | ||
154 | + * included | ||
155 | + * @param inclusiveLower whether keys equal to the lowerKey should be | ||
156 | + * included | ||
157 | + * @return a navigable map containing entries in the specified range (this | ||
158 | + * may be empty) | ||
159 | + */ | ||
160 | + CompletableFuture<NavigableMap<K, V>> subMap(K upperKey, K lowerKey, | ||
161 | + boolean inclusiveUpper, | ||
162 | + boolean inclusiveLower); | ||
163 | + | ||
143 | default ConsistentTreeMap<K, V> asTreeMap() { | 164 | default ConsistentTreeMap<K, V> asTreeMap() { |
144 | return asTreeMap(DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS); | 165 | return asTreeMap(DistributedPrimitive.DEFAULT_OPERTATION_TIMEOUT_MILLIS); |
145 | } | 166 | } | ... | ... |
... | @@ -266,7 +266,7 @@ public class AtomixConsistentMap extends AbstractResource<AtomixConsistentMap> | ... | @@ -266,7 +266,7 @@ public class AtomixConsistentMap extends AbstractResource<AtomixConsistentMap> |
266 | public synchronized CompletableFuture<Void> addListener(MapEventListener<String, byte[]> listener, | 266 | public synchronized CompletableFuture<Void> addListener(MapEventListener<String, byte[]> listener, |
267 | Executor executor) { | 267 | Executor executor) { |
268 | if (mapEventListeners.isEmpty()) { | 268 | if (mapEventListeners.isEmpty()) { |
269 | - return client.submit(new Listen()).thenRun(() -> mapEventListeners.putIfAbsent(listener, executor)); | 269 | + return client.submit(new Listen()).thenRun(() -> mapEventListeners.put(listener, executor)); |
270 | } else { | 270 | } else { |
271 | mapEventListeners.put(listener, executor); | 271 | mapEventListeners.put(listener, executor); |
272 | return CompletableFuture.completedFuture(null); | 272 | return CompletableFuture.completedFuture(null); | ... | ... |
This diff is collapsed. Click to expand it.
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.primitives.resources.impl; | ||
18 | + | ||
19 | +import io.atomix.catalyst.serializer.SerializableTypeResolver; | ||
20 | +import io.atomix.copycat.client.CopycatClient; | ||
21 | +import io.atomix.resource.ResourceFactory; | ||
22 | +import io.atomix.resource.ResourceStateMachine; | ||
23 | + | ||
24 | +import java.util.Properties; | ||
25 | + | ||
26 | +/** | ||
27 | + * Factory for {@link AtomixConsistentTreeMap}. | ||
28 | + */ | ||
29 | +public class AtomixConsistentTreeMapFactory implements ResourceFactory<AtomixConsistentTreeMap> { | ||
30 | + @Override | ||
31 | + public SerializableTypeResolver createSerializableTypeResolver() { | ||
32 | + return new AtomixConsistentTreeMapCommands.TypeResolver(); | ||
33 | + } | ||
34 | + | ||
35 | + @Override | ||
36 | + public ResourceStateMachine createStateMachine(Properties config) { | ||
37 | + return new AtomixConsistentTreeMapState(config); | ||
38 | + } | ||
39 | + | ||
40 | + @Override | ||
41 | + public AtomixConsistentTreeMap createInstance(CopycatClient client, Properties options) { | ||
42 | + return new AtomixConsistentTreeMap(client, options); | ||
43 | + } | ||
44 | +} |
This diff is collapsed. Click to expand it.
... | @@ -404,7 +404,7 @@ public class AtomixConsistentSetMultimapTest extends AtomixTestBase { | ... | @@ -404,7 +404,7 @@ public class AtomixConsistentSetMultimapTest extends AtomixTestBase { |
404 | private AtomixConsistentSetMultimap createResource(String mapName) { | 404 | private AtomixConsistentSetMultimap createResource(String mapName) { |
405 | try { | 405 | try { |
406 | AtomixConsistentSetMultimap map = createAtomixClient(). | 406 | AtomixConsistentSetMultimap map = createAtomixClient(). |
407 | - getResource("mapName", AtomixConsistentSetMultimap.class) | 407 | + getResource(mapName, AtomixConsistentSetMultimap.class) |
408 | .join(); | 408 | .join(); |
409 | return map; | 409 | return map; |
410 | } catch (Throwable e) { | 410 | } catch (Throwable e) { | ... | ... |
This diff is collapsed. Click to expand it.
-
Please register or login to post a comment