Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 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.impl; |
| 18 | |
| 19 | import java.util.concurrent.CompletableFuture; |
| 20 | import java.util.function.BiFunction; |
| 21 | import java.util.function.Predicate; |
| 22 | |
| 23 | import org.onlab.util.Tools; |
| 24 | import org.onosproject.store.service.AsyncConsistentMap; |
| 25 | import org.onosproject.store.service.Versioned; |
| 26 | |
| 27 | /** |
| 28 | * An unmodifiable {@link AsyncConsistentMap}. |
| 29 | * <p> |
| 30 | * Any attempt to update the map through this instance will cause the |
| 31 | * operation to be completed with an {@link UnsupportedOperationException}. |
| 32 | * |
| 33 | * @param <K> key type |
| 34 | * @param <V> value type |
| 35 | */ |
| 36 | public class UnmodifiableAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMap<K, V> { |
| 37 | |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 38 | private static final String ERROR_MSG = "map updates are not allowed"; |
| 39 | |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 40 | public UnmodifiableAsyncConsistentMap(AsyncConsistentMap<K, V> backingMap) { |
| 41 | super(backingMap); |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public CompletableFuture<Versioned<V>> computeIf(K key, |
| 46 | Predicate<? super V> condition, |
| 47 | BiFunction<? super K, ? super V, ? extends V> remappingFunction) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 48 | return Tools.exceptionalFuture(new UnsupportedOperationException("")); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public CompletableFuture<Versioned<V>> put(K key, V value) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 53 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 54 | } |
| 55 | |
| 56 | @Override |
| 57 | public CompletableFuture<Versioned<V>> putAndGet(K key, V value) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 58 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | @Override |
| 62 | public CompletableFuture<Versioned<V>> remove(K key) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 63 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | @Override |
| 67 | public CompletableFuture<Void> clear() { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 68 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | @Override |
| 72 | public CompletableFuture<Versioned<V>> putIfAbsent(K key, V value) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 73 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 74 | } |
| 75 | |
| 76 | @Override |
| 77 | public CompletableFuture<Boolean> remove(K key, V value) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 78 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | @Override |
| 82 | public CompletableFuture<Boolean> remove(K key, long version) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 83 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 84 | } |
| 85 | |
| 86 | @Override |
| 87 | public CompletableFuture<Versioned<V>> replace(K key, V value) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 88 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | @Override |
| 92 | public CompletableFuture<Boolean> replace(K key, V oldValue, V newValue) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 93 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | @Override |
| 97 | public CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue) { |
Madan Jampani | 832686d | 2016-04-04 21:57:26 -0700 | [diff] [blame] | 98 | return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG)); |
Madan Jampani | 1007367 | 2016-01-21 19:13:59 -0800 | [diff] [blame] | 99 | } |
| 100 | } |