Committed by
Gerrit Code Review
Removed deprecated ClusterCommunicationService APIs
MessagingService::sendAsync now returns a CompletableFuture<Void> in place of boolean Change-Id: I98134c4c0ea65b9c7e9ba705eebd1669067324ef
Showing
11 changed files
with
176 additions
and
290 deletions
| ... | @@ -24,61 +24,12 @@ import java.util.function.Function; | ... | @@ -24,61 +24,12 @@ import java.util.function.Function; |
| 24 | 24 | ||
| 25 | import org.onosproject.cluster.NodeId; | 25 | import org.onosproject.cluster.NodeId; |
| 26 | 26 | ||
| 27 | -import com.google.common.util.concurrent.ListenableFuture; | ||
| 28 | - | ||
| 29 | /** | 27 | /** |
| 30 | * Service for assisting communications between controller cluster nodes. | 28 | * Service for assisting communications between controller cluster nodes. |
| 31 | */ | 29 | */ |
| 32 | public interface ClusterCommunicationService { | 30 | public interface ClusterCommunicationService { |
| 33 | 31 | ||
| 34 | /** | 32 | /** |
| 35 | - * Broadcast a message to all controller nodes. | ||
| 36 | - * | ||
| 37 | - * @param message message to send | ||
| 38 | - * @return true if the message was sent successfully to all nodes; false otherwise. | ||
| 39 | - */ | ||
| 40 | - @Deprecated | ||
| 41 | - boolean broadcast(ClusterMessage message); | ||
| 42 | - | ||
| 43 | - /** | ||
| 44 | - * Broadcast a message to all controller nodes including self. | ||
| 45 | - * | ||
| 46 | - * @param message message to send | ||
| 47 | - * @return true if the message was sent successfully to all nodes; false otherwise. | ||
| 48 | - */ | ||
| 49 | - @Deprecated | ||
| 50 | - boolean broadcastIncludeSelf(ClusterMessage message); | ||
| 51 | - | ||
| 52 | - /** | ||
| 53 | - * Sends a message to the specified controller node. | ||
| 54 | - * | ||
| 55 | - * @param message message to send | ||
| 56 | - * @param toNodeId node identifier | ||
| 57 | - * @return true if the message was sent successfully; false otherwise. | ||
| 58 | - */ | ||
| 59 | - @Deprecated | ||
| 60 | - boolean unicast(ClusterMessage message, NodeId toNodeId); | ||
| 61 | - | ||
| 62 | - /** | ||
| 63 | - * Multicast a message to a set of controller nodes. | ||
| 64 | - * | ||
| 65 | - * @param message message to send | ||
| 66 | - * @param nodeIds recipient node identifiers | ||
| 67 | - * @return true if the message was sent successfully to all nodes in the group; false otherwise. | ||
| 68 | - */ | ||
| 69 | - @Deprecated | ||
| 70 | - boolean multicast(ClusterMessage message, Iterable<NodeId> nodeIds); | ||
| 71 | - | ||
| 72 | - /** | ||
| 73 | - * Sends a message synchronously. | ||
| 74 | - * @param message message to send | ||
| 75 | - * @param toNodeId recipient node identifier | ||
| 76 | - * @return reply future. | ||
| 77 | - */ | ||
| 78 | - @Deprecated | ||
| 79 | - ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId); | ||
| 80 | - | ||
| 81 | - /** | ||
| 82 | * Adds a new subscriber for the specified message subject. | 33 | * Adds a new subscriber for the specified message subject. |
| 83 | * | 34 | * |
| 84 | * @param subject message subject | 35 | * @param subject message subject |
| ... | @@ -120,9 +71,9 @@ public interface ClusterCommunicationService { | ... | @@ -120,9 +71,9 @@ public interface ClusterCommunicationService { |
| 120 | * @param encoder function for encoding message to byte[] | 71 | * @param encoder function for encoding message to byte[] |
| 121 | * @param toNodeId destination node identifier | 72 | * @param toNodeId destination node identifier |
| 122 | * @param <M> message type | 73 | * @param <M> message type |
| 123 | - * @return true if the message was sent successfully; false otherwise | 74 | + * @return future that is completed when the message is sent |
| 124 | */ | 75 | */ |
| 125 | - <M> boolean unicast(M message, | 76 | + <M> CompletableFuture<Void> unicast(M message, |
| 126 | MessageSubject subject, | 77 | MessageSubject subject, |
| 127 | Function<M, byte[]> encoder, | 78 | Function<M, byte[]> encoder, |
| 128 | NodeId toNodeId); | 79 | NodeId toNodeId); | ... | ... |
| ... | @@ -15,7 +15,6 @@ | ... | @@ -15,7 +15,6 @@ |
| 15 | */ | 15 | */ |
| 16 | package org.onosproject.store.cluster.messaging; | 16 | package org.onosproject.store.cluster.messaging; |
| 17 | 17 | ||
| 18 | -import java.io.IOException; | ||
| 19 | import java.util.concurrent.CompletableFuture; | 18 | import java.util.concurrent.CompletableFuture; |
| 20 | import java.util.concurrent.Executor; | 19 | import java.util.concurrent.Executor; |
| 21 | import java.util.function.Consumer; | 20 | import java.util.function.Consumer; |
| ... | @@ -32,9 +31,9 @@ public interface MessagingService { | ... | @@ -32,9 +31,9 @@ public interface MessagingService { |
| 32 | * @param ep end point to send the message to. | 31 | * @param ep end point to send the message to. |
| 33 | * @param type type of message. | 32 | * @param type type of message. |
| 34 | * @param payload message payload bytes. | 33 | * @param payload message payload bytes. |
| 35 | - * @throws IOException when I/O exception of some sort has occurred | 34 | + * @return future that is completed when the message is sent |
| 36 | */ | 35 | */ |
| 37 | - void sendAsync(Endpoint ep, String type, byte[] payload) throws IOException; | 36 | + CompletableFuture<Void> sendAsync(Endpoint ep, String type, byte[] payload); |
| 38 | 37 | ||
| 39 | /** | 38 | /** |
| 40 | * Sends a message synchronously and waits for a response. | 39 | * Sends a message synchronously and waits for a response. | ... | ... |
| ... | @@ -42,7 +42,6 @@ import org.onosproject.store.serializers.KryoNamespaces; | ... | @@ -42,7 +42,6 @@ import org.onosproject.store.serializers.KryoNamespaces; |
| 42 | import org.onosproject.store.serializers.KryoSerializer; | 42 | import org.onosproject.store.serializers.KryoSerializer; |
| 43 | import org.slf4j.Logger; | 43 | import org.slf4j.Logger; |
| 44 | 44 | ||
| 45 | -import java.io.IOException; | ||
| 46 | import java.util.Map; | 45 | import java.util.Map; |
| 47 | import java.util.Set; | 46 | import java.util.Set; |
| 48 | import java.util.concurrent.ExecutorService; | 47 | import java.util.concurrent.ExecutorService; |
| ... | @@ -237,11 +236,11 @@ public class DistributedClusterStore | ... | @@ -237,11 +236,11 @@ public class DistributedClusterStore |
| 237 | 236 | ||
| 238 | private void heartbeatToPeer(byte[] messagePayload, ControllerNode peer) { | 237 | private void heartbeatToPeer(byte[] messagePayload, ControllerNode peer) { |
| 239 | Endpoint remoteEp = new Endpoint(peer.ip(), peer.tcpPort()); | 238 | Endpoint remoteEp = new Endpoint(peer.ip(), peer.tcpPort()); |
| 240 | - try { | 239 | + messagingService.sendAsync(remoteEp, HEARTBEAT_MESSAGE, messagePayload).whenComplete((result, error) -> { |
| 241 | - messagingService.sendAsync(remoteEp, HEARTBEAT_MESSAGE, messagePayload); | 240 | + if (error != null) { |
| 242 | - } catch (IOException e) { | 241 | + log.trace("Sending heartbeat to {} failed", remoteEp, error); |
| 243 | - log.trace("Sending heartbeat to {} failed", remoteEp, e); | 242 | + } |
| 244 | - } | 243 | + }); |
| 245 | } | 244 | } |
| 246 | 245 | ||
| 247 | private class HeartbeatMessageHandler implements Consumer<byte[]> { | 246 | private class HeartbeatMessageHandler implements Consumer<byte[]> { | ... | ... |
| ... | @@ -35,10 +35,6 @@ import org.slf4j.Logger; | ... | @@ -35,10 +35,6 @@ import org.slf4j.Logger; |
| 35 | import org.slf4j.LoggerFactory; | 35 | import org.slf4j.LoggerFactory; |
| 36 | 36 | ||
| 37 | import com.google.common.base.Objects; | 37 | import com.google.common.base.Objects; |
| 38 | -import com.google.common.util.concurrent.ListenableFuture; | ||
| 39 | -import com.google.common.util.concurrent.SettableFuture; | ||
| 40 | - | ||
| 41 | -import java.io.IOException; | ||
| 42 | import java.util.Set; | 38 | import java.util.Set; |
| 43 | import java.util.concurrent.CompletableFuture; | 39 | import java.util.concurrent.CompletableFuture; |
| 44 | import java.util.concurrent.Executor; | 40 | import java.util.concurrent.Executor; |
| ... | @@ -62,8 +58,11 @@ public class ClusterCommunicationManager | ... | @@ -62,8 +58,11 @@ public class ClusterCommunicationManager |
| 62 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) | 58 | @Reference(cardinality = ReferenceCardinality.MANDATORY_UNARY) |
| 63 | protected MessagingService messagingService; | 59 | protected MessagingService messagingService; |
| 64 | 60 | ||
| 61 | + private NodeId localNodeId; | ||
| 62 | + | ||
| 65 | @Activate | 63 | @Activate |
| 66 | public void activate() { | 64 | public void activate() { |
| 65 | + localNodeId = clusterService.getLocalNode().id(); | ||
| 67 | log.info("Started"); | 66 | log.info("Started"); |
| 68 | } | 67 | } |
| 69 | 68 | ||
| ... | @@ -73,60 +72,6 @@ public class ClusterCommunicationManager | ... | @@ -73,60 +72,6 @@ public class ClusterCommunicationManager |
| 73 | } | 72 | } |
| 74 | 73 | ||
| 75 | @Override | 74 | @Override |
| 76 | - public boolean broadcast(ClusterMessage message) { | ||
| 77 | - boolean ok = true; | ||
| 78 | - final ControllerNode localNode = clusterService.getLocalNode(); | ||
| 79 | - byte[] payload = message.getBytes(); | ||
| 80 | - for (ControllerNode node : clusterService.getNodes()) { | ||
| 81 | - if (!node.equals(localNode)) { | ||
| 82 | - ok = unicastUnchecked(message.subject(), payload, node.id()) && ok; | ||
| 83 | - } | ||
| 84 | - } | ||
| 85 | - return ok; | ||
| 86 | - } | ||
| 87 | - | ||
| 88 | - @Override | ||
| 89 | - public boolean broadcastIncludeSelf(ClusterMessage message) { | ||
| 90 | - boolean ok = true; | ||
| 91 | - byte[] payload = message.getBytes(); | ||
| 92 | - for (ControllerNode node : clusterService.getNodes()) { | ||
| 93 | - ok = unicastUnchecked(message.subject(), payload, node.id()) && ok; | ||
| 94 | - } | ||
| 95 | - return ok; | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - @Override | ||
| 99 | - public boolean multicast(ClusterMessage message, Iterable<NodeId> nodes) { | ||
| 100 | - boolean ok = true; | ||
| 101 | - final ControllerNode localNode = clusterService.getLocalNode(); | ||
| 102 | - byte[] payload = message.getBytes(); | ||
| 103 | - for (NodeId nodeId : nodes) { | ||
| 104 | - if (!nodeId.equals(localNode.id())) { | ||
| 105 | - ok = unicastUnchecked(message.subject(), payload, nodeId) && ok; | ||
| 106 | - } | ||
| 107 | - } | ||
| 108 | - return ok; | ||
| 109 | - } | ||
| 110 | - | ||
| 111 | - @Override | ||
| 112 | - public boolean unicast(ClusterMessage message, NodeId toNodeId) { | ||
| 113 | - return unicastUnchecked(message.subject(), message.getBytes(), toNodeId); | ||
| 114 | - } | ||
| 115 | - | ||
| 116 | - @Override | ||
| 117 | - public ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) { | ||
| 118 | - SettableFuture<byte[]> response = SettableFuture.create(); | ||
| 119 | - sendAndReceive(message.subject(), message.getBytes(), toNodeId).whenComplete((r, e) -> { | ||
| 120 | - if (e == null) { | ||
| 121 | - response.set(r); | ||
| 122 | - } else { | ||
| 123 | - response.setException(e); | ||
| 124 | - } | ||
| 125 | - }); | ||
| 126 | - return response; | ||
| 127 | - } | ||
| 128 | - | ||
| 129 | - @Override | ||
| 130 | public <M> void broadcast(M message, | 75 | public <M> void broadcast(M message, |
| 131 | MessageSubject subject, | 76 | MessageSubject subject, |
| 132 | Function<M, byte[]> encoder) { | 77 | Function<M, byte[]> encoder) { |
| ... | @@ -154,15 +99,19 @@ public class ClusterCommunicationManager | ... | @@ -154,15 +99,19 @@ public class ClusterCommunicationManager |
| 154 | } | 99 | } |
| 155 | 100 | ||
| 156 | @Override | 101 | @Override |
| 157 | - public <M> boolean unicast(M message, | 102 | + public <M> CompletableFuture<Void> unicast(M message, |
| 158 | - MessageSubject subject, | 103 | + MessageSubject subject, |
| 159 | - Function<M, byte[]> encoder, | 104 | + Function<M, byte[]> encoder, |
| 160 | - NodeId toNodeId) { | 105 | + NodeId toNodeId) { |
| 161 | - byte[] payload = new ClusterMessage( | 106 | + try { |
| 162 | - clusterService.getLocalNode().id(), | 107 | + byte[] payload = new ClusterMessage( |
| 163 | - subject, | 108 | + localNodeId, |
| 164 | - encoder.apply(message)).getBytes(); | 109 | + subject, |
| 165 | - return unicastUnchecked(subject, payload, toNodeId); | 110 | + encoder.apply(message)).getBytes(); |
| 111 | + return doUnicast(subject, payload, toNodeId); | ||
| 112 | + } catch (Exception e) { | ||
| 113 | + return Tools.exceptionalFuture(e); | ||
| 114 | + } | ||
| 166 | } | 115 | } |
| 167 | 116 | ||
| 168 | @Override | 117 | @Override |
| ... | @@ -171,10 +120,10 @@ public class ClusterCommunicationManager | ... | @@ -171,10 +120,10 @@ public class ClusterCommunicationManager |
| 171 | Function<M, byte[]> encoder, | 120 | Function<M, byte[]> encoder, |
| 172 | Set<NodeId> nodes) { | 121 | Set<NodeId> nodes) { |
| 173 | byte[] payload = new ClusterMessage( | 122 | byte[] payload = new ClusterMessage( |
| 174 | - clusterService.getLocalNode().id(), | 123 | + localNodeId, |
| 175 | subject, | 124 | subject, |
| 176 | encoder.apply(message)).getBytes(); | 125 | encoder.apply(message)).getBytes(); |
| 177 | - nodes.forEach(nodeId -> unicastUnchecked(subject, payload, nodeId)); | 126 | + nodes.forEach(nodeId -> doUnicast(subject, payload, nodeId)); |
| 178 | } | 127 | } |
| 179 | 128 | ||
| 180 | @Override | 129 | @Override |
| ... | @@ -194,17 +143,11 @@ public class ClusterCommunicationManager | ... | @@ -194,17 +143,11 @@ public class ClusterCommunicationManager |
| 194 | } | 143 | } |
| 195 | } | 144 | } |
| 196 | 145 | ||
| 197 | - private boolean unicastUnchecked(MessageSubject subject, byte[] payload, NodeId toNodeId) { | 146 | + private CompletableFuture<Void> doUnicast(MessageSubject subject, byte[] payload, NodeId toNodeId) { |
| 198 | ControllerNode node = clusterService.getNode(toNodeId); | 147 | ControllerNode node = clusterService.getNode(toNodeId); |
| 199 | checkArgument(node != null, "Unknown nodeId: %s", toNodeId); | 148 | checkArgument(node != null, "Unknown nodeId: %s", toNodeId); |
| 200 | Endpoint nodeEp = new Endpoint(node.ip(), node.tcpPort()); | 149 | Endpoint nodeEp = new Endpoint(node.ip(), node.tcpPort()); |
| 201 | - try { | 150 | + return messagingService.sendAsync(nodeEp, subject.value(), payload); |
| 202 | - messagingService.sendAsync(nodeEp, subject.value(), payload); | ||
| 203 | - return true; | ||
| 204 | - } catch (IOException e) { | ||
| 205 | - log.debug("Failed to send cluster message to nodeId: " + toNodeId, e); | ||
| 206 | - return false; | ||
| 207 | - } | ||
| 208 | } | 151 | } |
| 209 | 152 | ||
| 210 | private CompletableFuture<byte[]> sendAndReceive(MessageSubject subject, byte[] payload, NodeId toNodeId) { | 153 | private CompletableFuture<byte[]> sendAndReceive(MessageSubject subject, byte[] payload, NodeId toNodeId) { | ... | ... |
| ... | @@ -66,27 +66,27 @@ public class EventuallyConsistentMapBuilderImpl<K, V> | ... | @@ -66,27 +66,27 @@ public class EventuallyConsistentMapBuilderImpl<K, V> |
| 66 | } | 66 | } |
| 67 | 67 | ||
| 68 | @Override | 68 | @Override |
| 69 | - public EventuallyConsistentMapBuilder withName(String name) { | 69 | + public EventuallyConsistentMapBuilder<K, V> withName(String name) { |
| 70 | this.name = checkNotNull(name); | 70 | this.name = checkNotNull(name); |
| 71 | return this; | 71 | return this; |
| 72 | } | 72 | } |
| 73 | 73 | ||
| 74 | @Override | 74 | @Override |
| 75 | - public EventuallyConsistentMapBuilder withSerializer( | 75 | + public EventuallyConsistentMapBuilder<K, V> withSerializer( |
| 76 | KryoNamespace.Builder serializerBuilder) { | 76 | KryoNamespace.Builder serializerBuilder) { |
| 77 | this.serializerBuilder = checkNotNull(serializerBuilder); | 77 | this.serializerBuilder = checkNotNull(serializerBuilder); |
| 78 | return this; | 78 | return this; |
| 79 | } | 79 | } |
| 80 | 80 | ||
| 81 | @Override | 81 | @Override |
| 82 | - public EventuallyConsistentMapBuilder withClockService( | 82 | + public EventuallyConsistentMapBuilder<K, V> withClockService( |
| 83 | ClockService<K, V> clockService) { | 83 | ClockService<K, V> clockService) { |
| 84 | this.clockService = checkNotNull(clockService); | 84 | this.clockService = checkNotNull(clockService); |
| 85 | return this; | 85 | return this; |
| 86 | } | 86 | } |
| 87 | 87 | ||
| 88 | @Override | 88 | @Override |
| 89 | - public EventuallyConsistentMapBuilder withEventExecutor(ExecutorService executor) { | 89 | + public EventuallyConsistentMapBuilder<K, V> withEventExecutor(ExecutorService executor) { |
| 90 | this.eventExecutor = checkNotNull(executor); | 90 | this.eventExecutor = checkNotNull(executor); |
| 91 | return this; | 91 | return this; |
| 92 | } | 92 | } |
| ... | @@ -99,13 +99,13 @@ public class EventuallyConsistentMapBuilderImpl<K, V> | ... | @@ -99,13 +99,13 @@ public class EventuallyConsistentMapBuilderImpl<K, V> |
| 99 | } | 99 | } |
| 100 | 100 | ||
| 101 | @Override | 101 | @Override |
| 102 | - public EventuallyConsistentMapBuilder withBackgroundExecutor(ScheduledExecutorService executor) { | 102 | + public EventuallyConsistentMapBuilder<K, V> withBackgroundExecutor(ScheduledExecutorService executor) { |
| 103 | this.backgroundExecutor = checkNotNull(executor); | 103 | this.backgroundExecutor = checkNotNull(executor); |
| 104 | return this; | 104 | return this; |
| 105 | } | 105 | } |
| 106 | 106 | ||
| 107 | @Override | 107 | @Override |
| 108 | - public EventuallyConsistentMapBuilder withPeerUpdateFunction( | 108 | + public EventuallyConsistentMapBuilder<K, V> withPeerUpdateFunction( |
| 109 | BiFunction<K, V, Collection<NodeId>> peerUpdateFunction) { | 109 | BiFunction<K, V, Collection<NodeId>> peerUpdateFunction) { |
| 110 | this.peerUpdateFunction = checkNotNull(peerUpdateFunction); | 110 | this.peerUpdateFunction = checkNotNull(peerUpdateFunction); |
| 111 | return this; | 111 | return this; | ... | ... |
| ... | @@ -509,12 +509,6 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -509,12 +509,6 @@ public class EventuallyConsistentMapImpl<K, V> |
| 509 | ); | 509 | ); |
| 510 | } | 510 | } |
| 511 | 511 | ||
| 512 | - private boolean unicastMessage(NodeId peer, MessageSubject subject, Object event) { | ||
| 513 | - return clusterCommunicator.unicast(event, subject, serializer::encode, peer); | ||
| 514 | - // Note: we had this flipped before... | ||
| 515 | -// communicationExecutor.execute(() -> clusterCommunicator.unicast(message, peer)); | ||
| 516 | - } | ||
| 517 | - | ||
| 518 | private boolean underHighLoad() { | 512 | private boolean underHighLoad() { |
| 519 | return counter.get(LOAD_WINDOW) > HIGH_LOAD_THRESHOLD; | 513 | return counter.get(LOAD_WINDOW) > HIGH_LOAD_THRESHOLD; |
| 520 | } | 514 | } |
| ... | @@ -556,10 +550,14 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -556,10 +550,14 @@ public class EventuallyConsistentMapImpl<K, V> |
| 556 | } | 550 | } |
| 557 | 551 | ||
| 558 | AntiEntropyAdvertisement<K> ad = createAdvertisement(); | 552 | AntiEntropyAdvertisement<K> ad = createAdvertisement(); |
| 553 | + NodeId destination = peer; | ||
| 554 | + clusterCommunicator.unicast(ad, antiEntropyAdvertisementSubject, serializer::encode, peer) | ||
| 555 | + .whenComplete((result, error) -> { | ||
| 556 | + if (error != null) { | ||
| 557 | + log.debug("Failed to send anti-entropy advertisement to {}", destination); | ||
| 558 | + } | ||
| 559 | + }); | ||
| 559 | 560 | ||
| 560 | - if (!unicastMessage(peer, antiEntropyAdvertisementSubject, ad)) { | ||
| 561 | - log.debug("Failed to send anti-entropy advertisement to {}", peer); | ||
| 562 | - } | ||
| 563 | } catch (Exception e) { | 561 | } catch (Exception e) { |
| 564 | // Catch all exceptions to avoid scheduled task being suppressed. | 562 | // Catch all exceptions to avoid scheduled task being suppressed. |
| 565 | log.error("Exception thrown while sending advertisement", e); | 563 | log.error("Exception thrown while sending advertisement", e); |
| ... | @@ -595,9 +593,14 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -595,9 +593,14 @@ public class EventuallyConsistentMapImpl<K, V> |
| 595 | // Send the advertisement back if this peer is out-of-sync | 593 | // Send the advertisement back if this peer is out-of-sync |
| 596 | final NodeId sender = ad.sender(); | 594 | final NodeId sender = ad.sender(); |
| 597 | AntiEntropyAdvertisement<K> myAd = createAdvertisement(); | 595 | AntiEntropyAdvertisement<K> myAd = createAdvertisement(); |
| 598 | - if (!unicastMessage(sender, antiEntropyAdvertisementSubject, myAd)) { | 596 | + |
| 599 | - log.debug("Failed to send reactive anti-entropy advertisement to {}", sender); | 597 | + clusterCommunicator.unicast(myAd, antiEntropyAdvertisementSubject, serializer::encode, sender) |
| 600 | - } | 598 | + .whenComplete((result, error) -> { |
| 599 | + if (error != null) { | ||
| 600 | + log.debug("Failed to send reactive " | ||
| 601 | + + "anti-entropy advertisement to {}", sender); | ||
| 602 | + } | ||
| 603 | + }); | ||
| 601 | break; | 604 | break; |
| 602 | } | 605 | } |
| 603 | } | 606 | } |
| ... | @@ -801,11 +804,15 @@ public class EventuallyConsistentMapImpl<K, V> | ... | @@ -801,11 +804,15 @@ public class EventuallyConsistentMapImpl<K, V> |
| 801 | ) | 804 | ) |
| 802 | ); | 805 | ); |
| 803 | communicationExecutor.submit(() -> { | 806 | communicationExecutor.submit(() -> { |
| 804 | - try { | 807 | + clusterCommunicator.unicast(Lists.newArrayList(map.values()), |
| 805 | - unicastMessage(peer, updateMessageSubject, Lists.newArrayList(map.values())); | 808 | + updateMessageSubject, |
| 806 | - } catch (Exception e) { | 809 | + serializer::encode, |
| 807 | - log.warn("broadcast error", e); | 810 | + peer) |
| 808 | - } | 811 | + .whenComplete((result, error) -> { |
| 812 | + if (error != null) { | ||
| 813 | + log.debug("Failed to send to {}", peer); | ||
| 814 | + } | ||
| 815 | + }); | ||
| 809 | }); | 816 | }); |
| 810 | } | 817 | } |
| 811 | } | 818 | } | ... | ... |
| ... | @@ -407,21 +407,22 @@ public class NewDistributedFlowRuleStore | ... | @@ -407,21 +407,22 @@ public class NewDistributedFlowRuleStore |
| 407 | log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}", | 407 | log.trace("Forwarding storeBatch to {}, which is the primary (master) for device {}", |
| 408 | master, deviceId); | 408 | master, deviceId); |
| 409 | 409 | ||
| 410 | - if (!clusterCommunicator.unicast(operation, | 410 | + clusterCommunicator.unicast(operation, |
| 411 | - APPLY_BATCH_FLOWS, | 411 | + APPLY_BATCH_FLOWS, |
| 412 | - SERIALIZER::encode, | 412 | + SERIALIZER::encode, |
| 413 | - master)) { | 413 | + master) |
| 414 | - log.warn("Failed to storeBatch: {} to {}", operation, master); | 414 | + .whenComplete((result, error) -> { |
| 415 | - | 415 | + log.warn("Failed to storeBatch: {} to {}", operation, master); |
| 416 | - Set<FlowRule> allFailures = operation.getOperations().stream() | 416 | + |
| 417 | - .map(op -> op.target()) | 417 | + Set<FlowRule> allFailures = operation.getOperations() |
| 418 | - .collect(Collectors.toSet()); | 418 | + .stream() |
| 419 | - | 419 | + .map(op -> op.target()) |
| 420 | - notifyDelegate(FlowRuleBatchEvent.completed( | 420 | + .collect(Collectors.toSet()); |
| 421 | - new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), | 421 | + |
| 422 | - new CompletedBatchOperation(false, allFailures, deviceId))); | 422 | + notifyDelegate(FlowRuleBatchEvent.completed( |
| 423 | - return; | 423 | + new FlowRuleBatchRequest(operation.id(), Collections.emptySet()), |
| 424 | - } | 424 | + new CompletedBatchOperation(false, allFailures, deviceId))); |
| 425 | + }); | ||
| 425 | } | 426 | } |
| 426 | 427 | ||
| 427 | private void storeBatchInternal(FlowRuleBatchOperation operation) { | 428 | private void storeBatchInternal(FlowRuleBatchOperation operation) { | ... | ... |
| ... | @@ -395,8 +395,7 @@ public class DistributedGroupStore | ... | @@ -395,8 +395,7 @@ public class DistributedGroupStore |
| 395 | } | 395 | } |
| 396 | 396 | ||
| 397 | // Check if group to be created by a remote instance | 397 | // Check if group to be created by a remote instance |
| 398 | - if (mastershipService.getLocalRole( | 398 | + if (mastershipService.getLocalRole(groupDesc.deviceId()) != MastershipRole.MASTER) { |
| 399 | - groupDesc.deviceId()) != MastershipRole.MASTER) { | ||
| 400 | log.debug("storeGroupDescription: Device {} local role is not MASTER", | 399 | log.debug("storeGroupDescription: Device {} local role is not MASTER", |
| 401 | groupDesc.deviceId()); | 400 | groupDesc.deviceId()); |
| 402 | if (mastershipService.getMasterFor(groupDesc.deviceId()) == null) { | 401 | if (mastershipService.getMasterFor(groupDesc.deviceId()) == null) { |
| ... | @@ -410,19 +409,22 @@ public class DistributedGroupStore | ... | @@ -410,19 +409,22 @@ public class DistributedGroupStore |
| 410 | createGroupAddRequestMsg(groupDesc.deviceId(), | 409 | createGroupAddRequestMsg(groupDesc.deviceId(), |
| 411 | groupDesc); | 410 | groupDesc); |
| 412 | 411 | ||
| 413 | - if (!clusterCommunicator.unicast(groupOp, | 412 | + clusterCommunicator.unicast(groupOp, |
| 414 | GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, | 413 | GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
| 415 | m -> kryoBuilder.build().serialize(m), | 414 | m -> kryoBuilder.build().serialize(m), |
| 416 | - mastershipService.getMasterFor(groupDesc.deviceId()))) { | 415 | + mastershipService.getMasterFor(groupDesc.deviceId())).whenComplete((result, error) -> { |
| 417 | - log.warn("Failed to send request to master: {} to {}", | 416 | + if (error != null) { |
| 418 | - groupOp, | 417 | + log.warn("Failed to send request to master: {} to {}", |
| 419 | - mastershipService.getMasterFor(groupDesc.deviceId())); | 418 | + groupOp, |
| 420 | - //TODO: Send Group operation failure event | 419 | + mastershipService.getMasterFor(groupDesc.deviceId())); |
| 421 | - return; | 420 | + //TODO: Send Group operation failure event |
| 422 | - } | 421 | + } else { |
| 423 | - log.debug("Sent Group operation request for device {} to remote MASTER {}", | 422 | + log.debug("Sent Group operation request for device {} " |
| 424 | - groupDesc.deviceId(), | 423 | + + "to remote MASTER {}", |
| 425 | - mastershipService.getMasterFor(groupDesc.deviceId())); | 424 | + groupDesc.deviceId(), |
| 425 | + mastershipService.getMasterFor(groupDesc.deviceId())); | ||
| 426 | + } | ||
| 427 | + }); | ||
| 426 | return; | 428 | return; |
| 427 | } | 429 | } |
| 428 | 430 | ||
| ... | @@ -512,15 +514,17 @@ public class DistributedGroupStore | ... | @@ -512,15 +514,17 @@ public class DistributedGroupStore |
| 512 | newBuckets, | 514 | newBuckets, |
| 513 | newAppCookie); | 515 | newAppCookie); |
| 514 | 516 | ||
| 515 | - if (!clusterCommunicator.unicast(groupOp, | 517 | + clusterCommunicator.unicast(groupOp, |
| 516 | - GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, | 518 | + GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
| 517 | - m -> kryoBuilder.build().serialize(m), | 519 | + m -> kryoBuilder.build().serialize(m), |
| 518 | - mastershipService.getMasterFor(deviceId))) { | 520 | + mastershipService.getMasterFor(deviceId)).whenComplete((result, error) -> { |
| 519 | - log.warn("Failed to send request to master: {} to {}", | 521 | + if (error != null) { |
| 520 | - groupOp, | 522 | + log.warn("Failed to send request to master: {} to {}", |
| 521 | - mastershipService.getMasterFor(deviceId)); | 523 | + groupOp, |
| 522 | - //TODO: Send Group operation failure event | 524 | + mastershipService.getMasterFor(deviceId), error); |
| 523 | - } | 525 | + } |
| 526 | + //TODO: Send Group operation failure event | ||
| 527 | + }); | ||
| 524 | return; | 528 | return; |
| 525 | } | 529 | } |
| 526 | log.debug("updateGroupDescription for device {} is getting handled locally", | 530 | log.debug("updateGroupDescription for device {} is getting handled locally", |
| ... | @@ -643,15 +647,17 @@ public class DistributedGroupStore | ... | @@ -643,15 +647,17 @@ public class DistributedGroupStore |
| 643 | createGroupDeleteRequestMsg(deviceId, | 647 | createGroupDeleteRequestMsg(deviceId, |
| 644 | appCookie); | 648 | appCookie); |
| 645 | 649 | ||
| 646 | - if (!clusterCommunicator.unicast(groupOp, | 650 | + clusterCommunicator.unicast(groupOp, |
| 647 | GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, | 651 | GroupStoreMessageSubjects.REMOTE_GROUP_OP_REQUEST, |
| 648 | m -> kryoBuilder.build().serialize(m), | 652 | m -> kryoBuilder.build().serialize(m), |
| 649 | - mastershipService.getMasterFor(deviceId))) { | 653 | + mastershipService.getMasterFor(deviceId)).whenComplete((result, error) -> { |
| 650 | - log.warn("Failed to send request to master: {} to {}", | 654 | + if (error != null) { |
| 651 | - groupOp, | 655 | + log.warn("Failed to send request to master: {} to {}", |
| 652 | - mastershipService.getMasterFor(deviceId)); | 656 | + groupOp, |
| 653 | - //TODO: Send Group operation failure event | 657 | + mastershipService.getMasterFor(deviceId), error); |
| 654 | - } | 658 | + } |
| 659 | + //TODO: Send Group operation failure event | ||
| 660 | + }); | ||
| 655 | return; | 661 | return; |
| 656 | } | 662 | } |
| 657 | log.debug("deleteGroupDescription in device {} is getting handled locally", | 663 | log.debug("deleteGroupDescription in device {} is getting handled locally", | ... | ... |
| ... | @@ -18,7 +18,6 @@ package org.onosproject.store.ecmap; | ... | @@ -18,7 +18,6 @@ package org.onosproject.store.ecmap; |
| 18 | import com.google.common.collect.ComparisonChain; | 18 | import com.google.common.collect.ComparisonChain; |
| 19 | import com.google.common.collect.ImmutableSet; | 19 | import com.google.common.collect.ImmutableSet; |
| 20 | import com.google.common.collect.Lists; | 20 | import com.google.common.collect.Lists; |
| 21 | -import com.google.common.util.concurrent.ListenableFuture; | ||
| 22 | import com.google.common.util.concurrent.MoreExecutors; | 21 | import com.google.common.util.concurrent.MoreExecutors; |
| 23 | 22 | ||
| 24 | import org.junit.After; | 23 | import org.junit.After; |
| ... | @@ -145,7 +144,7 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -145,7 +144,7 @@ public class EventuallyConsistentMapImplTest { |
| 145 | .register(KryoNamespaces.API) | 144 | .register(KryoNamespaces.API) |
| 146 | .register(TestTimestamp.class); | 145 | .register(TestTimestamp.class); |
| 147 | 146 | ||
| 148 | - ecMap = new EventuallyConsistentMapBuilderImpl<>( | 147 | + ecMap = new EventuallyConsistentMapBuilderImpl<String, String>( |
| 149 | clusterService, clusterCommunicator) | 148 | clusterService, clusterCommunicator) |
| 150 | .withName(MAP_NAME) | 149 | .withName(MAP_NAME) |
| 151 | .withSerializer(serializer) | 150 | .withSerializer(serializer) |
| ... | @@ -702,7 +701,7 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -702,7 +701,7 @@ public class EventuallyConsistentMapImplTest { |
| 702 | anyObject(MessageSubject.class), | 701 | anyObject(MessageSubject.class), |
| 703 | anyObject(Function.class), | 702 | anyObject(Function.class), |
| 704 | anyObject(NodeId.class))) | 703 | anyObject(NodeId.class))) |
| 705 | - .andReturn(true) | 704 | + .andReturn(CompletableFuture.completedFuture(null)) |
| 706 | .anyTimes(); | 705 | .anyTimes(); |
| 707 | replay(clusterCommunicator); | 706 | replay(clusterCommunicator); |
| 708 | } | 707 | } |
| ... | @@ -761,9 +760,9 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -761,9 +760,9 @@ public class EventuallyConsistentMapImplTest { |
| 761 | } | 760 | } |
| 762 | 761 | ||
| 763 | @Override | 762 | @Override |
| 764 | - public <M> boolean unicast(M message, MessageSubject subject, | 763 | + public <M> CompletableFuture<Void> unicast(M message, MessageSubject subject, |
| 765 | Function<M, byte[]> encoder, NodeId toNodeId) { | 764 | Function<M, byte[]> encoder, NodeId toNodeId) { |
| 766 | - return false; | 765 | + return null; |
| 767 | } | 766 | } |
| 768 | 767 | ||
| 769 | @Override | 768 | @Override |
| ... | @@ -795,33 +794,6 @@ public class EventuallyConsistentMapImplTest { | ... | @@ -795,33 +794,6 @@ public class EventuallyConsistentMapImplTest { |
| 795 | Function<byte[], M> decoder, Consumer<M> handler, | 794 | Function<byte[], M> decoder, Consumer<M> handler, |
| 796 | Executor executor) { | 795 | Executor executor) { |
| 797 | } | 796 | } |
| 798 | - | ||
| 799 | - @Override | ||
| 800 | - public boolean broadcast(ClusterMessage message) { | ||
| 801 | - return false; | ||
| 802 | - } | ||
| 803 | - | ||
| 804 | - @Override | ||
| 805 | - public boolean broadcastIncludeSelf(ClusterMessage message) { | ||
| 806 | - return false; | ||
| 807 | - } | ||
| 808 | - | ||
| 809 | - @Override | ||
| 810 | - public boolean unicast(ClusterMessage message, NodeId toNodeId) { | ||
| 811 | - return false; | ||
| 812 | - } | ||
| 813 | - | ||
| 814 | - @Override | ||
| 815 | - public boolean multicast(ClusterMessage message, | ||
| 816 | - Iterable<NodeId> nodeIds) { | ||
| 817 | - return false; | ||
| 818 | - } | ||
| 819 | - | ||
| 820 | - @Override | ||
| 821 | - public ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, | ||
| 822 | - NodeId toNodeId) { | ||
| 823 | - return null; | ||
| 824 | - } | ||
| 825 | } | 797 | } |
| 826 | 798 | ||
| 827 | /** | 799 | /** | ... | ... |
| ... | @@ -20,7 +20,6 @@ import io.netty.bootstrap.ServerBootstrap; | ... | @@ -20,7 +20,6 @@ import io.netty.bootstrap.ServerBootstrap; |
| 20 | import io.netty.buffer.PooledByteBufAllocator; | 20 | import io.netty.buffer.PooledByteBufAllocator; |
| 21 | import io.netty.channel.Channel; | 21 | import io.netty.channel.Channel; |
| 22 | import io.netty.channel.ChannelFuture; | 22 | import io.netty.channel.ChannelFuture; |
| 23 | -import io.netty.channel.ChannelFutureListener; | ||
| 24 | import io.netty.channel.ChannelHandler; | 23 | import io.netty.channel.ChannelHandler; |
| 25 | import io.netty.channel.ChannelHandlerContext; | 24 | import io.netty.channel.ChannelHandlerContext; |
| 26 | import io.netty.channel.ChannelInitializer; | 25 | import io.netty.channel.ChannelInitializer; |
| ... | @@ -136,32 +135,39 @@ public class NettyMessaging implements MessagingService { | ... | @@ -136,32 +135,39 @@ public class NettyMessaging implements MessagingService { |
| 136 | } | 135 | } |
| 137 | 136 | ||
| 138 | @Override | 137 | @Override |
| 139 | - public void sendAsync(Endpoint ep, String type, byte[] payload) throws IOException { | 138 | + public CompletableFuture<Void> sendAsync(Endpoint ep, String type, byte[] payload) { |
| 140 | InternalMessage message = new InternalMessage(messageIdGenerator.incrementAndGet(), | 139 | InternalMessage message = new InternalMessage(messageIdGenerator.incrementAndGet(), |
| 141 | localEp, | 140 | localEp, |
| 142 | type, | 141 | type, |
| 143 | payload); | 142 | payload); |
| 144 | - sendAsync(ep, message); | 143 | + return sendAsync(ep, message); |
| 145 | } | 144 | } |
| 146 | 145 | ||
| 147 | - protected void sendAsync(Endpoint ep, InternalMessage message) throws IOException { | 146 | + protected CompletableFuture<Void> sendAsync(Endpoint ep, InternalMessage message) { |
| 148 | - if (ep.equals(localEp)) { | 147 | + CompletableFuture<Void> future = new CompletableFuture<>(); |
| 149 | - dispatchLocally(message); | ||
| 150 | - return; | ||
| 151 | - } | ||
| 152 | - Channel channel = null; | ||
| 153 | try { | 148 | try { |
| 154 | - try { | 149 | + if (ep.equals(localEp)) { |
| 155 | - channel = channels.borrowObject(ep); | 150 | + dispatchLocally(message); |
| 156 | - channel.writeAndFlush(message).addListener(ChannelFutureListener.CLOSE_ON_FAILURE); | 151 | + future.complete(null); |
| 157 | - } finally { | 152 | + } else { |
| 158 | - channels.returnObject(ep, channel); | 153 | + Channel channel = null; |
| 154 | + try { | ||
| 155 | + channel = channels.borrowObject(ep); | ||
| 156 | + channel.writeAndFlush(message).addListener(channelFuture -> { | ||
| 157 | + if (!channelFuture.isSuccess()) { | ||
| 158 | + future.completeExceptionally(channelFuture.cause()); | ||
| 159 | + } else { | ||
| 160 | + future.complete(null); | ||
| 161 | + } | ||
| 162 | + }); | ||
| 163 | + } finally { | ||
| 164 | + channels.returnObject(ep, channel); | ||
| 165 | + } | ||
| 159 | } | 166 | } |
| 160 | - } catch (IOException e) { | ||
| 161 | - throw e; | ||
| 162 | } catch (Exception e) { | 167 | } catch (Exception e) { |
| 163 | - throw new IOException(e); | 168 | + future.completeExceptionally(e); |
| 164 | } | 169 | } |
| 170 | + return future; | ||
| 165 | } | 171 | } |
| 166 | 172 | ||
| 167 | @Override | 173 | @Override |
| ... | @@ -193,11 +199,11 @@ public class NettyMessaging implements MessagingService { | ... | @@ -193,11 +199,11 @@ public class NettyMessaging implements MessagingService { |
| 193 | localEp, | 199 | localEp, |
| 194 | REPLY_MESSAGE_TYPE, | 200 | REPLY_MESSAGE_TYPE, |
| 195 | responsePayload); | 201 | responsePayload); |
| 196 | - try { | 202 | + sendAsync(message.sender(), response).whenComplete((result, error) -> { |
| 197 | - sendAsync(message.sender(), response); | 203 | + if (error != null) { |
| 198 | - } catch (IOException e) { | 204 | + log.debug("Failed to respond", error); |
| 199 | - log.debug("Failed to respond", e); | 205 | + } |
| 200 | - } | 206 | + }); |
| 201 | } | 207 | } |
| 202 | })); | 208 | })); |
| 203 | } | 209 | } |
| ... | @@ -206,17 +212,17 @@ public class NettyMessaging implements MessagingService { | ... | @@ -206,17 +212,17 @@ public class NettyMessaging implements MessagingService { |
| 206 | public void registerHandler(String type, Function<byte[], CompletableFuture<byte[]>> handler) { | 212 | public void registerHandler(String type, Function<byte[], CompletableFuture<byte[]>> handler) { |
| 207 | handlers.put(type, message -> { | 213 | handlers.put(type, message -> { |
| 208 | handler.apply(message.payload()).whenComplete((result, error) -> { | 214 | handler.apply(message.payload()).whenComplete((result, error) -> { |
| 209 | - if (error == null) { | 215 | + if (error == null) { |
| 210 | - InternalMessage response = new InternalMessage(message.id(), | 216 | + InternalMessage response = new InternalMessage(message.id(), |
| 211 | - localEp, | 217 | + localEp, |
| 212 | - REPLY_MESSAGE_TYPE, | 218 | + REPLY_MESSAGE_TYPE, |
| 213 | - result); | 219 | + result); |
| 214 | - try { | 220 | + sendAsync(message.sender(), response).whenComplete((r, e) -> { |
| 215 | - sendAsync(message.sender(), response); | 221 | + if (e != null) { |
| 216 | - } catch (IOException e) { | 222 | + log.debug("Failed to respond", e); |
| 217 | - log.debug("Failed to respond", e); | 223 | + } |
| 224 | + }); | ||
| 218 | } | 225 | } |
| 219 | - } | ||
| 220 | }); | 226 | }); |
| 221 | }); | 227 | }); |
| 222 | } | 228 | } | ... | ... |
| ... | @@ -138,29 +138,30 @@ public class IOLoopMessaging implements MessagingService { | ... | @@ -138,29 +138,30 @@ public class IOLoopMessaging implements MessagingService { |
| 138 | 138 | ||
| 139 | 139 | ||
| 140 | @Override | 140 | @Override |
| 141 | - public void sendAsync(Endpoint ep, String type, byte[] payload) throws IOException { | 141 | + public CompletableFuture<Void> sendAsync(Endpoint ep, String type, byte[] payload) { |
| 142 | DefaultMessage message = new DefaultMessage( | 142 | DefaultMessage message = new DefaultMessage( |
| 143 | messageIdGenerator.incrementAndGet(), | 143 | messageIdGenerator.incrementAndGet(), |
| 144 | localEp, | 144 | localEp, |
| 145 | type, | 145 | type, |
| 146 | payload); | 146 | payload); |
| 147 | - sendAsync(ep, message); | 147 | + return sendAsync(ep, message); |
| 148 | } | 148 | } |
| 149 | 149 | ||
| 150 | - protected void sendAsync(Endpoint ep, DefaultMessage message) throws IOException { | 150 | + protected CompletableFuture<Void> sendAsync(Endpoint ep, DefaultMessage message) { |
| 151 | + CompletableFuture<Void> future = new CompletableFuture<>(); | ||
| 151 | if (ep.equals(localEp)) { | 152 | if (ep.equals(localEp)) { |
| 152 | dispatchLocally(message); | 153 | dispatchLocally(message); |
| 153 | - return; | 154 | + future.complete(null); |
| 155 | + return future; | ||
| 154 | } | 156 | } |
| 155 | 157 | ||
| 156 | DefaultMessageStream stream = null; | 158 | DefaultMessageStream stream = null; |
| 157 | try { | 159 | try { |
| 158 | stream = streams.borrowObject(ep); | 160 | stream = streams.borrowObject(ep); |
| 159 | - } catch (Exception e) { | ||
| 160 | - throw new IOException(e); | ||
| 161 | - } | ||
| 162 | - try { | ||
| 163 | stream.write(message); | 161 | stream.write(message); |
| 162 | + future.complete(null); | ||
| 163 | + } catch (Exception e) { | ||
| 164 | + future.completeExceptionally(e); | ||
| 164 | } finally { | 165 | } finally { |
| 165 | try { | 166 | try { |
| 166 | streams.returnObject(ep, stream); | 167 | streams.returnObject(ep, stream); |
| ... | @@ -168,6 +169,7 @@ public class IOLoopMessaging implements MessagingService { | ... | @@ -168,6 +169,7 @@ public class IOLoopMessaging implements MessagingService { |
| 168 | log.warn("Failed to return stream to pool"); | 169 | log.warn("Failed to return stream to pool"); |
| 169 | } | 170 | } |
| 170 | } | 171 | } |
| 172 | + return future; | ||
| 171 | } | 173 | } |
| 172 | 174 | ||
| 173 | @Override | 175 | @Override |
| ... | @@ -202,30 +204,30 @@ public class IOLoopMessaging implements MessagingService { | ... | @@ -202,30 +204,30 @@ public class IOLoopMessaging implements MessagingService { |
| 202 | localEp, | 204 | localEp, |
| 203 | REPLY_MESSAGE_TYPE, | 205 | REPLY_MESSAGE_TYPE, |
| 204 | responsePayload); | 206 | responsePayload); |
| 205 | - try { | 207 | + sendAsync(message.sender(), response).whenComplete((result, error) -> { |
| 206 | - sendAsync(message.sender(), response); | 208 | + log.debug("Failed to respond", error); |
| 207 | - } catch (IOException e) { | 209 | + }); |
| 208 | - log.debug("Failed to respond", e); | ||
| 209 | - } | ||
| 210 | } | 210 | } |
| 211 | })); | 211 | })); |
| 212 | } | 212 | } |
| 213 | 213 | ||
| 214 | @Override | 214 | @Override |
| 215 | public void registerHandler(String type, Function<byte[], CompletableFuture<byte[]>> handler) { | 215 | public void registerHandler(String type, Function<byte[], CompletableFuture<byte[]>> handler) { |
| 216 | - handlers.put(type, message -> handler.apply(message.payload()).whenComplete((result, error) -> { | 216 | + handlers.put(type, message -> { |
| 217 | - if (error == null) { | 217 | + handler.apply(message.payload()).whenComplete((result, error) -> { |
| 218 | - DefaultMessage response = new DefaultMessage(message.id(), | 218 | + if (error == null) { |
| 219 | + DefaultMessage response = new DefaultMessage(message.id(), | ||
| 219 | localEp, | 220 | localEp, |
| 220 | REPLY_MESSAGE_TYPE, | 221 | REPLY_MESSAGE_TYPE, |
| 221 | result); | 222 | result); |
| 222 | - try { | 223 | + sendAsync(message.sender(), response).whenComplete((r, e) -> { |
| 223 | - sendAsync(message.sender(), response); | 224 | + if (e != null) { |
| 224 | - } catch (IOException e) { | 225 | + log.debug("Failed to respond", e); |
| 225 | - log.debug("Failed to respond", e); | 226 | + } |
| 227 | + }); | ||
| 226 | } | 228 | } |
| 227 | - } | 229 | + }); |
| 228 | - })); | 230 | + }); |
| 229 | } | 231 | } |
| 230 | 232 | ||
| 231 | @Override | 233 | @Override | ... | ... |
-
Please register or login to post a comment