Package com.mastfrog.netty.http.client
Class ResponseFuture
java.lang.Object
com.mastfrog.netty.http.client.ResponseFuture
- All Implemented Interfaces:
Comparable<ResponseFuture>
Returned from launching an HTTP request; attach handlers using the
on(Class<EventType>, Receiver<State<T>>))
method. Note that it is preferable to attach handlers when constructing the
request, unless you can guarantee that the request won't be completed before
your handler is attached.- Author:
- Tim Boudreau
-
Method Summary
Modifier and TypeMethodDescriptionawait()Wait for the channel to be closed.Wait for a timeout for the request to be complleted.booleancancel()Cancel the associated request.intfinal StateType<T> ResponseFutureAdd a listener for a particular type of event<T> ResponseFutureonAnyEvent(Receiver<State<?>> r) Add a listener which is notified of all state changes (there are many!).Send some objects through the channel once a given state is reached (if the state already has been, they will be sent immediately if the channel is not closed).If an error was encountered, throw it
-
Method Details
-
sendOn
Send some objects through the channel once a given state is reached (if the state already has been, they will be sent immediately if the channel is not closed).- Parameters:
stateType- The state to trigger sending. Must NOT be a state that indicates a closed channel, error or failure condition, or pre-connection state, because there is no channel to use.o- What to send - must be an object Netty's channel pipeline has a handler for it, such as an HttpContent or ByteBuf or WebSocketFrame (the main use for this method)- Returns:
- this
- Throws:
IllegalArgumentException- if the state type is one that has no associated network channel
-
await
Wait for the channel to be closed. Dangerous without a timeout! Note - blocking while waiting for a response defeats the purpose of using an asynchronous HTTP client; this sort of thing is sometimes useful in unit tests, but should not be done in production code. Where possible, find a way to attach a callback and finish work there, rather than use this method.- Throws:
InterruptedException
-
await
Wait for a timeout for the request to be complleted. This is realy for use in unit tests - normal users of this library should use callbacks. Note - blocking while waiting for a response defeats the purpose of using an asynchronous HTTP client; this sort of thing is sometimes useful in unit tests, but should not be done in production code. Where possible, find a way to attach a callback and finish work there, rather than use this method.- Parameters:
l- A number of time unitstu- Time units- Returns:
- follows the contract of CountDownLatch.await()
- Throws:
InterruptedException
-
cancel
public boolean cancel()Cancel the associated request. This will make a best-effort, but cannot guarantee, that no state changes will be fired after the final Cancelled.- Returns:
- true if it succeeded, false if it was already canceled
-
throwIfError
If an error was encountered, throw it- Returns:
- this
- Throws:
Throwable- a throwable
-
lastState
-
onAnyEvent
Add a listener which is notified of all state changes (there are many!).- Parameters:
r-- Returns:
-
on
Add a listener for a particular type of event -
on
-
compareTo
- Specified by:
compareToin interfaceComparable<ResponseFuture>
-