Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 1 | /* |
| 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 | */ |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 16 | package org.onlab.onos.store.cluster.messaging; |
| 17 | |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 18 | import java.io.IOException; |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 19 | import java.util.Set; |
| 20 | |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 21 | import org.onlab.onos.cluster.NodeId; |
| 22 | |
Madan Jampani | 24f9efb | 2014-10-24 18:56:23 -0700 | [diff] [blame] | 23 | import com.google.common.util.concurrent.ListenableFuture; |
| 24 | |
Yuta HIGUCHI | 6e50173 | 2014-10-12 12:00:27 -0700 | [diff] [blame] | 25 | // TODO: remove IOExceptions? |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 26 | /** |
| 27 | * Service for assisting communications between controller cluster nodes. |
| 28 | */ |
| 29 | public interface ClusterCommunicationService { |
| 30 | |
| 31 | /** |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 32 | * Broadcast a message to all controller nodes. |
tom | d33e640 | 2014-09-30 03:14:43 -0700 | [diff] [blame] | 33 | * |
| 34 | * @param message message to send |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 35 | * @return true if the message was sent successfully to all nodes; false otherwise. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 36 | * @throws IOException when I/O exception of some sort has occurred |
tom | d33e640 | 2014-09-30 03:14:43 -0700 | [diff] [blame] | 37 | */ |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 38 | boolean broadcast(ClusterMessage message) throws IOException; |
tom | d33e640 | 2014-09-30 03:14:43 -0700 | [diff] [blame] | 39 | |
| 40 | /** |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 41 | * Sends a message to the specified controller node. |
| 42 | * |
| 43 | * @param message message to send |
| 44 | * @param toNodeId node identifier |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 45 | * @return true if the message was sent successfully; false otherwise. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 46 | * @throws IOException when I/O exception of some sort has occurred |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 47 | */ |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 48 | 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 HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 54 | * @param nodeIds recipient node identifiers |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 55 | * @return true if the message was sent successfully to all nodes in the group; false otherwise. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 56 | * @throws IOException when I/O exception of some sort has occurred |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 57 | */ |
| 58 | boolean multicast(ClusterMessage message, Set<NodeId> nodeIds) throws IOException; |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 59 | |
| 60 | /** |
Madan Jampani | 4a9cb6d | 2014-10-17 10:48:50 -0700 | [diff] [blame] | 61 | * Sends a message synchronously. |
| 62 | * @param message message to send |
| 63 | * @param toNodeId recipient node identifier |
Madan Jampani | 24f9efb | 2014-10-24 18:56:23 -0700 | [diff] [blame] | 64 | * @return reply future. |
Yuta HIGUCHI | 5c94727 | 2014-11-03 21:39:21 -0800 | [diff] [blame] | 65 | * @throws IOException when I/O exception of some sort has occurred |
Madan Jampani | 4a9cb6d | 2014-10-17 10:48:50 -0700 | [diff] [blame] | 66 | */ |
Madan Jampani | 24f9efb | 2014-10-24 18:56:23 -0700 | [diff] [blame] | 67 | ListenableFuture<byte[]> sendAndReceive(ClusterMessage message, NodeId toNodeId) throws IOException; |
Madan Jampani | 4a9cb6d | 2014-10-17 10:48:50 -0700 | [diff] [blame] | 68 | |
| 69 | /** |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 70 | * Adds a new subscriber for the specified message subject. |
| 71 | * |
| 72 | * @param subject message subject |
| 73 | * @param subscriber message subscriber |
| 74 | */ |
Madan Jampani | 890bc35 | 2014-10-01 22:35:29 -0700 | [diff] [blame] | 75 | void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber); |
tom | 1d416c5 | 2014-09-29 20:55:24 -0700 | [diff] [blame] | 76 | } |