blob: df28826aa90a19971a707f19106b3fee9c557504 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2015-present Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska24c849c2014-10-27 09:53:05 -070015 */
Madan Jampanic26eede2015-04-16 11:42:16 -070016package org.onosproject.store.cluster.messaging;
Madan Jampaniab6d3112014-10-02 16:30:14 -070017
Madan Jampani2bfa94c2015-04-11 05:03:49 -070018import java.util.concurrent.CompletableFuture;
Madan Jampaniec5ae342015-04-13 15:43:10 -070019import java.util.concurrent.Executor;
Madan Jampanid36def02016-01-13 11:21:56 -080020import java.util.function.BiConsumer;
21import java.util.function.BiFunction;
Madan Jampaniab6d3112014-10-02 16:30:14 -070022
23/**
24 * Interface for low level messaging primitives.
25 */
26public interface MessagingService {
Madan Jampanic26eede2015-04-16 11:42:16 -070027
Madan Jampaniab6d3112014-10-02 16:30:14 -070028 /**
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 Jampani53e44e62014-10-07 12:39:51 -070033 * @param payload message payload bytes.
Madan Jampani175e8fd2015-05-20 14:10:45 -070034 * @return future that is completed when the message is sent
Madan Jampaniab6d3112014-10-02 16:30:14 -070035 */
Madan Jampani175e8fd2015-05-20 14:10:45 -070036 CompletableFuture<Void> sendAsync(Endpoint ep, String type, byte[] payload);
Madan Jampaniab6d3112014-10-02 16:30:14 -070037
38 /**
Madan Jampanid36def02016-01-13 11:21:56 -080039 * Sends a message asynchronously and expects a response.
Madan Jampaniab6d3112014-10-02 16:30:14 -070040 * @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 Jampaniab6d3112014-10-02 16:30:14 -070044 */
Madan Jampanic26eede2015-04-16 11:42:16 -070045 CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload);
Madan Jampaniab6d3112014-10-02 16:30:14 -070046
47 /**
Madan Jampanid36def02016-01-13 11:21:56 -080048 * 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 Jampaniab6d3112014-10-02 16:30:14 -070054 */
Madan Jampanid36def02016-01-13 11:21:56 -080055 CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload, Executor executor);
Madan Jampani2af244a2015-02-22 13:12:01 -080056
57 /**
58 * Registers a new message handler for message type.
59 * @param type message type.
60 * @param handler message handler
Madan Jampanic26eede2015-04-16 11:42:16 -070061 * @param executor executor to use for running message handler logic.
Madan Jampani2af244a2015-02-22 13:12:01 -080062 */
Madan Jampanid36def02016-01-13 11:21:56 -080063 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 Jampaniab6d3112014-10-02 16:30:14 -070072
73 /**
Madan Jampani27b69c62015-05-15 15:49:02 -070074 * Registers a new message handler for message type.
75 * @param type message type.
76 * @param handler message handler
77 */
Madan Jampanid36def02016-01-13 11:21:56 -080078 void registerHandler(String type, BiFunction<Endpoint, byte[], CompletableFuture<byte[]>> handler);
Madan Jampani27b69c62015-05-15 15:49:02 -070079
80 /**
Madan Jampaniab6d3112014-10-02 16:30:14 -070081 * Unregister current handler, if one exists for message type.
82 * @param type message type
83 */
Madan Jampanic26eede2015-04-16 11:42:16 -070084 void unregisterHandler(String type);
Brian O'Connorabafb502014-12-02 22:26:20 -080085}