blob: 6ccd48352e496ee3a0f2ec6ba83b163bf102f30a [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Ray Milkey34c95902015-04-15 09:47:53 -07002 * Copyright 2014-2015 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 Jampanic26eede2015-04-16 11:42:16 -070020import java.util.function.Consumer;
21import java.util.function.Function;
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 /**
39 * Sends a message synchronously and waits for a response.
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 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 /**
48 * Registers a new message handler for message type.
49 * @param type message type.
50 * @param handler message handler
Madan Jampani2af244a2015-02-22 13:12:01 -080051 * @param executor executor to use for running message handler logic.
Madan Jampaniab6d3112014-10-02 16:30:14 -070052 */
Madan Jampanic26eede2015-04-16 11:42:16 -070053 void registerHandler(String type, Consumer<byte[]> handler, Executor executor);
Madan Jampani2af244a2015-02-22 13:12:01 -080054
55 /**
56 * Registers a new message handler for message type.
57 * @param type message type.
58 * @param handler message handler
Madan Jampanic26eede2015-04-16 11:42:16 -070059 * @param executor executor to use for running message handler logic.
Madan Jampani2af244a2015-02-22 13:12:01 -080060 */
Madan Jampanic26eede2015-04-16 11:42:16 -070061 void registerHandler(String type, Function<byte[], byte[]> handler, Executor executor);
Madan Jampaniab6d3112014-10-02 16:30:14 -070062
63 /**
Madan Jampani27b69c62015-05-15 15:49:02 -070064 * Registers a new message handler for message type.
65 * @param type message type.
66 * @param handler message handler
67 */
68 void registerHandler(String type, Function<byte[], CompletableFuture<byte[]>> handler);
69
70 /**
Madan Jampaniab6d3112014-10-02 16:30:14 -070071 * Unregister current handler, if one exists for message type.
72 * @param type message type
73 */
Madan Jampanic26eede2015-04-16 11:42:16 -070074 void unregisterHandler(String type);
Brian O'Connorabafb502014-12-02 22:26:20 -080075}