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