blob: 6525f12196122ed1c0ef1524af7d17bf4a01244b [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
Madan Jampani832686d2016-04-04 21:57:26 -070038 private static final String ERROR_MSG = "map updates are not allowed";
39
Madan Jampani10073672016-01-21 19:13:59 -080040 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 Jampani832686d2016-04-04 21:57:26 -070048 return Tools.exceptionalFuture(new UnsupportedOperationException(""));
Madan Jampani10073672016-01-21 19:13:59 -080049 }
50
51 @Override
52 public CompletableFuture<Versioned<V>> put(K key, V value) {
Madan Jampani832686d2016-04-04 21:57:26 -070053 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080054 }
55
56 @Override
57 public CompletableFuture<Versioned<V>> putAndGet(K key, V value) {
Madan Jampani832686d2016-04-04 21:57:26 -070058 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080059 }
60
61 @Override
62 public CompletableFuture<Versioned<V>> remove(K key) {
Madan Jampani832686d2016-04-04 21:57:26 -070063 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080064 }
65
66 @Override
67 public CompletableFuture<Void> clear() {
Madan Jampani832686d2016-04-04 21:57:26 -070068 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080069 }
70
71 @Override
72 public CompletableFuture<Versioned<V>> putIfAbsent(K key, V value) {
Madan Jampani832686d2016-04-04 21:57:26 -070073 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080074 }
75
76 @Override
77 public CompletableFuture<Boolean> remove(K key, V value) {
Madan Jampani832686d2016-04-04 21:57:26 -070078 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080079 }
80
81 @Override
82 public CompletableFuture<Boolean> remove(K key, long version) {
Madan Jampani832686d2016-04-04 21:57:26 -070083 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080084 }
85
86 @Override
87 public CompletableFuture<Versioned<V>> replace(K key, V value) {
Madan Jampani832686d2016-04-04 21:57:26 -070088 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080089 }
90
91 @Override
92 public CompletableFuture<Boolean> replace(K key, V oldValue, V newValue) {
Madan Jampani832686d2016-04-04 21:57:26 -070093 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080094 }
95
96 @Override
97 public CompletableFuture<Boolean> replace(K key, long oldVersion, V newValue) {
Madan Jampani832686d2016-04-04 21:57:26 -070098 return Tools.exceptionalFuture(new UnsupportedOperationException(ERROR_MSG));
Madan Jampani10073672016-01-21 19:13:59 -080099 }
100}