Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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 |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 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. |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
Madan Jampani | c26eede | 2015-04-16 11:42:16 -0700 | [diff] [blame] | 16 | package org.onosproject.store.cluster.messaging; |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 17 | |
Madan Jampani | 2bfa94c | 2015-04-11 05:03:49 -0700 | [diff] [blame] | 18 | import java.util.concurrent.CompletableFuture; |
Madan Jampani | ec5ae34 | 2015-04-13 15:43:10 -0700 | [diff] [blame] | 19 | import java.util.concurrent.Executor; |
Madan Jampani | d36def0 | 2016-01-13 11:21:56 -0800 | [diff] [blame] | 20 | import java.util.function.BiConsumer; |
| 21 | import java.util.function.BiFunction; |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 22 | |
| 23 | /** |
| 24 | * Interface for low level messaging primitives. |
| 25 | */ |
| 26 | public interface MessagingService { |
Madan Jampani | c26eede | 2015-04-16 11:42:16 -0700 | [diff] [blame] | 27 | |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 28 | /** |
| 29 | * Sends a message asynchronously to the specified communication end point. |
| 30 | * The message is specified using the type and payload. |
| 31 | * @param ep end point to send the message to. |
| 32 | * @param type type of message. |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 33 | * @param payload message payload bytes. |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 34 | * @return future that is completed when the message is sent |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 35 | */ |
Madan Jampani | 175e8fd | 2015-05-20 14:10:45 -0700 | [diff] [blame] | 36 | CompletableFuture<Void> sendAsync(Endpoint ep, String type, byte[] payload); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 37 | |
| 38 | /** |
Madan Jampani | d36def0 | 2016-01-13 11:21:56 -0800 | [diff] [blame] | 39 | * Sends a message asynchronously and expects a response. |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 40 | * @param ep end point to send the message to. |
| 41 | * @param type type of message. |
| 42 | * @param payload message payload. |
| 43 | * @return a response future |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 44 | */ |
Madan Jampani | c26eede | 2015-04-16 11:42:16 -0700 | [diff] [blame] | 45 | CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 46 | |
| 47 | /** |
Madan Jampani | d36def0 | 2016-01-13 11:21:56 -0800 | [diff] [blame] | 48 | * Sends a message synchronously and expects a response. |
| 49 | * @param ep end point to send the message to. |
| 50 | * @param type type of message. |
| 51 | * @param payload message payload. |
| 52 | * @param executor executor over which any follow up actions after completion will be executed. |
| 53 | * @return a response future |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 54 | */ |
Madan Jampani | d36def0 | 2016-01-13 11:21:56 -0800 | [diff] [blame] | 55 | CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload, Executor executor); |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Registers a new message handler for message type. |
| 59 | * @param type message type. |
| 60 | * @param handler message handler |
Madan Jampani | c26eede | 2015-04-16 11:42:16 -0700 | [diff] [blame] | 61 | * @param executor executor to use for running message handler logic. |
Madan Jampani | 2af244a | 2015-02-22 13:12:01 -0800 | [diff] [blame] | 62 | */ |
Madan Jampani | d36def0 | 2016-01-13 11:21:56 -0800 | [diff] [blame] | 63 | void registerHandler(String type, BiConsumer<Endpoint, byte[]> handler, Executor executor); |
| 64 | |
| 65 | /** |
| 66 | * Registers a new message handler for message type. |
| 67 | * @param type message type. |
| 68 | * @param handler message handler |
| 69 | * @param executor executor to use for running message handler logic. |
| 70 | */ |
| 71 | void registerHandler(String type, BiFunction<Endpoint, byte[], byte[]> handler, Executor executor); |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 72 | |
| 73 | /** |
Madan Jampani | 27b69c6 | 2015-05-15 15:49:02 -0700 | [diff] [blame] | 74 | * Registers a new message handler for message type. |
| 75 | * @param type message type. |
| 76 | * @param handler message handler |
| 77 | */ |
Madan Jampani | d36def0 | 2016-01-13 11:21:56 -0800 | [diff] [blame] | 78 | void registerHandler(String type, BiFunction<Endpoint, byte[], CompletableFuture<byte[]>> handler); |
Madan Jampani | 27b69c6 | 2015-05-15 15:49:02 -0700 | [diff] [blame] | 79 | |
| 80 | /** |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 81 | * Unregister current handler, if one exists for message type. |
| 82 | * @param type message type |
| 83 | */ |
Madan Jampani | c26eede | 2015-04-16 11:42:16 -0700 | [diff] [blame] | 84 | void unregisterHandler(String type); |
Brian O'Connor | abafb50 | 2014-12-02 22:26:20 -0800 | [diff] [blame] | 85 | } |