blob: 4f8fd8efa5cae84c984577bb33bcf746af5d0f36 [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;
Madan Jampaniec5ae342015-04-13 15:43:10 -070020import java.util.concurrent.Executor;
Madan Jampani2bfa94c2015-04-11 05:03:49 -070021import java.util.concurrent.ExecutorService;
22import java.util.function.Consumer;
23import java.util.function.Function;
24
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.cluster.NodeId;
Madan Jampani890bc352014-10-01 22:35:29 -070026
Madan Jampani2bfa94c2015-04-11 05:03:49 -070027import com.google.common.util.concurrent.ListenableFuture;
Madan Jampani24f9efb2014-10-24 18:56:23 -070028
tom1d416c52014-09-29 20:55:24 -070029/**
30 * Service for assisting communications between controller cluster nodes.
31 */
32public interface ClusterCommunicationService {
33
34 /**
Madan Jampani890bc352014-10-01 22:35:29 -070035 * Broadcast a message to all controller nodes.
tomd33e6402014-09-30 03:14:43 -070036 *
37 * @param message message to send
Madan Jampani890bc352014-10-01 22:35:29 -070038 * @return true if the message was sent successfully to all nodes; false otherwise.
tomd33e6402014-09-30 03:14:43 -070039 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070040 @Deprecated
Jonathan Hart7d656f42015-01-27 14:07:23 -080041 boolean broadcast(ClusterMessage message);
tomd33e6402014-09-30 03:14:43 -070042
43 /**
Madan Jampanif5d263b2014-11-13 10:04:40 -080044 * 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 Jampanif5d263b2014-11-13 10:04:40 -080048 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070049 @Deprecated
Jonathan Hart7d656f42015-01-27 14:07:23 -080050 boolean broadcastIncludeSelf(ClusterMessage message);
Madan Jampanif5d263b2014-11-13 10:04:40 -080051
52 /**
tom1d416c52014-09-29 20:55:24 -070053 * Sends a message to the specified controller node.
54 *
55 * @param message message to send
56 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070057 * @return true if the message was sent successfully; false otherwise.
tom1d416c52014-09-29 20:55:24 -070058 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070059 @Deprecated
Brian O'Connor5eb77c82015-03-02 18:09:39 -080060 boolean unicast(ClusterMessage message, NodeId toNodeId);
Madan Jampani890bc352014-10-01 22:35:29 -070061
62 /**
63 * Multicast a message to a set of controller nodes.
64 *
65 * @param message message to send
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080066 * @param nodeIds recipient node identifiers
Madan Jampani890bc352014-10-01 22:35:29 -070067 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
68 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070069 @Deprecated
Brian O'Connor5eb77c82015-03-02 18:09:39 -080070 boolean multicast(ClusterMessage message, Iterable<NodeId> nodeIds);
tom1d416c52014-09-29 20:55:24 -070071
72 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070073 * Sends a message synchronously.
74 * @param message message to send
75 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070076 * @return reply future.
tom1d416c52014-09-29 20:55:24 -070077 */
Madan Jampani2af244a2015-02-22 13:12:01 -080078 @Deprecated
Madan Jampani2bfa94c2015-04-11 05:03:49 -070079 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId);
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080080
81 /**
Madan Jampani2af244a2015-02-22 13:12:01 -080082 * 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 Jampani2bfa94c2015-04-11 05:03:49 -070088 @Deprecated
Madan Jampani2af244a2015-02-22 13:12:01 -080089 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber, ExecutorService executor);
90
91 /**
Madan Jampani2bfa94c2015-04-11 05:03:49 -070092 * 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 Jampaniec5ae342015-04-13 15:43:10 -0700177 Executor executor);
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700178
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 Jampaniec5ae342015-04-13 15:43:10 -0700191 Executor executor);
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700192
193 /**
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -0800194 * Removes a subscriber for the specified message subject.
195 *
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700196 * @param subject message subject
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -0800197 */
198 void removeSubscriber(MessageSubject subject);
tom1d416c52014-09-29 20:55:24 -0700199}