Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2014 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 | */ |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 16 | package org.onosproject.store.cluster.messaging; |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 17 | |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 18 | import java.util.Set; |
| 19 | import java.util.concurrent.CompletableFuture; |
| 20 | import java.util.concurrent.ExecutorService; |
| 21 | import java.util.function.Consumer; |
| 22 | import java.util.function.Function; |
| 23 | |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 24 | import org.onosproject.cluster.NodeId; |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 25 | |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 26 | import com.google.common.util.concurrent.ListenableFuture; |
Madan Jampani | 24f9efb | 2014-10-24 18:56:23 -0700 | [diff] [blame] | 27 | |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Service for assisting communications between controller cluster nodes. |
| 30 | */ |
| 31 | public interface ClusterCommunicationService { |
| 32 | |
| 33 | /** |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 34 | * Broadcast a message to all controller nodes. |
tom | d33e640 | 2014-09-30 03:14:43 -0700 | [diff] [blame] | 35 | * |
| 36 | * @param message message to send |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 37 | * @return true if the message was sent successfully to all nodes; false otherwise. |
tom | d33e640 | 2014-09-30 03:14:43 -0700 | [diff] [blame] | 38 | */ |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 39 | @Deprecated |
Jonathan Hart | 7d656f4 | 2015-01-27 14:07:23 -0800 | [diff] [blame] | 40 | boolean broadcast(ClusterMessage message); |
tom | d33e640 | 2014-09-30 03:14:43 -0700 | [diff] [blame] | 41 | |
| 42 | /** |
Madan Jampani | f5d263b | 2014-11-13 10:04:40 -0800 | [diff] [blame] | 43 | * Broadcast a message to all controller nodes including self. |
| 44 | * |
| 45 | * @param message message to send |
| 46 | * @return true if the message was sent successfully to all nodes; false otherwise. |
Madan Jampani | f5d263b | 2014-11-13 10:04:40 -0800 | [diff] [blame] | 47 | */ |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 48 | @Deprecated |
Jonathan Hart | 7d656f4 | 2015-01-27 14:07:23 -0800 | [diff] [blame] | 49 | boolean broadcastIncludeSelf(ClusterMessage message); |
Madan Jampani | f5d263b | 2014-11-13 10:04:40 -0800 | [diff] [blame] | 50 | |
| 51 | /** |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 52 | * Sends a message to the specified controller node. |
| 53 | * |
| 54 | * @param message message to send |
| 55 | * @param toNodeId node identifier |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 56 | * @return true if the message was sent successfully; false otherwise. |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 57 | */ |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 58 | @Deprecated |
Brian O'Connor | 5eb77c8 | 2015-03-02 18:09:39 -0800 | [diff] [blame] | 59 | boolean unicast(ClusterMessage message, NodeId toNodeId); |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 60 | |
| 61 | /** |
| 62 | * Multicast a message to a set of controller nodes. |
| 63 | * |
| 64 | * @param message message to send |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 65 | * @param nodeIds recipient node identifiers |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 66 | * @return true if the message was sent successfully to all nodes in the group; false otherwise. |
| 67 | */ |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 68 | @Deprecated |
Brian O'Connor | 5eb77c8 | 2015-03-02 18:09:39 -0800 | [diff] [blame] | 69 | boolean multicast(ClusterMessage message, Iterable<NodeId> nodeIds); |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 70 | |
| 71 | /** |
Madan Jampani | 4a9cb6d | 2014-10-17 10:48:50 -0700 | [diff] [blame] | 72 | * Sends a message synchronously. |
| 73 | * @param message message to send |
| 74 | * @param toNodeId recipient node identifier |
Madan Jampani | 24f9efb | 2014-10-24 18:56:23 -0700 | [diff] [blame] | 75 | * @return reply future. |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 76 | */ |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 77 | @Deprecated |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 78 | ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId); |
Yuta HIGUCHI | 76b54bf | 2014-11-07 01:56:55 -0800 | [diff] [blame] | 79 | |
| 80 | /** |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 81 | * Adds a new subscriber for the specified message subject. |
| 82 | * |
| 83 | * @param subject message subject |
| 84 | * @param subscriber message subscriber |
| 85 | * @param executor executor to use for running handler. |
| 86 | */ |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 87 | @Deprecated |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 88 | void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber, ExecutorService executor); |
| 89 | |
| 90 | /** |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 91 | * Broadcasts a message to all controller nodes. |
| 92 | * |
| 93 | * @param message message to send |
| 94 | * @param subject message subject |
| 95 | * @param encoder function for encoding message to byte[] |
| 96 | * @param <M> message type |
| 97 | */ |
| 98 | <M> void broadcast(M message, |
| 99 | MessageSubject subject, |
| 100 | Function<M, byte[]> encoder); |
| 101 | |
| 102 | /** |
| 103 | * Broadcasts a message to all controller nodes including self. |
| 104 | * |
| 105 | * @param message message to send |
| 106 | * @param subject message subject |
| 107 | * @param encoder function for encoding message to byte[] |
| 108 | * @param <M> message type |
| 109 | */ |
| 110 | <M> void broadcastIncludeSelf(M message, |
| 111 | MessageSubject subject, |
| 112 | Function<M, byte[]> encoder); |
| 113 | |
| 114 | /** |
| 115 | * Sends a message to the specified controller node. |
| 116 | * |
| 117 | * @param message message to send |
| 118 | * @param subject message subject |
| 119 | * @param encoder function for encoding message to byte[] |
| 120 | * @param toNodeId destination node identifier |
| 121 | * @param <M> message type |
| 122 | * @return true if the message was sent successfully; false otherwise |
| 123 | */ |
| 124 | <M> boolean unicast(M message, |
| 125 | MessageSubject subject, |
| 126 | Function<M, byte[]> encoder, |
| 127 | NodeId toNodeId); |
| 128 | |
| 129 | /** |
| 130 | * Multicasts a message to a set of controller nodes. |
| 131 | * |
| 132 | * @param message message to send |
| 133 | * @param subject message subject |
| 134 | * @param encoder function for encoding message to byte[] |
| 135 | * @param nodeIds recipient node identifiers |
| 136 | * @param <M> message type |
| 137 | */ |
| 138 | <M> void multicast(M message, |
| 139 | MessageSubject subject, |
| 140 | Function<M, byte[]> encoder, |
| 141 | Set<NodeId> nodeIds); |
| 142 | |
| 143 | /** |
| 144 | * Sends a message and expects a reply. |
| 145 | * |
| 146 | * @param message message to send |
| 147 | * @param subject message subject |
| 148 | * @param encoder function for encoding request to byte[] |
| 149 | * @param decoder function for decoding response from byte[] |
| 150 | * @param toNodeId recipient node identifier |
| 151 | * @param <M> request type |
| 152 | * @param <R> reply type |
| 153 | * @return reply future |
| 154 | */ |
| 155 | <M, R> CompletableFuture<R> sendAndReceive(M message, |
| 156 | MessageSubject subject, |
| 157 | Function<M, byte[]> encoder, |
| 158 | Function<byte[], R> decoder, |
| 159 | NodeId toNodeId); |
| 160 | |
| 161 | /** |
| 162 | * Adds a new subscriber for the specified message subject. |
| 163 | * |
| 164 | * @param subject message subject |
| 165 | * @param decoder decoder for resurrecting incoming message |
| 166 | * @param handler handler function that process the incoming message and produces a reply |
| 167 | * @param encoder encoder for serializing reply |
| 168 | * @param executor executor to run this handler on |
| 169 | * @param <M> incoming message type |
| 170 | * @param <R> reply message type |
| 171 | */ |
| 172 | <M, R> void addSubscriber(MessageSubject subject, |
| 173 | Function<byte[], M> decoder, |
| 174 | Function<M, R> handler, |
| 175 | Function<R, byte[]> encoder, |
| 176 | ExecutorService executor); |
| 177 | |
| 178 | /** |
| 179 | * Adds a new subscriber for the specified message subject. |
| 180 | * |
| 181 | * @param subject message subject |
| 182 | * @param decoder decoder to resurrecting incoming message |
| 183 | * @param handler handler for handling message |
| 184 | * @param executor executor to run this handler on |
| 185 | * @param <M> incoming message type |
| 186 | */ |
| 187 | <M> void addSubscriber(MessageSubject subject, |
| 188 | Function<byte[], M> decoder, |
| 189 | Consumer<M> handler, |
| 190 | ExecutorService executor); |
| 191 | |
| 192 | /** |
Yuta HIGUCHI | 76b54bf | 2014-11-07 01:56:55 -0800 | [diff] [blame] | 193 | * Removes a subscriber for the specified message subject. |
| 194 | * |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 195 | * @param subject message subject |
Yuta HIGUCHI | 76b54bf | 2014-11-07 01:56:55 -0800 | [diff] [blame] | 196 | */ |
| 197 | void removeSubscriber(MessageSubject subject); |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 198 | } |