blob: 2cff64ac4989d4936103213f06182986f786f1a3 [file] [log] [blame]
tom1d416c52014-09-29 20:55:24 -07001package org.onlab.onos.store.cluster.messaging;
2
Madan Jampani890bc352014-10-01 22:35:29 -07003import java.io.IOException;
tom1d416c52014-09-29 20:55:24 -07004import java.util.Set;
5
Madan Jampani890bc352014-10-01 22:35:29 -07006import org.onlab.onos.cluster.NodeId;
7
Madan Jampani24f9efb2014-10-24 18:56:23 -07008import com.google.common.util.concurrent.ListenableFuture;
9
Yuta HIGUCHI6e501732014-10-12 12:00:27 -070010// TODO: remove IOExceptions?
tom1d416c52014-09-29 20:55:24 -070011/**
12 * Service for assisting communications between controller cluster nodes.
13 */
14public interface ClusterCommunicationService {
15
16 /**
Madan Jampani890bc352014-10-01 22:35:29 -070017 * Broadcast a message to all controller nodes.
tomd33e6402014-09-30 03:14:43 -070018 *
19 * @param message message to send
Madan Jampani890bc352014-10-01 22:35:29 -070020 * @return true if the message was sent successfully to all nodes; false otherwise.
tomd33e6402014-09-30 03:14:43 -070021 */
Madan Jampani890bc352014-10-01 22:35:29 -070022 boolean broadcast(ClusterMessage message) throws IOException;
tomd33e6402014-09-30 03:14:43 -070023
24 /**
tom1d416c52014-09-29 20:55:24 -070025 * Sends a message to the specified controller node.
26 *
27 * @param message message to send
28 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070029 * @return true if the message was sent successfully; false otherwise.
tom1d416c52014-09-29 20:55:24 -070030 */
Madan Jampani890bc352014-10-01 22:35:29 -070031 boolean unicast(ClusterMessage message, NodeId toNodeId) throws IOException;
32
33 /**
34 * Multicast a message to a set of controller nodes.
35 *
36 * @param message message to send
37 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
38 */
39 boolean multicast(ClusterMessage message, Set<NodeId> nodeIds) throws IOException;
tom1d416c52014-09-29 20:55:24 -070040
41 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070042 * Sends a message synchronously.
43 * @param message message to send
44 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070045 * @return reply future.
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070046 * @throws IOException
47 */
Madan Jampani24f9efb2014-10-24 18:56:23 -070048 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) throws IOException;
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070049
50 /**
tom1d416c52014-09-29 20:55:24 -070051 * Adds a new subscriber for the specified message subject.
52 *
53 * @param subject message subject
54 * @param subscriber message subscriber
55 */
Madan Jampani890bc352014-10-01 22:35:29 -070056 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber);
tom1d416c52014-09-29 20:55:24 -070057}