Jordan Halterman | 8d8da59 | 2017-08-28 14:45:19 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017-present Open Networking Foundation |
| 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 | package org.onosproject.store.primitives.impl; |
| 17 | |
| 18 | import java.util.Map; |
| 19 | import java.util.Objects; |
| 20 | import java.util.concurrent.CompletableFuture; |
| 21 | |
| 22 | import com.google.common.base.MoreObjects; |
| 23 | import org.onosproject.store.primitives.NodeUpdate; |
| 24 | import org.onosproject.store.primitives.TransactionId; |
| 25 | import org.onosproject.store.service.AsyncDocumentTree; |
| 26 | import org.onosproject.store.service.DocumentPath; |
| 27 | import org.onosproject.store.service.DocumentTreeListener; |
| 28 | import org.onosproject.store.service.TransactionLog; |
| 29 | import org.onosproject.store.service.Version; |
| 30 | import org.onosproject.store.service.Versioned; |
| 31 | |
| 32 | /** |
| 33 | * Document tree that delegates to an underlying instance. |
| 34 | */ |
| 35 | public class DelegatingAsyncDocumentTree<V> extends DelegatingDistributedPrimitive implements AsyncDocumentTree<V> { |
| 36 | private final AsyncDocumentTree<V> delegateTree; |
| 37 | |
| 38 | public DelegatingAsyncDocumentTree(AsyncDocumentTree<V> delegateTree) { |
| 39 | super(delegateTree); |
| 40 | this.delegateTree = delegateTree; |
| 41 | } |
| 42 | |
| 43 | @Override |
| 44 | public DocumentPath root() { |
| 45 | return delegateTree.root(); |
| 46 | } |
| 47 | |
| 48 | @Override |
| 49 | public CompletableFuture<Map<String, Versioned<V>>> getChildren(DocumentPath path) { |
| 50 | return delegateTree.getChildren(path); |
| 51 | } |
| 52 | |
| 53 | @Override |
| 54 | public CompletableFuture<Versioned<V>> get(DocumentPath path) { |
| 55 | return delegateTree.get(path); |
| 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public CompletableFuture<Versioned<V>> set(DocumentPath path, V value) { |
| 60 | return delegateTree.set(path, value); |
| 61 | } |
| 62 | |
| 63 | @Override |
| 64 | public CompletableFuture<Boolean> create(DocumentPath path, V value) { |
| 65 | return delegateTree.create(path, value); |
| 66 | } |
| 67 | |
| 68 | @Override |
| 69 | public CompletableFuture<Boolean> createRecursive(DocumentPath path, V value) { |
| 70 | return delegateTree.createRecursive(path, value); |
| 71 | } |
| 72 | |
| 73 | @Override |
| 74 | public CompletableFuture<Boolean> replace(DocumentPath path, V newValue, long version) { |
| 75 | return delegateTree.replace(path, newValue, version); |
| 76 | } |
| 77 | |
| 78 | @Override |
| 79 | public CompletableFuture<Boolean> replace(DocumentPath path, V newValue, V currentValue) { |
| 80 | return delegateTree.replace(path, newValue, currentValue); |
| 81 | } |
| 82 | |
| 83 | @Override |
| 84 | public CompletableFuture<Versioned<V>> removeNode(DocumentPath path) { |
| 85 | return delegateTree.removeNode(path); |
| 86 | } |
| 87 | |
| 88 | @Override |
| 89 | public CompletableFuture<Void> addListener(DocumentPath path, DocumentTreeListener<V> listener) { |
| 90 | return delegateTree.addListener(path, listener); |
| 91 | } |
| 92 | |
| 93 | @Override |
| 94 | public CompletableFuture<Void> removeListener(DocumentTreeListener<V> listener) { |
| 95 | return delegateTree.removeListener(listener); |
| 96 | } |
| 97 | |
| 98 | @Override |
| 99 | public CompletableFuture<Version> begin(TransactionId transactionId) { |
| 100 | return delegateTree.begin(transactionId); |
| 101 | } |
| 102 | |
| 103 | @Override |
| 104 | public CompletableFuture<Boolean> prepare(TransactionLog<NodeUpdate<V>> transactionLog) { |
| 105 | return delegateTree.prepare(transactionLog); |
| 106 | } |
| 107 | |
| 108 | @Override |
| 109 | public CompletableFuture<Boolean> prepareAndCommit(TransactionLog<NodeUpdate<V>> transactionLog) { |
| 110 | return delegateTree.prepareAndCommit(transactionLog); |
| 111 | } |
| 112 | |
| 113 | @Override |
| 114 | public CompletableFuture<Void> commit(TransactionId transactionId) { |
| 115 | return delegateTree.commit(transactionId); |
| 116 | } |
| 117 | |
| 118 | @Override |
| 119 | public CompletableFuture<Void> rollback(TransactionId transactionId) { |
| 120 | return delegateTree.rollback(transactionId); |
| 121 | } |
| 122 | |
| 123 | @Override |
| 124 | public String toString() { |
| 125 | return MoreObjects.toStringHelper(getClass()) |
| 126 | .add("delegateTree", delegateTree) |
| 127 | .toString(); |
| 128 | } |
| 129 | |
| 130 | @Override |
| 131 | public int hashCode() { |
| 132 | return Objects.hash(delegateTree); |
| 133 | } |
| 134 | |
| 135 | @Override |
| 136 | public boolean equals(Object other) { |
| 137 | if (other instanceof DelegatingAsyncDocumentTree) { |
| 138 | DelegatingAsyncDocumentTree<V> that = (DelegatingAsyncDocumentTree) other; |
| 139 | return this.delegateTree.equals(that.delegateTree); |
| 140 | } |
| 141 | return false; |
| 142 | } |
| 143 | } |