blob: 59970f343146ef4ebd8df89f85be058fcb385383 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.cluster.messaging;
tom1d416c52014-09-29 20:55:24 -070017
Madan Jampani2bfa94c2015-04-11 05:03:49 -070018import java.util.Set;
19import java.util.concurrent.CompletableFuture;
20import java.util.concurrent.ExecutorService;
21import java.util.function.Consumer;
22import java.util.function.Function;
23
Brian O'Connorabafb502014-12-02 22:26:20 -080024import org.onosproject.cluster.NodeId;
Madan Jampani890bc352014-10-01 22:35:29 -070025
Madan Jampani2bfa94c2015-04-11 05:03:49 -070026import com.google.common.util.concurrent.ListenableFuture;
Madan Jampani24f9efb2014-10-24 18:56:23 -070027
tom1d416c52014-09-29 20:55:24 -070028/**
29 * Service for assisting communications between controller cluster nodes.
30 */
31public interface ClusterCommunicationService {
32
33 /**
Madan Jampani890bc352014-10-01 22:35:29 -070034 * Broadcast a message to all controller nodes.
tomd33e6402014-09-30 03:14:43 -070035 *
36 * @param message message to send
Madan Jampani890bc352014-10-01 22:35:29 -070037 * @return true if the message was sent successfully to all nodes; false otherwise.
tomd33e6402014-09-30 03:14:43 -070038 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070039 @Deprecated
Jonathan Hart7d656f42015-01-27 14:07:23 -080040 boolean broadcast(ClusterMessage message);
tomd33e6402014-09-30 03:14:43 -070041
42 /**
Madan Jampanif5d263b2014-11-13 10:04:40 -080043 * 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 Jampanif5d263b2014-11-13 10:04:40 -080047 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070048 @Deprecated
Jonathan Hart7d656f42015-01-27 14:07:23 -080049 boolean broadcastIncludeSelf(ClusterMessage message);
Madan Jampanif5d263b2014-11-13 10:04:40 -080050
51 /**
tom1d416c52014-09-29 20:55:24 -070052 * Sends a message to the specified controller node.
53 *
54 * @param message message to send
55 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070056 * @return true if the message was sent successfully; false otherwise.
tom1d416c52014-09-29 20:55:24 -070057 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070058 @Deprecated
Brian O'Connor5eb77c82015-03-02 18:09:39 -080059 boolean unicast(ClusterMessage message, NodeId toNodeId);
Madan Jampani890bc352014-10-01 22:35:29 -070060
61 /**
62 * Multicast a message to a set of controller nodes.
63 *
64 * @param message message to send
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080065 * @param nodeIds recipient node identifiers
Madan Jampani890bc352014-10-01 22:35:29 -070066 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
67 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070068 @Deprecated
Brian O'Connor5eb77c82015-03-02 18:09:39 -080069 boolean multicast(ClusterMessage message, Iterable<NodeId> nodeIds);
tom1d416c52014-09-29 20:55:24 -070070
71 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070072 * Sends a message synchronously.
73 * @param message message to send
74 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070075 * @return reply future.
tom1d416c52014-09-29 20:55:24 -070076 */
Madan Jampani2af244a2015-02-22 13:12:01 -080077 @Deprecated
Madan Jampani2bfa94c2015-04-11 05:03:49 -070078 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId);
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080079
80 /**
Madan Jampani2af244a2015-02-22 13:12:01 -080081 * 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 Jampani2bfa94c2015-04-11 05:03:49 -070087 @Deprecated
Madan Jampani2af244a2015-02-22 13:12:01 -080088 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber, ExecutorService executor);
89
90 /**
Madan Jampani2bfa94c2015-04-11 05:03:49 -070091 * 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 HIGUCHI76b54bf2014-11-07 01:56:55 -0800193 * Removes a subscriber for the specified message subject.
194 *
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700195 * @param subject message subject
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -0800196 */
197 void removeSubscriber(MessageSubject subject);
tom1d416c52014-09-29 20:55:24 -0700198}