blob: cd2daff84313bf1d8902f021cda2302611de2a01 [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.
tomd33e6402014-09-30 03:14:43 -070036 */
Madan Jampani890bc352014-10-01 22:35:29 -070037 boolean broadcast(ClusterMessage message) throws IOException;
tomd33e6402014-09-30 03:14:43 -070038
39 /**
tom1d416c52014-09-29 20:55:24 -070040 * Sends a message to the specified controller node.
41 *
42 * @param message message to send
43 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070044 * @return true if the message was sent successfully; false otherwise.
tom1d416c52014-09-29 20:55:24 -070045 */
Madan Jampani890bc352014-10-01 22:35:29 -070046 boolean unicast(ClusterMessage message, NodeId toNodeId) throws IOException;
47
48 /**
49 * Multicast a message to a set of controller nodes.
50 *
51 * @param message message to send
52 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
53 */
54 boolean multicast(ClusterMessage message, Set<NodeId> nodeIds) throws IOException;
tom1d416c52014-09-29 20:55:24 -070055
56 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070057 * Sends a message synchronously.
58 * @param message message to send
59 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070060 * @return reply future.
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070061 * @throws IOException
62 */
Madan Jampani24f9efb2014-10-24 18:56:23 -070063 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) throws IOException;
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070064
65 /**
tom1d416c52014-09-29 20:55:24 -070066 * Adds a new subscriber for the specified message subject.
67 *
68 * @param subject message subject
69 * @param subscriber message subscriber
70 */
Madan Jampani890bc352014-10-01 22:35:29 -070071 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber);
tom1d416c52014-09-29 20:55:24 -070072}