blob: a2b308a481da560f9eccdc248f2a1d8129ec8277 [file] [log] [blame]
Jordan Halterman544d1d52017-04-19 23:45:12 -07001/*
2 * Copyright 2017-present 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 */
16package org.onosproject.store.primitives.impl;
17
18import java.util.Collection;
19import java.util.Map;
20import java.util.Set;
21import java.util.concurrent.CompletableFuture;
22import java.util.concurrent.Executor;
23
24import com.google.common.collect.Multiset;
25import org.onlab.util.Tools;
26import org.onosproject.store.service.AsyncConsistentMultimap;
27import org.onosproject.store.service.Versioned;
28
29/**
30 * {@link org.onosproject.store.service.AsyncConsistentMultimap} that executes asynchronous callbacks on a provided
31 * {@link Executor}.
32 */
33public class ExecutingAsyncConsistentMultimap<K, V>
34 extends ExecutingDistributedPrimitive implements AsyncConsistentMultimap<K, V> {
35 private final AsyncConsistentMultimap<K, V> delegateMap;
36 private final Executor executor;
37
38 public ExecutingAsyncConsistentMultimap(AsyncConsistentMultimap<K, V> delegateMap, Executor executor) {
39 super(delegateMap, executor);
40 this.delegateMap = delegateMap;
41 this.executor = executor;
42 }
43
44 @Override
45 public CompletableFuture<Integer> size() {
46 return Tools.asyncFuture(delegateMap.size(), executor);
47 }
48
49 @Override
50 public CompletableFuture<Boolean> isEmpty() {
51 return Tools.asyncFuture(delegateMap.isEmpty(), executor);
52 }
53
54 @Override
55 public CompletableFuture<Boolean> containsKey(K key) {
56 return Tools.asyncFuture(delegateMap.containsKey(key), executor);
57 }
58
59 @Override
60 public CompletableFuture<Boolean> containsValue(V value) {
61 return Tools.asyncFuture(delegateMap.containsValue(value), executor);
62 }
63
64 @Override
65 public CompletableFuture<Boolean> containsEntry(K key, V value) {
66 return Tools.asyncFuture(delegateMap.containsEntry(key, value), executor);
67 }
68
69 @Override
70 public CompletableFuture<Boolean> put(K key, V value) {
71 return Tools.asyncFuture(delegateMap.put(key, value), executor);
72 }
73
74 @Override
75 public CompletableFuture<Boolean> remove(K key, V value) {
76 return Tools.asyncFuture(delegateMap.remove(key, value), executor);
77 }
78
79 @Override
80 public CompletableFuture<Boolean> removeAll(K key, Collection<? extends V> values) {
81 return Tools.asyncFuture(delegateMap.removeAll(key, values), executor);
82 }
83
84 @Override
85 public CompletableFuture<Versioned<Collection<? extends V>>> removeAll(K key) {
86 return Tools.asyncFuture(delegateMap.removeAll(key), executor);
87 }
88
89 @Override
90 public CompletableFuture<Boolean> putAll(K key, Collection<? extends V> values) {
91 return Tools.asyncFuture(delegateMap.putAll(key, values), executor);
92 }
93
94 @Override
95 public CompletableFuture<Versioned<Collection<? extends V>>> replaceValues(K key, Collection<V> values) {
96 return Tools.asyncFuture(delegateMap.replaceValues(key, values), executor);
97 }
98
99 @Override
100 public CompletableFuture<Void> clear() {
101 return Tools.asyncFuture(delegateMap.clear(), executor);
102 }
103
104 @Override
105 public CompletableFuture<Versioned<Collection<? extends V>>> get(K key) {
106 return Tools.asyncFuture(delegateMap.get(key), executor);
107 }
108
109 @Override
110 public CompletableFuture<Set<K>> keySet() {
111 return Tools.asyncFuture(delegateMap.keySet(), executor);
112 }
113
114 @Override
115 public CompletableFuture<Multiset<K>> keys() {
116 return Tools.asyncFuture(delegateMap.keys(), executor);
117 }
118
119 @Override
120 public CompletableFuture<Multiset<V>> values() {
121 return Tools.asyncFuture(delegateMap.values(), executor);
122 }
123
124 @Override
125 public CompletableFuture<Collection<Map.Entry<K, V>>> entries() {
126 return Tools.asyncFuture(delegateMap.entries(), executor);
127 }
128
129 @Override
130 public CompletableFuture<Map<K, Collection<V>>> asMap() {
131 return Tools.asyncFuture(delegateMap.asMap(), executor);
132 }
133}