Madan Jampani | 630e7ac | 2016-05-31 11:34:05 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2016-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 | */ |
| 16 | package org.onosproject.store.primitives.impl; |
| 17 | |
| 18 | import io.atomix.catalyst.concurrent.Listener; |
| 19 | import io.atomix.catalyst.concurrent.ThreadContext; |
| 20 | import io.atomix.catalyst.serializer.Serializer; |
| 21 | import io.atomix.catalyst.transport.Address; |
| 22 | import io.atomix.catalyst.transport.Transport; |
| 23 | import io.atomix.copycat.Command; |
| 24 | import io.atomix.copycat.Query; |
| 25 | import io.atomix.copycat.client.CopycatClient; |
| 26 | import io.atomix.copycat.session.Session; |
| 27 | |
| 28 | import java.util.Collection; |
| 29 | import java.util.concurrent.CompletableFuture; |
| 30 | import java.util.function.Consumer; |
| 31 | |
| 32 | /** |
| 33 | * {@code CopycatClient} that merely delegates control to |
| 34 | * another CopycatClient. |
| 35 | */ |
| 36 | public class DelegatingCopycatClient implements CopycatClient { |
| 37 | |
| 38 | protected final CopycatClient client; |
| 39 | |
| 40 | DelegatingCopycatClient(CopycatClient client) { |
| 41 | this.client = client; |
| 42 | } |
| 43 | |
| 44 | @Override |
| 45 | public State state() { |
| 46 | return client.state(); |
| 47 | } |
| 48 | |
| 49 | @Override |
| 50 | public Listener<State> onStateChange(Consumer<State> callback) { |
| 51 | return client.onStateChange(callback); |
| 52 | } |
| 53 | |
| 54 | @Override |
| 55 | public ThreadContext context() { |
| 56 | return client.context(); |
| 57 | } |
| 58 | |
| 59 | @Override |
| 60 | public Transport transport() { |
| 61 | return client.transport(); |
| 62 | } |
| 63 | |
| 64 | @Override |
| 65 | public Serializer serializer() { |
| 66 | return client.serializer(); |
| 67 | } |
| 68 | |
| 69 | @Override |
| 70 | public Session session() { |
| 71 | return client.session(); |
| 72 | } |
| 73 | |
| 74 | @Override |
| 75 | public <T> CompletableFuture<T> submit(Command<T> command) { |
| 76 | return client.submit(command); |
| 77 | } |
| 78 | |
| 79 | @Override |
| 80 | public <T> CompletableFuture<T> submit(Query<T> query) { |
| 81 | return client.submit(query); |
| 82 | } |
| 83 | |
| 84 | @Override |
| 85 | public Listener<Void> onEvent(String event, Runnable callback) { |
| 86 | return client.onEvent(event, callback); |
| 87 | } |
| 88 | |
| 89 | @Override |
| 90 | public <T> Listener<T> onEvent(String event, Consumer<T> callback) { |
| 91 | return client.onEvent(event, callback); |
| 92 | } |
| 93 | |
| 94 | @Override |
| 95 | public CompletableFuture<CopycatClient> connect(Collection<Address> members) { |
| 96 | return client.connect(members); |
| 97 | } |
| 98 | |
| 99 | @Override |
| 100 | public CompletableFuture<CopycatClient> recover() { |
| 101 | return client.recover(); |
| 102 | } |
| 103 | |
| 104 | @Override |
| 105 | public CompletableFuture<Void> close() { |
| 106 | return client.close(); |
| 107 | } |
| 108 | } |