Madan Jampani
Committed by Gerrit Code Review

Ensure serialization exceptions are appropriately reported

Change-Id: Ib7a11f246a79e84e7d1a9e4bddc85d08e0f0cbf0
...@@ -26,6 +26,7 @@ import java.util.function.Function; ...@@ -26,6 +26,7 @@ import java.util.function.Function;
26 import java.util.function.Predicate; 26 import java.util.function.Predicate;
27 import java.util.stream.Collectors; 27 import java.util.stream.Collectors;
28 28
29 +import org.onlab.util.Tools;
29 import org.onosproject.store.primitives.TransactionId; 30 import org.onosproject.store.primitives.TransactionId;
30 import org.onosproject.store.service.AsyncConsistentMap; 31 import org.onosproject.store.service.AsyncConsistentMap;
31 import org.onosproject.store.service.MapEvent; 32 import org.onosproject.store.service.MapEvent;
...@@ -80,45 +81,73 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi ...@@ -80,45 +81,73 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi
80 81
81 @Override 82 @Override
82 public CompletableFuture<Boolean> containsKey(K1 key) { 83 public CompletableFuture<Boolean> containsKey(K1 key) {
83 - return backingMap.containsKey(keyEncoder.apply(key)); 84 + try {
85 + return backingMap.containsKey(keyEncoder.apply(key));
86 + } catch (Exception e) {
87 + return Tools.exceptionalFuture(e);
88 + }
84 } 89 }
85 90
86 @Override 91 @Override
87 public CompletableFuture<Boolean> containsValue(V1 value) { 92 public CompletableFuture<Boolean> containsValue(V1 value) {
88 - return backingMap.containsValue(valueEncoder.apply(value)); 93 + try {
94 + return backingMap.containsValue(valueEncoder.apply(value));
95 + } catch (Exception e) {
96 + return Tools.exceptionalFuture(e);
97 + }
89 } 98 }
90 99
91 @Override 100 @Override
92 public CompletableFuture<Versioned<V1>> get(K1 key) { 101 public CompletableFuture<Versioned<V1>> get(K1 key) {
93 - return backingMap.get(keyEncoder.apply(key)).thenApply(versionedValueTransform); 102 + try {
103 + return backingMap.get(keyEncoder.apply(key)).thenApply(versionedValueTransform);
104 + } catch (Exception e) {
105 + return Tools.exceptionalFuture(e);
106 + }
94 } 107 }
95 108
96 @Override 109 @Override
97 public CompletableFuture<Versioned<V1>> computeIf(K1 key, 110 public CompletableFuture<Versioned<V1>> computeIf(K1 key,
98 Predicate<? super V1> condition, 111 Predicate<? super V1> condition,
99 BiFunction<? super K1, ? super V1, ? extends V1> remappingFunction) { 112 BiFunction<? super K1, ? super V1, ? extends V1> remappingFunction) {
100 - return backingMap.computeIf(keyEncoder.apply(key), 113 + try {
101 - v -> condition.test(valueDecoder.apply(v)), 114 + return backingMap.computeIf(keyEncoder.apply(key),
102 - (k, v) -> valueEncoder.apply(remappingFunction.apply(keyDecoder.apply(k), 115 + v -> condition.test(valueDecoder.apply(v)),
103 - valueDecoder.apply(v)))) 116 + (k, v) -> valueEncoder.apply(remappingFunction.apply(keyDecoder.apply(k),
104 - .thenApply(versionedValueTransform); 117 + valueDecoder.apply(v))))
118 + .thenApply(versionedValueTransform);
119 + } catch (Exception e) {
120 + return Tools.exceptionalFuture(e);
121 + }
105 } 122 }
106 123
107 @Override 124 @Override
108 public CompletableFuture<Versioned<V1>> put(K1 key, V1 value) { 125 public CompletableFuture<Versioned<V1>> put(K1 key, V1 value) {
109 - return backingMap.put(keyEncoder.apply(key), valueEncoder.apply(value)) 126 + try {
110 - .thenApply(versionedValueTransform); 127 + return backingMap.put(keyEncoder.apply(key), valueEncoder.apply(value))
128 + .thenApply(versionedValueTransform);
129 + } catch (Exception e) {
130 + return Tools.exceptionalFuture(e);
131 + }
111 } 132 }
112 133
113 @Override 134 @Override
114 public CompletableFuture<Versioned<V1>> putAndGet(K1 key, V1 value) { 135 public CompletableFuture<Versioned<V1>> putAndGet(K1 key, V1 value) {
115 - return backingMap.putAndGet(keyEncoder.apply(key), valueEncoder.apply(value)) 136 + try {
116 - .thenApply(versionedValueTransform); 137 + return backingMap.putAndGet(keyEncoder.apply(key), valueEncoder.apply(value))
138 + .thenApply(versionedValueTransform);
139 + } catch (Exception e) {
140 + return Tools.exceptionalFuture(e);
141 + }
117 } 142 }
118 143
119 @Override 144 @Override
120 public CompletableFuture<Versioned<V1>> remove(K1 key) { 145 public CompletableFuture<Versioned<V1>> remove(K1 key) {
121 - return backingMap.remove(keyEncoder.apply(key)).thenApply(versionedValueTransform); 146 + try {
147 + return backingMap.remove(keyEncoder.apply(key)).thenApply(versionedValueTransform);
148 + } catch (Exception e) {
149 + return Tools.exceptionalFuture(e);
150 + }
122 } 151 }
123 152
124 @Override 153 @Override
...@@ -149,34 +178,60 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi ...@@ -149,34 +178,60 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi
149 178
150 @Override 179 @Override
151 public CompletableFuture<Versioned<V1>> putIfAbsent(K1 key, V1 value) { 180 public CompletableFuture<Versioned<V1>> putIfAbsent(K1 key, V1 value) {
152 - return backingMap.putIfAbsent(keyEncoder.apply(key), valueEncoder.apply(value)) 181 + try {
153 - .thenApply(versionedValueTransform); 182 + return backingMap.putIfAbsent(keyEncoder.apply(key), valueEncoder.apply(value))
183 + .thenApply(versionedValueTransform);
184 + } catch (Exception e) {
185 + return Tools.exceptionalFuture(e);
186 + }
154 } 187 }
155 188
156 @Override 189 @Override
157 public CompletableFuture<Boolean> remove(K1 key, V1 value) { 190 public CompletableFuture<Boolean> remove(K1 key, V1 value) {
158 - return backingMap.remove(keyEncoder.apply(key), valueEncoder.apply(value)); 191 + try {
192 + return backingMap.remove(keyEncoder.apply(key), valueEncoder.apply(value));
193 + } catch (Exception e) {
194 + return Tools.exceptionalFuture(e);
195 + }
159 } 196 }
160 197
161 @Override 198 @Override
162 public CompletableFuture<Boolean> remove(K1 key, long version) { 199 public CompletableFuture<Boolean> remove(K1 key, long version) {
163 - return backingMap.remove(keyEncoder.apply(key), version); 200 + try {
201 + return backingMap.remove(keyEncoder.apply(key), version);
202 + } catch (Exception e) {
203 + return Tools.exceptionalFuture(e);
204 + }
164 } 205 }
165 206
166 @Override 207 @Override
167 public CompletableFuture<Versioned<V1>> replace(K1 key, V1 value) { 208 public CompletableFuture<Versioned<V1>> replace(K1 key, V1 value) {
168 - return backingMap.replace(keyEncoder.apply(key), valueEncoder.apply(value)) 209 + try {
169 - .thenApply(versionedValueTransform); 210 + return backingMap.replace(keyEncoder.apply(key), valueEncoder.apply(value))
211 + .thenApply(versionedValueTransform);
212 + } catch (Exception e) {
213 + return Tools.exceptionalFuture(e);
214 + }
170 } 215 }
171 216
172 @Override 217 @Override
173 public CompletableFuture<Boolean> replace(K1 key, V1 oldValue, V1 newValue) { 218 public CompletableFuture<Boolean> replace(K1 key, V1 oldValue, V1 newValue) {
174 - return backingMap.replace(keyEncoder.apply(key), valueEncoder.apply(oldValue), valueEncoder.apply(newValue)); 219 + try {
220 + return backingMap.replace(keyEncoder.apply(key),
221 + valueEncoder.apply(oldValue),
222 + valueEncoder.apply(newValue));
223 + } catch (Exception e) {
224 + return Tools.exceptionalFuture(e);
225 + }
175 } 226 }
176 227
177 @Override 228 @Override
178 public CompletableFuture<Boolean> replace(K1 key, long oldVersion, V1 newValue) { 229 public CompletableFuture<Boolean> replace(K1 key, long oldVersion, V1 newValue) {
179 - return backingMap.replace(keyEncoder.apply(key), oldVersion, valueEncoder.apply(newValue)); 230 + try {
231 + return backingMap.replace(keyEncoder.apply(key), oldVersion, valueEncoder.apply(newValue));
232 + } catch (Exception e) {
233 + return Tools.exceptionalFuture(e);
234 + }
180 } 235 }
181 236
182 @Override 237 @Override
...@@ -200,7 +255,11 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi ...@@ -200,7 +255,11 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi
200 255
201 @Override 256 @Override
202 public CompletableFuture<Boolean> prepare(MapTransaction<K1, V1> transaction) { 257 public CompletableFuture<Boolean> prepare(MapTransaction<K1, V1> transaction) {
203 - return backingMap.prepare(transaction.map(keyEncoder, valueEncoder)); 258 + try {
259 + return backingMap.prepare(transaction.map(keyEncoder, valueEncoder));
260 + } catch (Exception e) {
261 + return Tools.exceptionalFuture(e);
262 + }
204 } 263 }
205 264
206 @Override 265 @Override
...@@ -215,7 +274,11 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi ...@@ -215,7 +274,11 @@ public class TranscodingAsyncConsistentMap<K1, V1, K2, V2> implements AsyncConsi
215 274
216 @Override 275 @Override
217 public CompletableFuture<Boolean> prepareAndCommit(MapTransaction<K1, V1> transaction) { 276 public CompletableFuture<Boolean> prepareAndCommit(MapTransaction<K1, V1> transaction) {
218 - return backingMap.prepareAndCommit(transaction.map(keyEncoder, valueEncoder)); 277 + try {
278 + return backingMap.prepareAndCommit(transaction.map(keyEncoder, valueEncoder));
279 + } catch (Exception e) {
280 + return Tools.exceptionalFuture(e);
281 + }
219 } 282 }
220 283
221 private class InternalBackingMapEventListener implements MapEventListener<K2, V2> { 284 private class InternalBackingMapEventListener implements MapEventListener<K2, V2> {
......