Madan Jampani | 3289fbf | 2016-01-13 14:14:27 -0800 | [diff] [blame^] | 1 | /* |
| 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 | package org.onosproject.store.primitives.impl; |
| 17 | |
| 18 | import static com.google.common.base.Preconditions.checkNotNull; |
| 19 | |
| 20 | import org.onosproject.store.cluster.messaging.MessagingService; |
| 21 | |
| 22 | import io.atomix.catalyst.transport.Client; |
| 23 | import io.atomix.catalyst.transport.Server; |
| 24 | import io.atomix.catalyst.transport.Transport; |
| 25 | |
| 26 | /** |
| 27 | * Custom {@link Transport transport} for Copycat interactions |
| 28 | * built on top of {@link MessagingService}. |
| 29 | * |
| 30 | * @see CopycatTransportServer |
| 31 | * @see CopycatTransportClient |
| 32 | */ |
| 33 | public class CopycatTransport implements Transport { |
| 34 | |
| 35 | /** |
| 36 | * Transport Mode. |
| 37 | */ |
| 38 | public enum Mode { |
| 39 | /** |
| 40 | * Signifies transport for client -> server interaction. |
| 41 | */ |
| 42 | CLIENT, |
| 43 | |
| 44 | /** |
| 45 | * Signified transport for server -> server interaction. |
| 46 | */ |
| 47 | SERVER |
| 48 | } |
| 49 | |
| 50 | private final Mode mode; |
| 51 | private final String clusterName; |
| 52 | private final MessagingService messagingService; |
| 53 | |
| 54 | public CopycatTransport(Mode mode, String clusterName, MessagingService messagingService) { |
| 55 | this.mode = checkNotNull(mode); |
| 56 | this.clusterName = checkNotNull(clusterName); |
| 57 | this.messagingService = checkNotNull(messagingService); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Client client() { |
| 62 | return new CopycatTransportClient(clusterName, |
| 63 | messagingService, |
| 64 | mode); |
| 65 | } |
| 66 | |
| 67 | @Override |
| 68 | public Server server() { |
| 69 | return new CopycatTransportServer(clusterName, |
| 70 | messagingService); |
| 71 | } |
| 72 | } |