Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 1 | package org.onlab.netty; |
| 2 | |
| 3 | import java.io.IOException; |
| 4 | |
Madan Jampani | 24f9efb | 2014-10-24 18:56:23 -0700 | [diff] [blame] | 5 | import com.google.common.util.concurrent.ListenableFuture; |
| 6 | |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 7 | /** |
| 8 | * Interface for low level messaging primitives. |
| 9 | */ |
| 10 | public interface MessagingService { |
| 11 | /** |
| 12 | * Sends a message asynchronously to the specified communication end point. |
| 13 | * The message is specified using the type and payload. |
| 14 | * @param ep end point to send the message to. |
| 15 | * @param type type of message. |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 16 | * @param payload message payload bytes. |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 17 | * @throws IOException |
| 18 | */ |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 19 | public void sendAsync(Endpoint ep, String type, byte[] payload) throws IOException; |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 20 | |
| 21 | /** |
| 22 | * Sends a message synchronously and waits for a response. |
| 23 | * @param ep end point to send the message to. |
| 24 | * @param type type of message. |
| 25 | * @param payload message payload. |
| 26 | * @return a response future |
| 27 | * @throws IOException |
| 28 | */ |
Madan Jampani | 24f9efb | 2014-10-24 18:56:23 -0700 | [diff] [blame] | 29 | public ListenableFuture<byte[]> sendAndReceive(Endpoint ep, String type, byte[] payload) throws IOException; |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 30 | |
| 31 | /** |
| 32 | * Registers a new message handler for message type. |
| 33 | * @param type message type. |
| 34 | * @param handler message handler |
| 35 | */ |
| 36 | public void registerHandler(String type, MessageHandler handler); |
| 37 | |
| 38 | /** |
| 39 | * Unregister current handler, if one exists for message type. |
| 40 | * @param type message type |
| 41 | */ |
| 42 | public void unregisterHandler(String type); |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 43 | } |