blob: cf17fbebda03a2c8a60cb276d38ec61b33663578 [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 /**
tom1d416c52014-09-29 20:55:24 -070041 * Sends a message to the specified controller node.
42 *
43 * @param message message to send
44 * @param toNodeId node identifier
Madan Jampani890bc352014-10-01 22:35:29 -070045 * @return true if the message was sent successfully; false otherwise.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080046 * @throws IOException when I/O exception of some sort has occurred
tom1d416c52014-09-29 20:55:24 -070047 */
Madan Jampani890bc352014-10-01 22:35:29 -070048 boolean unicast(ClusterMessage message, NodeId toNodeId) throws IOException;
49
50 /**
51 * Multicast a message to a set of controller nodes.
52 *
53 * @param message message to send
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080054 * @param nodeIds recipient node identifiers
Madan Jampani890bc352014-10-01 22:35:29 -070055 * @return true if the message was sent successfully to all nodes in the group; false otherwise.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080056 * @throws IOException when I/O exception of some sort has occurred
Madan Jampani890bc352014-10-01 22:35:29 -070057 */
58 boolean multicast(ClusterMessage message, Set<NodeId> nodeIds) throws IOException;
tom1d416c52014-09-29 20:55:24 -070059
60 /**
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070061 * Sends a message synchronously.
62 * @param message message to send
63 * @param toNodeId recipient node identifier
Madan Jampani24f9efb2014-10-24 18:56:23 -070064 * @return reply future.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080065 * @throws IOException when I/O exception of some sort has occurred
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070066 */
Madan Jampani24f9efb2014-10-24 18:56:23 -070067 ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) throws IOException;
Madan Jampani4a9cb6d2014-10-17 10:48:50 -070068
69 /**
tom1d416c52014-09-29 20:55:24 -070070 * Adds a new subscriber for the specified message subject.
71 *
72 * @param subject message subject
73 * @param subscriber message subscriber
74 */
Madan Jampani890bc352014-10-01 22:35:29 -070075 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber);
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -080076
77 /**
78 * Removes a subscriber for the specified message subject.
79 *
80 * @param subject message subject
81 */
82 void removeSubscriber(MessageSubject subject);
83
tom1d416c52014-09-29 20:55:24 -070084}