blob: ddec252ded73a16bd18cecf6045ab9bb828ed6f0 [file] [log] [blame]
Madan Jampani3289fbf2016-01-13 14:14:27 -08001/*
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 */
16package org.onosproject.store.primitives.impl;
17
18import static com.google.common.base.Preconditions.checkNotNull;
19
Madan Jampanif778c962016-01-31 22:56:38 -080020import org.onosproject.cluster.PartitionId;
Madan Jampani3289fbf2016-01-13 14:14:27 -080021import org.onosproject.store.cluster.messaging.MessagingService;
22
23import io.atomix.catalyst.transport.Client;
24import io.atomix.catalyst.transport.Server;
25import 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 */
34public class CopycatTransport implements Transport {
35
36 /**
37 * Transport Mode.
38 */
39 public enum Mode {
40 /**
HIGUCHI Yuta556cf1e2016-01-13 18:04:58 -080041 * Signifies transport for client {@literal ->} server interaction.
Madan Jampani3289fbf2016-01-13 14:14:27 -080042 */
43 CLIENT,
44
45 /**
HIGUCHI Yuta556cf1e2016-01-13 18:04:58 -080046 * Signified transport for server {@literal ->} server interaction.
Madan Jampani3289fbf2016-01-13 14:14:27 -080047 */
48 SERVER
49 }
50
51 private final Mode mode;
Madan Jampanif778c962016-01-31 22:56:38 -080052 private final PartitionId partitionId;
Madan Jampani3289fbf2016-01-13 14:14:27 -080053 private final MessagingService messagingService;
54
Madan Jampanif778c962016-01-31 22:56:38 -080055 public CopycatTransport(Mode mode, PartitionId partitionId, MessagingService messagingService) {
Madan Jampani3289fbf2016-01-13 14:14:27 -080056 this.mode = checkNotNull(mode);
Madan Jampanif778c962016-01-31 22:56:38 -080057 this.partitionId = checkNotNull(partitionId);
Madan Jampani3289fbf2016-01-13 14:14:27 -080058 this.messagingService = checkNotNull(messagingService);
59 }
60
61 @Override
62 public Client client() {
Madan Jampanif778c962016-01-31 22:56:38 -080063 return new CopycatTransportClient(partitionId,
Madan Jampani3289fbf2016-01-13 14:14:27 -080064 messagingService,
65 mode);
66 }
67
68 @Override
69 public Server server() {
Madan Jampanif778c962016-01-31 22:56:38 -080070 return new CopycatTransportServer(partitionId,
Madan Jampani3289fbf2016-01-13 14:14:27 -080071 messagingService);
72 }
73}