blob: c33d2ea7afee64d630f9fff8dffdf89ea969db8d [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;
Madan Jampani2af244a2015-02-22 13:12:01 -080019
Brian O'Connorabafb502014-12-02 22:26:20 -080020import org.onosproject.cluster.NodeId;
Madan Jampani890bc352014-10-01 22:35:29 -070021
Jonathan Hart7d656f42015-01-27 14:07:23 -080022import java.io.IOException;
23import java.util.Set;
Madan Jampani2af244a2015-02-22 13:12:01 -080024import java.util.concurrent.ExecutorService;
Madan Jampani24f9efb2014-10-24 18:56:23 -070025
Yuta HIGUCHI6e501732014-10-12 12:00:27 -070026// TODO: remove IOExceptions?
tom1d416c52014-09-29 20:55:24 -070027/**
28 * Service for assisting communications between controller cluster nodes.
29 */
30public interface ClusterCommunicationService {
31
32 /**
Madan Jampani890bc352014-10-01 22:35:29 -070033 * Broadcast a message to all controller nodes.
tomd33e6402014-09-30 03:14:43 -070034 *
35 * @param message message to send
Madan Jampani890bc352014-10-01 22:35:29 -070036 * @return true if the message was sent successfully to all nodes; false otherwise.
tomd33e6402014-09-30 03:14:43 -070037 */
Jonathan Hart7d656f42015-01-27 14:07:23 -080038 boolean broadcast(ClusterMessage message);
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.
Madan Jampanif5d263b2014-11-13 10:04:40 -080045 */
Jonathan Hart7d656f42015-01-27 14:07:23 -080046 boolean broadcastIncludeSelf(ClusterMessage message);
Madan Jampanif5d263b2014-11-13 10:04:40 -080047
48 /**
tom1d416c52014-09-29 20:55:24 -070049 * Sends a message to the specified controller node.
50 *
51 * @param message message to send
52 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070053 * @return true if the message was sent successfully; false otherwise.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080054 * @throws IOException when I/O exception of some sort has occurred
tom1d416c52014-09-29 20:55:24 -070055 */
Madan Jampani890bc352014-10-01 22:35:29 -070056 boolean unicast(ClusterMessage message, NodeId toNodeId) throws IOException;
57
58 /**
59 * Multicast a message to a set of controller nodes.
60 *
61 * @param message message to send
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080062 * @param nodeIds recipient node identifiers
Madan Jampani890bc352014-10-01 22:35:29 -070063 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
64 */
Jonathan Hart7d656f42015-01-27 14:07:23 -080065 boolean multicast(ClusterMessage message, Set<NodeId> nodeIds);
tom1d416c52014-09-29 20:55:24 -070066
67 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070068 * Sends a message synchronously.
69 * @param message message to send
70 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070071 * @return reply future.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080072 * @throws IOException when I/O exception of some sort has occurred
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070073 */
Madan Jampani24f9efb2014-10-24 18:56:23 -070074 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) throws IOException;
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070075
76 /**
tom1d416c52014-09-29 20:55:24 -070077 * Adds a new subscriber for the specified message subject.
78 *
79 * @param subject message subject
80 * @param subscriber message subscriber
81 */
Madan Jampani2af244a2015-02-22 13:12:01 -080082 @Deprecated
Madan Jampani890bc352014-10-01 22:35:29 -070083 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber);
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080084
85 /**
Madan Jampani2af244a2015-02-22 13:12:01 -080086 * Adds a new subscriber for the specified message subject.
87 *
88 * @param subject message subject
89 * @param subscriber message subscriber
90 * @param executor executor to use for running handler.
91 */
92 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber, ExecutorService executor);
93
94 /**
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080095 * Removes a subscriber for the specified message subject.
96 *
97 * @param subject message subject
98 */
99 void removeSubscriber(MessageSubject subject);
100
tom1d416c52014-09-29 20:55:24 -0700101}