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