blob: 4ed8477e485d86083c8810b05b03472849a90e20 [file] [log] [blame]
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07003 *
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'Connorabafb502014-12-02 22:26:20 -080016package org.onosproject.store.cluster.messaging;
tom1d416c52014-09-29 20:55:24 -070017
Madan Jampani2bfa94c2015-04-11 05:03:49 -070018import java.util.Set;
19import java.util.concurrent.CompletableFuture;
Madan Jampaniec5ae342015-04-13 15:43:10 -070020import java.util.concurrent.Executor;
Madan Jampani2bfa94c2015-04-11 05:03:49 -070021import java.util.concurrent.ExecutorService;
22import java.util.function.Consumer;
23import java.util.function.Function;
24
Brian O'Connorabafb502014-12-02 22:26:20 -080025import org.onosproject.cluster.NodeId;
Madan Jampani890bc352014-10-01 22:35:29 -070026
tom1d416c52014-09-29 20:55:24 -070027/**
28 * Service for assisting communications between controller cluster nodes.
29 */
30public interface ClusterCommunicationService {
31
32 /**
Madan Jampani2af244a2015-02-22 13:12:01 -080033 * Adds a new subscriber for the specified message subject.
34 *
35 * @param subject message subject
36 * @param subscriber message subscriber
37 * @param executor executor to use for running handler.
Sho SHIMIZUbe63b232015-06-30 10:57:58 -070038 * @deprecated in Cardinal Release
Madan Jampani2af244a2015-02-22 13:12:01 -080039 */
Madan Jampani2bfa94c2015-04-11 05:03:49 -070040 @Deprecated
Madan Jampani2af244a2015-02-22 13:12:01 -080041 void addSubscriber(MessageSubject subject, ClusterMessageHandler subscriber, ExecutorService executor);
42
43 /**
Madan Jampani2bfa94c2015-04-11 05:03:49 -070044 * Broadcasts a message to all controller nodes.
45 *
46 * @param message message to send
47 * @param subject message subject
48 * @param encoder function for encoding message to byte[]
49 * @param <M> message type
50 */
51 <M> void broadcast(M message,
52 MessageSubject subject,
53 Function<M, byte[]> encoder);
54
55 /**
56 * Broadcasts a message to all controller nodes including self.
57 *
58 * @param message message to send
59 * @param subject message subject
60 * @param encoder function for encoding message to byte[]
61 * @param <M> message type
62 */
63 <M> void broadcastIncludeSelf(M message,
64 MessageSubject subject,
65 Function<M, byte[]> encoder);
66
67 /**
68 * Sends a message to the specified controller node.
69 *
70 * @param message message to send
71 * @param subject message subject
72 * @param encoder function for encoding message to byte[]
73 * @param toNodeId destination node identifier
74 * @param <M> message type
Madan Jampani175e8fd2015-05-20 14:10:45 -070075 * @return future that is completed when the message is sent
Madan Jampani2bfa94c2015-04-11 05:03:49 -070076 */
Madan Jampani175e8fd2015-05-20 14:10:45 -070077 <M> CompletableFuture<Void> unicast(M message,
Madan Jampani2bfa94c2015-04-11 05:03:49 -070078 MessageSubject subject,
79 Function<M, byte[]> encoder,
80 NodeId toNodeId);
81
82 /**
83 * Multicasts a message to a set of controller nodes.
84 *
85 * @param message message to send
86 * @param subject message subject
87 * @param encoder function for encoding message to byte[]
88 * @param nodeIds recipient node identifiers
89 * @param <M> message type
90 */
91 <M> void multicast(M message,
92 MessageSubject subject,
93 Function<M, byte[]> encoder,
94 Set<NodeId> nodeIds);
95
96 /**
97 * Sends a message and expects a reply.
98 *
99 * @param message message to send
100 * @param subject message subject
101 * @param encoder function for encoding request to byte[]
102 * @param decoder function for decoding response from byte[]
103 * @param toNodeId recipient node identifier
104 * @param <M> request type
105 * @param <R> reply type
106 * @return reply future
107 */
108 <M, R> CompletableFuture<R> sendAndReceive(M message,
109 MessageSubject subject,
110 Function<M, byte[]> encoder,
111 Function<byte[], R> decoder,
112 NodeId toNodeId);
113
114 /**
115 * Adds a new subscriber for the specified message subject.
116 *
117 * @param subject message subject
118 * @param decoder decoder for resurrecting incoming message
Madan Jampani27b69c62015-05-15 15:49:02 -0700119 * @param handler handler function that processes the incoming message and produces a reply
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700120 * @param encoder encoder for serializing reply
121 * @param executor executor to run this handler on
122 * @param <M> incoming message type
123 * @param <R> reply message type
124 */
125 <M, R> void addSubscriber(MessageSubject subject,
126 Function<byte[], M> decoder,
127 Function<M, R> handler,
128 Function<R, byte[]> encoder,
Madan Jampaniec5ae342015-04-13 15:43:10 -0700129 Executor executor);
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700130
131 /**
132 * Adds a new subscriber for the specified message subject.
133 *
134 * @param subject message subject
Madan Jampani27b69c62015-05-15 15:49:02 -0700135 * @param decoder decoder for resurrecting incoming message
136 * @param handler handler function that processes the incoming message and produces a reply
137 * @param encoder encoder for serializing reply
138 * @param <M> incoming message type
139 * @param <R> reply message type
140 */
141 <M, R> void addSubscriber(MessageSubject subject,
142 Function<byte[], M> decoder,
143 Function<M, CompletableFuture<R>> handler,
144 Function<R, byte[]> encoder);
145
146 /**
147 * Adds a new subscriber for the specified message subject.
148 *
149 * @param subject message subject
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700150 * @param decoder decoder to resurrecting incoming message
151 * @param handler handler for handling message
152 * @param executor executor to run this handler on
153 * @param <M> incoming message type
154 */
155 <M> void addSubscriber(MessageSubject subject,
156 Function<byte[], M> decoder,
157 Consumer<M> handler,
Madan Jampaniec5ae342015-04-13 15:43:10 -0700158 Executor executor);
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700159
160 /**
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -0800161 * Removes a subscriber for the specified message subject.
162 *
Madan Jampani2bfa94c2015-04-11 05:03:49 -0700163 * @param subject message subject
Yuta HIGUCHI76b54bf2014-11-07 01:56:55 -0800164 */
165 void removeSubscriber(MessageSubject subject);
tom1d416c52014-09-29 20:55:24 -0700166}