blob: cbf2398b67bca207edb868dcb89c7942ccd9c3cf [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
Jonathan Hart7d656f42015-01-27 14:07:23 -080018import com.google.common.util.concurrent.ListenableFuture;
Brian O'Connorabafb502014-12-02 22:26:20 -080019import org.onosproject.cluster.NodeId;
Madan Jampani890bc352014-10-01 22:35:29 -070020
Jonathan Hart7d656f42015-01-27 14:07:23 -080021import java.io.IOException;
Madan Jampani2af244a2015-02-22 13:12:01 -080022import java.util.concurrent.ExecutorService;
Madan Jampani24f9efb2014-10-24 18:56:23 -070023
Yuta HIGUCHI6e501732014-10-12 12:00:27 -070024// TODO: remove IOExceptions?
tom1d416c52014-09-29 20:55:24 -070025/**
26 * Service for assisting communications between controller cluster nodes.
27 */
28public interface ClusterCommunicationService {
29
30 /**
Madan Jampani890bc352014-10-01 22:35:29 -070031 * Broadcast a message to all controller nodes.
tomd33e6402014-09-30 03:14:43 -070032 *
33 * @param message message to send
Madan Jampani890bc352014-10-01 22:35:29 -070034 * @return true if the message was sent successfully to all nodes; false otherwise.
tomd33e6402014-09-30 03:14:43 -070035 */
Jonathan Hart7d656f42015-01-27 14:07:23 -080036 boolean broadcast(ClusterMessage message);
tomd33e6402014-09-30 03:14:43 -070037
38 /**
Madan Jampanif5d263b2014-11-13 10:04:40 -080039 * Broadcast a message to all controller nodes including self.
40 *
41 * @param message message to send
42 * @return true if the message was sent successfully to all nodes; false otherwise.
Madan Jampanif5d263b2014-11-13 10:04:40 -080043 */
Jonathan Hart7d656f42015-01-27 14:07:23 -080044 boolean broadcastIncludeSelf(ClusterMessage message);
Madan Jampanif5d263b2014-11-13 10:04:40 -080045
46 /**
tom1d416c52014-09-29 20:55:24 -070047 * Sends a message to the specified controller node.
48 *
49 * @param message message to send
50 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070051 * @return true if the message was sent successfully; false otherwise.
tom1d416c52014-09-29 20:55:24 -070052 */
Brian O'Connor5eb77c82015-03-02 18:09:39 -080053 boolean unicast(ClusterMessage message, NodeId toNodeId);
Madan Jampani890bc352014-10-01 22:35:29 -070054
55 /**
56 * Multicast a message to a set of controller nodes.
57 *
58 * @param message message to send
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080059 * @param nodeIds recipient node identifiers
Madan Jampani890bc352014-10-01 22:35:29 -070060 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
61 */
Brian O'Connor5eb77c82015-03-02 18:09:39 -080062 boolean multicast(ClusterMessage message, Iterable<NodeId> nodeIds);
tom1d416c52014-09-29 20:55:24 -070063
64 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070065 * Sends a message synchronously.
66 * @param message message to send
67 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070068 * @return reply future.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080069 * @throws IOException when I/O exception of some sort has occurred
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070070 */
Madan Jampani24f9efb2014-10-24 18:56:23 -070071 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) throws IOException;
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070072
73 /**
tom1d416c52014-09-29 20:55:24 -070074 * Adds a new subscriber for the specified message subject.
75 *
76 * @param subject message subject
77 * @param subscriber message subscriber
78 */
Madan Jampani2af244a2015-02-22 13:12:01 -080079 @Deprecated
Madan Jampani890bc352014-10-01 22:35:29 -070080 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber);
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080081
82 /**
Madan Jampani2af244a2015-02-22 13:12:01 -080083 * Adds a new subscriber for the specified message subject.
84 *
85 * @param subject message subject
86 * @param subscriber message subscriber
87 * @param executor executor to use for running handler.
88 */
89 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber, ExecutorService executor);
90
91 /**
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080092 * Removes a subscriber for the specified message subject.
93 *
94 * @param subject message subject
95 */
96 void removeSubscriber(MessageSubject subject);
97
tom1d416c52014-09-29 20:55:24 -070098}