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