Use partitionId instead of clusterName in CopycatTransport
Change-Id: I8e7ab3863a36944ac9e48e187037fb43695ebde3
Showing
4 changed files
with
25 additions
and
20 deletions
... | @@ -17,6 +17,7 @@ package org.onosproject.store.primitives.impl; | ... | @@ -17,6 +17,7 @@ package org.onosproject.store.primitives.impl; |
17 | 17 | ||
18 | import static com.google.common.base.Preconditions.checkNotNull; | 18 | import static com.google.common.base.Preconditions.checkNotNull; |
19 | 19 | ||
20 | +import org.onosproject.cluster.PartitionId; | ||
20 | import org.onosproject.store.cluster.messaging.MessagingService; | 21 | import org.onosproject.store.cluster.messaging.MessagingService; |
21 | 22 | ||
22 | import io.atomix.catalyst.transport.Client; | 23 | import io.atomix.catalyst.transport.Client; |
... | @@ -48,25 +49,25 @@ public class CopycatTransport implements Transport { | ... | @@ -48,25 +49,25 @@ public class CopycatTransport implements Transport { |
48 | } | 49 | } |
49 | 50 | ||
50 | private final Mode mode; | 51 | private final Mode mode; |
51 | - private final String clusterName; | 52 | + private final PartitionId partitionId; |
52 | private final MessagingService messagingService; | 53 | private final MessagingService messagingService; |
53 | 54 | ||
54 | - public CopycatTransport(Mode mode, String clusterName, MessagingService messagingService) { | 55 | + public CopycatTransport(Mode mode, PartitionId partitionId, MessagingService messagingService) { |
55 | this.mode = checkNotNull(mode); | 56 | this.mode = checkNotNull(mode); |
56 | - this.clusterName = checkNotNull(clusterName); | 57 | + this.partitionId = checkNotNull(partitionId); |
57 | this.messagingService = checkNotNull(messagingService); | 58 | this.messagingService = checkNotNull(messagingService); |
58 | } | 59 | } |
59 | 60 | ||
60 | @Override | 61 | @Override |
61 | public Client client() { | 62 | public Client client() { |
62 | - return new CopycatTransportClient(clusterName, | 63 | + return new CopycatTransportClient(partitionId, |
63 | messagingService, | 64 | messagingService, |
64 | mode); | 65 | mode); |
65 | } | 66 | } |
66 | 67 | ||
67 | @Override | 68 | @Override |
68 | public Server server() { | 69 | public Server server() { |
69 | - return new CopycatTransportServer(clusterName, | 70 | + return new CopycatTransportServer(partitionId, |
70 | messagingService); | 71 | messagingService); |
71 | } | 72 | } |
72 | } | 73 | } | ... | ... |
... | @@ -19,7 +19,9 @@ import static com.google.common.base.Preconditions.checkNotNull; | ... | @@ -19,7 +19,9 @@ import static com.google.common.base.Preconditions.checkNotNull; |
19 | 19 | ||
20 | import java.util.Set; | 20 | import java.util.Set; |
21 | import java.util.concurrent.CompletableFuture; | 21 | import java.util.concurrent.CompletableFuture; |
22 | + | ||
22 | import org.apache.commons.lang.math.RandomUtils; | 23 | import org.apache.commons.lang.math.RandomUtils; |
24 | +import org.onosproject.cluster.PartitionId; | ||
23 | import org.onosproject.store.cluster.messaging.MessagingService; | 25 | import org.onosproject.store.cluster.messaging.MessagingService; |
24 | 26 | ||
25 | import com.google.common.collect.Sets; | 27 | import com.google.common.collect.Sets; |
... | @@ -34,13 +36,13 @@ import io.atomix.catalyst.util.concurrent.ThreadContext; | ... | @@ -34,13 +36,13 @@ import io.atomix.catalyst.util.concurrent.ThreadContext; |
34 | */ | 36 | */ |
35 | public class CopycatTransportClient implements Client { | 37 | public class CopycatTransportClient implements Client { |
36 | 38 | ||
37 | - private final String clusterName; | 39 | + private final PartitionId partitionId; |
38 | private final MessagingService messagingService; | 40 | private final MessagingService messagingService; |
39 | private final CopycatTransport.Mode mode; | 41 | private final CopycatTransport.Mode mode; |
40 | private final Set<CopycatTransportConnection> connections = Sets.newConcurrentHashSet(); | 42 | private final Set<CopycatTransportConnection> connections = Sets.newConcurrentHashSet(); |
41 | 43 | ||
42 | - CopycatTransportClient(String clusterName, MessagingService messagingService, CopycatTransport.Mode mode) { | 44 | + CopycatTransportClient(PartitionId partitionId, MessagingService messagingService, CopycatTransport.Mode mode) { |
43 | - this.clusterName = checkNotNull(clusterName); | 45 | + this.partitionId = checkNotNull(partitionId); |
44 | this.messagingService = checkNotNull(messagingService); | 46 | this.messagingService = checkNotNull(messagingService); |
45 | this.mode = checkNotNull(mode); | 47 | this.mode = checkNotNull(mode); |
46 | } | 48 | } |
... | @@ -51,7 +53,7 @@ public class CopycatTransportClient implements Client { | ... | @@ -51,7 +53,7 @@ public class CopycatTransportClient implements Client { |
51 | CopycatTransportConnection connection = new CopycatTransportConnection( | 53 | CopycatTransportConnection connection = new CopycatTransportConnection( |
52 | nextConnectionId(), | 54 | nextConnectionId(), |
53 | CopycatTransport.Mode.CLIENT, | 55 | CopycatTransport.Mode.CLIENT, |
54 | - clusterName, | 56 | + partitionId, |
55 | remoteAddress, | 57 | remoteAddress, |
56 | messagingService, | 58 | messagingService, |
57 | context); | 59 | context); | ... | ... |
... | @@ -32,6 +32,7 @@ import java.util.function.Consumer; | ... | @@ -32,6 +32,7 @@ import java.util.function.Consumer; |
32 | import org.apache.commons.io.IOUtils; | 32 | import org.apache.commons.io.IOUtils; |
33 | import org.onlab.packet.IpAddress; | 33 | import org.onlab.packet.IpAddress; |
34 | import org.onlab.util.Tools; | 34 | import org.onlab.util.Tools; |
35 | +import org.onosproject.cluster.PartitionId; | ||
35 | import org.onosproject.store.cluster.messaging.Endpoint; | 36 | import org.onosproject.store.cluster.messaging.Endpoint; |
36 | import org.onosproject.store.cluster.messaging.MessagingService; | 37 | import org.onosproject.store.cluster.messaging.MessagingService; |
37 | 38 | ||
... | @@ -77,7 +78,7 @@ public class CopycatTransportConnection implements Connection { | ... | @@ -77,7 +78,7 @@ public class CopycatTransportConnection implements Connection { |
77 | 78 | ||
78 | CopycatTransportConnection(long connectionId, | 79 | CopycatTransportConnection(long connectionId, |
79 | CopycatTransport.Mode mode, | 80 | CopycatTransport.Mode mode, |
80 | - String clusterName, | 81 | + PartitionId partitionId, |
81 | Address address, | 82 | Address address, |
82 | MessagingService messagingService, | 83 | MessagingService messagingService, |
83 | ThreadContext context) { | 84 | ThreadContext context) { |
... | @@ -86,11 +87,11 @@ public class CopycatTransportConnection implements Connection { | ... | @@ -86,11 +87,11 @@ public class CopycatTransportConnection implements Connection { |
86 | this.remoteAddress = checkNotNull(address); | 87 | this.remoteAddress = checkNotNull(address); |
87 | this.messagingService = checkNotNull(messagingService); | 88 | this.messagingService = checkNotNull(messagingService); |
88 | if (mode == CopycatTransport.Mode.CLIENT) { | 89 | if (mode == CopycatTransport.Mode.CLIENT) { |
89 | - this.outboundMessageSubject = String.format("onos-copycat-%s", clusterName); | 90 | + this.outboundMessageSubject = String.format("onos-copycat-%s", partitionId); |
90 | - this.inboundMessageSubject = String.format("onos-copycat-%s-%d", clusterName, connectionId); | 91 | + this.inboundMessageSubject = String.format("onos-copycat-%s-%d", partitionId, connectionId); |
91 | } else { | 92 | } else { |
92 | - this.outboundMessageSubject = String.format("onos-copycat-%s-%d", clusterName, connectionId); | 93 | + this.outboundMessageSubject = String.format("onos-copycat-%s-%d", partitionId, connectionId); |
93 | - this.inboundMessageSubject = String.format("onos-copycat-%s", clusterName); | 94 | + this.inboundMessageSubject = String.format("onos-copycat-%s", partitionId); |
94 | } | 95 | } |
95 | this.context = checkNotNull(context); | 96 | this.context = checkNotNull(context); |
96 | } | 97 | } | ... | ... |
... | @@ -29,6 +29,7 @@ import java.util.function.Consumer; | ... | @@ -29,6 +29,7 @@ import java.util.function.Consumer; |
29 | 29 | ||
30 | import org.apache.commons.io.IOUtils; | 30 | import org.apache.commons.io.IOUtils; |
31 | import org.onlab.util.Tools; | 31 | import org.onlab.util.Tools; |
32 | +import org.onosproject.cluster.PartitionId; | ||
32 | import org.onosproject.store.cluster.messaging.MessagingService; | 33 | import org.onosproject.store.cluster.messaging.MessagingService; |
33 | 34 | ||
34 | import com.google.common.collect.Maps; | 35 | import com.google.common.collect.Maps; |
... | @@ -46,15 +47,15 @@ public class CopycatTransportServer implements Server { | ... | @@ -46,15 +47,15 @@ public class CopycatTransportServer implements Server { |
46 | 47 | ||
47 | private final AtomicBoolean listening = new AtomicBoolean(false); | 48 | private final AtomicBoolean listening = new AtomicBoolean(false); |
48 | private CompletableFuture<Void> listenFuture = new CompletableFuture<>(); | 49 | private CompletableFuture<Void> listenFuture = new CompletableFuture<>(); |
49 | - private final String clusterName; | 50 | + private final PartitionId partitionId; |
50 | private final MessagingService messagingService; | 51 | private final MessagingService messagingService; |
51 | private final String messageSubject; | 52 | private final String messageSubject; |
52 | private final Map<Long, CopycatTransportConnection> connections = Maps.newConcurrentMap(); | 53 | private final Map<Long, CopycatTransportConnection> connections = Maps.newConcurrentMap(); |
53 | 54 | ||
54 | - CopycatTransportServer(String clusterName, MessagingService messagingService) { | 55 | + CopycatTransportServer(PartitionId partitionId, MessagingService messagingService) { |
55 | - this.clusterName = checkNotNull(clusterName); | 56 | + this.partitionId = checkNotNull(partitionId); |
56 | this.messagingService = checkNotNull(messagingService); | 57 | this.messagingService = checkNotNull(messagingService); |
57 | - this.messageSubject = String.format("onos-copycat-%s", clusterName); | 58 | + this.messageSubject = String.format("onos-copycat-%s", partitionId); |
58 | } | 59 | } |
59 | 60 | ||
60 | @Override | 61 | @Override |
... | @@ -78,7 +79,7 @@ public class CopycatTransportServer implements Server { | ... | @@ -78,7 +79,7 @@ public class CopycatTransportServer implements Server { |
78 | newConnection.set(true); | 79 | newConnection.set(true); |
79 | return new CopycatTransportConnection(connectionId, | 80 | return new CopycatTransportConnection(connectionId, |
80 | CopycatTransport.Mode.SERVER, | 81 | CopycatTransport.Mode.SERVER, |
81 | - clusterName, | 82 | + partitionId, |
82 | senderAddress, | 83 | senderAddress, |
83 | messagingService, | 84 | messagingService, |
84 | getOrCreateContext(context)); | 85 | getOrCreateContext(context)); |
... | @@ -114,6 +115,6 @@ public class CopycatTransportServer implements Server { | ... | @@ -114,6 +115,6 @@ public class CopycatTransportServer implements Server { |
114 | if (context != null) { | 115 | if (context != null) { |
115 | return context; | 116 | return context; |
116 | } | 117 | } |
117 | - return new SingleThreadContext("copycat-transport-server-" + clusterName, parentContext.serializer().clone()); | 118 | + return new SingleThreadContext("copycat-transport-server-" + partitionId, parentContext.serializer().clone()); |
118 | } | 119 | } |
119 | } | 120 | } | ... | ... |
-
Please register or login to post a comment