Interface AsyncHandle
-
public interface AsyncHandle
A class to handle the request and response handling when using asynchronous request handling.
To asynchronously read the request body, see
setReadListener(RequestBodyListener)
. To write data, this interface provides asynchronous write operations, or alternatively you can use the blocking write operations on the originalMuResponse
.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description void
addResponseCompleteHandler(ResponseCompleteListener responseCompleteListener)
Add a listener for when request processing is complete.void
complete()
Call this to indicate that the response is complete.void
complete(java.lang.Throwable throwable)
Call this to indicate that the response is complete.void
setReadListener(RequestBodyListener readListener)
Sets a listener that will be notified when chunks of request data become available.java.util.concurrent.Future<java.lang.Void>
write(java.nio.ByteBuffer data)
Writes data to the response asynchronously.void
write(java.nio.ByteBuffer data, DoneCallback callback)
Writes data to the response asynchronously.
-
-
-
Method Detail
-
setReadListener
void setReadListener(RequestBodyListener readListener)
Sets a listener that will be notified when chunks of request data become available.
If this is not set, then the usual (blocking) request reading methods on the request object can be used.
- Parameters:
readListener
- The listener.
-
complete
void complete()
Call this to indicate that the response is complete.
-
complete
void complete(java.lang.Throwable throwable)
Call this to indicate that the response is complete.If the
throwable
parameter is not null then the error will be logged and, if possible, a500 Internal Server Error
message will be sent to the client.- Parameters:
throwable
- an exception to log, or null if there was no problem
-
write
void write(java.nio.ByteBuffer data, DoneCallback callback)
Writes data to the response asynchronously.
Note that even in async mode it is possible to use the blocking write methods on the
MuResponse
See
write(ByteBuffer)
for an alternative that returns a future.- Parameters:
data
- The data to writecallback
- The callback when the write succeeds or fails
-
write
java.util.concurrent.Future<java.lang.Void> write(java.nio.ByteBuffer data)
Writes data to the response asynchronously.
Note that even in async mode it is possible to use the blocking write methods on the
MuResponse
See
write(ByteBuffer, DoneCallback)
for an alternative that uses a callback.- Parameters:
data
- The data to write- Returns:
- A future that is resolved when the write succeeds or fails.
-
addResponseCompleteHandler
void addResponseCompleteHandler(ResponseCompleteListener responseCompleteListener)
Add a listener for when request processing is complete. One use of this is to detect early client disconnects so that expensive operations can be cancelled.- Parameters:
responseCompleteListener
- The handler to invoke when the request is complete.
-
-