use maven shade plugin version defined in root pom + Minor fixes to CopycatTransport based on review comments
Change-Id: Iac2bd2e7eca99208930eb319e2f3996fbf043f88
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportConnection.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportConnection.java
index 7b5d42a..58928b3 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportConnection.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportConnection.java
@@ -62,7 +62,7 @@
static final byte FAILURE = 0x04;
private final long connectionId;
- private CopycatTransport.Mode mode;
+ private final CopycatTransport.Mode mode;
private final Address remoteAddress;
private final MessagingService messagingService;
private final String outboundMessageSubject;
@@ -73,6 +73,7 @@
private final AtomicInteger sendFailures = new AtomicInteger(0);
private final AtomicInteger messagesReceived = new AtomicInteger(0);
private final AtomicInteger receiveFailures = new AtomicInteger(0);
+ private final Map<Address, Endpoint> endpointLookupCache = Maps.newConcurrentMap();
CopycatTransportConnection(long connectionId,
CopycatTransport.Mode mode,
@@ -206,7 +207,6 @@
@Override
public CompletableFuture<Void> close() {
- // TODO: need to unregister message handler
closeListeners.forEach(listener -> listener.accept(this));
if (mode == CopycatTransport.Mode.CLIENT) {
messagingService.unregisterHandler(inboundMessageSubject);
@@ -240,12 +240,14 @@
}
private Endpoint toEndpoint(Address address) {
- try {
- return new Endpoint(IpAddress.valueOf(InetAddress.getByName(address.host())), address.port());
- } catch (UnknownHostException e) {
- Throwables.propagate(e);
- return null;
- }
+ return endpointLookupCache.computeIfAbsent(address, a -> {
+ try {
+ return new Endpoint(IpAddress.valueOf(InetAddress.getByName(a.host())), a.port());
+ } catch (UnknownHostException e) {
+ Throwables.propagate(e);
+ return null;
+ }
+ });
}
@SuppressWarnings("rawtypes")
diff --git a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportServer.java b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportServer.java
index 43c2cfc..7dfc59b 100644
--- a/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportServer.java
+++ b/core/store/primitives/src/main/java/org/onosproject/store/primitives/impl/CopycatTransportServer.java
@@ -45,7 +45,7 @@
public class CopycatTransportServer implements Server {
private final AtomicBoolean listening = new AtomicBoolean(false);
- private CompletableFuture<Void> listenFuture;
+ private CompletableFuture<Void> listenFuture = new CompletableFuture<>();
private final String clusterName;
private final MessagingService messagingService;
private final String messageSubject;
@@ -59,20 +59,14 @@
@Override
public CompletableFuture<Void> listen(Address address, Consumer<Connection> listener) {
- if (listening.get()) {
- return CompletableFuture.completedFuture(null);
- }
- ThreadContext context = ThreadContext.currentContextOrThrow();
- synchronized (this) {
- if (listenFuture == null) {
- listenFuture = new CompletableFuture<>();
- listen(address, listener, context);
- }
+ if (listening.compareAndSet(false, true)) {
+ ThreadContext context = ThreadContext.currentContextOrThrow();
+ listen(address, listener, context);
}
return listenFuture;
}
- public void listen(Address address, Consumer<Connection> listener, ThreadContext context) {
+ private void listen(Address address, Consumer<Connection> listener, ThreadContext context) {
messagingService.registerHandler(messageSubject, (sender, payload) -> {
try (DataInputStream input = new DataInputStream(new ByteArrayInputStream(payload))) {
long connectionId = input.readLong();
@@ -101,7 +95,6 @@
return Tools.exceptionalFuture(e);
}
});
- listening.set(true);
context.execute(() -> {
listenFuture.complete(null);
});
diff --git a/utils/thirdparty/pom.xml b/utils/thirdparty/pom.xml
index d2ec8f0..58b5e20 100644
--- a/utils/thirdparty/pom.xml
+++ b/utils/thirdparty/pom.xml
@@ -69,7 +69,6 @@
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
- <version>2.4.1</version>
<configuration>
<createSourcesJar>true</createSourcesJar>