Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 1 | package org.onlab.netty; |
| 2 | |
| 3 | import java.util.concurrent.TimeUnit; |
| 4 | import java.util.concurrent.TimeoutException; |
| 5 | |
| 6 | /** |
| 7 | * Response object returned when making synchronous requests. |
| 8 | * Can you used to check is a response is ready and/or wait for a response |
| 9 | * to become available. |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 10 | */ |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 11 | public interface Response { |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 12 | |
| 13 | /** |
| 14 | * Gets the response waiting for a designated timeout period. |
| 15 | * @param timeout timeout period (since request was sent out) |
| 16 | * @param tu unit of time. |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 17 | * @return response payload |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 18 | * @throws TimeoutException if the timeout expires before the response arrives. |
| 19 | */ |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 20 | public byte[] get(long timeout, TimeUnit tu) throws TimeoutException; |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 21 | |
| 22 | /** |
| 23 | * Gets the response waiting for indefinite timeout period. |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 24 | * @return response payload |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 25 | * @throws InterruptedException if the thread is interrupted before the response arrives. |
| 26 | */ |
Madan Jampani | 53e44e6 | 2014-10-07 12:39:51 -0700 | [diff] [blame] | 27 | public byte[] get() throws InterruptedException; |
Madan Jampani | ab6d311 | 2014-10-02 16:30:14 -0700 | [diff] [blame] | 28 | |
| 29 | /** |
| 30 | * Checks if the response is ready without blocking. |
| 31 | * @return true if response is ready, false otherwise. |
| 32 | */ |
| 33 | public boolean isReady(); |
| 34 | } |