blob: 30efc369b788f778d6f444a63ca5f45a83cabc14 [file] [log] [blame]
Madan Jampani10073672016-01-21 19:13:59 -08001/*
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
17package org.onosproject.store.primitives.impl;
18
19import java.util.concurrent.CompletableFuture;
20import java.util.function.BiFunction;
21import java.util.function.Predicate;
22
23import org.onlab.util.Tools;
24import org.onosproject.store.service.AsyncConsistentMap;
25import 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 */
36public class UnmodifiableAsyncConsistentMap<K, V> extends DelegatingAsyncConsistentMap<K, V> {
37
38 public UnmodifiableAsyncConsistentMap(AsyncConsistentMap<K, V> backingMap) {
39 super(backingMap);
40 }
41
42 @Override
43 public CompletableFuture<Versioned<V>> computeIf(K key,
44 Predicate<? super V> condition,
45 BiFunction<? super K, ? super V, ? extends V> remappingFunction) {
46 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
47 }
48
49 @Override
50 public CompletableFuture<Versioned<V>> put(K key, V value) {
51 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
52 }
53
54 @Override
55 public CompletableFuture<Versioned<V>> putAndGet(K key, V value) {
56 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
57 }
58
59 @Override
60 public CompletableFuture<Versioned<V>> remove(K key) {
61 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
62 }
63
64 @Override
65 public CompletableFuture<Void> clear() {
66 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
67 }
68
69 @Override
70 public CompletableFuture<Versioned<V>> putIfAbsent(K key, V value) {
71 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
72 }
73
74 @Override
75 public CompletableFuture<Boolean> remove(K key, V value) {
76 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
77 }
78
79 @Override
80 public CompletableFuture<Boolean> remove(K key, long version) {
81 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
82 }
83
84 @Override
85 public CompletableFuture<Versioned<V>> replace(K key, V value) {
86 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
87 }
88
89 @Override
90 public CompletableFuture<Boolean> replace(K key, V oldValue, V newValue) {
91 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
92 }
93
94 @Override
95 public CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue) {
96 return Tools.exceptionalFuture(new UnsupportedOperationException("map updates are not allowed"));
97 }
98}