blob: 09f15f8a986fde54e3afaa803dfc97613a99cf64 [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
18import java.io.IOException;
Madan Jampani2bfa94c2015-04-11 05:03:49 -070019import java.util.concurrent.CompletableFuture;
Madan Jampaniec5ae342015-04-13 15:43:10 -070020import java.util.concurrent.Executor;
Madan Jampanic26eede2015-04-16 11:42:16 -070021import java.util.function.Consumer;
22import java.util.function.Function;
Madan Jampaniab6d3112014-10-02 16:30:14 -070023
24/**
25 * Interface for low level messaging primitives.
26 */
27public interface MessagingService {
Madan Jampanic26eede2015-04-16 11:42:16 -070028
Madan Jampaniab6d3112014-10-02 16:30:14 -070029 /**
30 * Sends a message asynchronously to the specified communication end point.
31 * The message is specified using the type and payload.
32 * @param ep end point to send the message to.
33 * @param type type of message.
Madan Jampani53e44e62014-10-07 12:39:51 -070034 * @param payload message payload bytes.
Yuta HIGUCHI5c947272014-11-03 21:39:21 -080035 * @throws IOException when I/O exception of some sort has occurred
Madan Jampaniab6d3112014-10-02 16:30:14 -070036 */
Madan Jampanic26eede2015-04-16 11:42:16 -070037 void sendAsync(Endpoint ep, String type, byte[] payload) throws IOException;
Madan Jampaniab6d3112014-10-02 16:30:14 -070038
39 /**
40 * Sends a message synchronously and waits for a response.
41 * @param ep end point to send the message to.
42 * @param type type of message.
43 * @param payload message payload.
44 * @return a response future
Madan Jampaniab6d3112014-10-02 16:30:14 -070045 */
Madan Jampanic26eede2015-04-16 11:42:16 -070046 CompletableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload);
Madan Jampaniab6d3112014-10-02 16:30:14 -070047
48 /**
49 * Registers a new message handler for message type.
50 * @param type message type.
51 * @param handler message handler
Madan Jampani2af244a2015-02-22 13:12:01 -080052 * @param executor executor to use for running message handler logic.
Madan Jampaniab6d3112014-10-02 16:30:14 -070053 */
Madan Jampanic26eede2015-04-16 11:42:16 -070054 void registerHandler(String type, Consumer<byte[]> handler, Executor executor);
Madan Jampani2af244a2015-02-22 13:12:01 -080055
56 /**
57 * Registers a new message handler for message type.
58 * @param type message type.
59 * @param handler message handler
Madan Jampanic26eede2015-04-16 11:42:16 -070060 * @param executor executor to use for running message handler logic.
Madan Jampani2af244a2015-02-22 13:12:01 -080061 */
Madan Jampanic26eede2015-04-16 11:42:16 -070062 void registerHandler(String type, Function<byte[], byte[]> handler, Executor executor);
Madan Jampaniab6d3112014-10-02 16:30:14 -070063
64 /**
Madan Jampani27b69c62015-05-15 15:49:02 -070065 * Registers a new message handler for message type.
66 * @param type message type.
67 * @param handler message handler
68 */
69 void registerHandler(String type, Function<byte[], CompletableFuture<byte[]>> handler);
70
71 /**
Madan Jampaniab6d3112014-10-02 16:30:14 -070072 * Unregister current handler, if one exists for message type.
73 * @param type message type
74 */
Madan Jampanic26eede2015-04-16 11:42:16 -070075 void unregisterHandler(String type);
Brian O'Connorabafb502014-12-02 22:26:20 -080076}