public interface Interactor
extends java.io.Closeable
MultiCall
s in a pull-based fashion.
Using this class when executing MultiCall
instances gives more control over connection writes and reads, providing the following benefits:
NOTE:Take care of calling close() when done with objects of this type, or resource leaks will occur.
Modifier and Type | Method and Description |
---|---|
void |
close()
|
boolean |
hasMoreRequests() |
boolean |
hasNextResponse() |
Response |
nextResponse()
Read the next response
|
int |
submitRequests(int count)
Write a given amount of requests.
|
boolean hasMoreRequests()
true
if there are more Requests that can be written, false
otherwise.int submitRequests(int count) throws java.io.IOException
When called, the method will block and attempt to send at most count
requests, but no more than the remaining request count left to be sent.
The returned value is the actual number of requests sent.
For an example, if the total request count is 5, submitRequests(6)
will return 5
.
Next calls to submitRequests()
will always return 0
.
count
- the amount of requests to be sentjava.lang.IllegalArgumentException
- when count < 0
java.io.IOException
- if an error occurs during sending, or the MultiCall has been cancelled.boolean hasNextResponse()
true
if there are more Responses that can be read, false
otherwise.Response nextResponse() throws java.io.IOException
When called, the method will block and attempt to read a single response, either returning the result or failing with an error.
The method will throw an IllegalStateException if the number of sent requests is equal to the number of received responses to avoid the case where the method will be waiting for a response, but none is expected to arrive, thus blocking forever (or a connection read timeout is reached).
void close()
close
in interface java.lang.AutoCloseable
close
in interface java.io.Closeable