blob: 2763effbad302729454266261a6961926f975a1c [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 */
tom1d416c52014-09-29 20:55:24 -070016package org.onlab.onos.store.cluster.messaging;
17
Madan Jampani890bc352014-10-01 22:35:29 -070018import java.io.IOException;
tom1d416c52014-09-29 20:55:24 -070019import java.util.Set;
20
Madan Jampani890bc352014-10-01 22:35:29 -070021import org.onlab.onos.cluster.NodeId;
22
Madan Jampani24f9efb2014-10-24 18:56:23 -070023import com.google.common.util.concurrent.ListenableFuture;
24
Yuta HIGUCHI6e501732014-10-12 12:00:27 -070025// TODO: remove IOExceptions?
tom1d416c52014-09-29 20:55:24 -070026/**
27 * Service for assisting communications between controller cluster nodes.
28 */
29public interface ClusterCommunicationService {
30
31 /**
Madan Jampani890bc352014-10-01 22:35:29 -070032 * Broadcast a message to all controller nodes.
tomd33e6402014-09-30 03:14:43 -070033 *
34 * @param message message to send
Madan Jampani890bc352014-10-01 22:35:29 -070035 * @return true if the message was sent successfully to all nodes; false otherwise.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080036 * @throws IOException when I/O exception of some sort has occurred
tomd33e6402014-09-30 03:14:43 -070037 */
Madan Jampani890bc352014-10-01 22:35:29 -070038 boolean broadcast(ClusterMessage message) throws IOException;
tomd33e6402014-09-30 03:14:43 -070039
40 /**
Madan Jampanif5d263b2014-11-13 10:04:40 -080041 * Broadcast a message to all controller nodes including self.
42 *
43 * @param message message to send
44 * @return true if the message was sent successfully to all nodes; false otherwise.
45 * @throws IOException when I/O exception of some sort has occurred
46 */
47 boolean broadcastIncludeSelf(ClusterMessage message) throws IOException;
48
49 /**
tom1d416c52014-09-29 20:55:24 -070050 * Sends a message to the specified controller node.
51 *
52 * @param message message to send
53 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070054 * @return true if the message was sent successfully; false otherwise.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080055 * @throws IOException when I/O exception of some sort has occurred
tom1d416c52014-09-29 20:55:24 -070056 */
Madan Jampani890bc352014-10-01 22:35:29 -070057 boolean unicast(ClusterMessage message, NodeId toNodeId) throws IOException;
58
59 /**
60 * Multicast a message to a set of controller nodes.
61 *
62 * @param message message to send
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080063 * @param nodeIds recipient node identifiers
Madan Jampani890bc352014-10-01 22:35:29 -070064 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080065 * @throws IOException when I/O exception of some sort has occurred
Madan Jampani890bc352014-10-01 22:35:29 -070066 */
67 boolean multicast(ClusterMessage message, Set<NodeId> nodeIds) throws IOException;
tom1d416c52014-09-29 20:55:24 -070068
69 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070070 * Sends a message synchronously.
71 * @param message message to send
72 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070073 * @return reply future.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080074 * @throws IOException when I/O exception of some sort has occurred
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070075 */
Madan Jampani24f9efb2014-10-24 18:56:23 -070076 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) throws IOException;
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070077
78 /**
tom1d416c52014-09-29 20:55:24 -070079 * Adds a new subscriber for the specified message subject.
80 *
81 * @param subject message subject
82 * @param subscriber message subscriber
83 */
Madan Jampani890bc352014-10-01 22:35:29 -070084 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber);
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080085
86 /**
87 * Removes a subscriber for the specified message subject.
88 *
89 * @param subject message subject
90 */
91 void removeSubscriber(MessageSubject subject);
92
tom1d416c52014-09-29 20:55:24 -070093}