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