R
- the type of the SQS request to batchResult
- the type of result he futures issued by this task will returnprivate abstract class SendQueueBuffer.OutboundBatchTask<R extends AmazonWebServiceRequest,Result>
extends java.lang.Object
implements java.lang.Runnable
The batch task is constructed open and accepts requests until full, or until
maxBatchOpenMs
elapses. At that point, the batch closes and the collected requests
are assembled into a single batch request to SQS. Specialized for each type of outbound
request.
Instances of this class (and subclasses) are thread-safe.
Modifier and Type | Field and Description |
---|---|
private boolean |
closed |
protected java.util.ArrayList<QueueBufferFuture<R,Result>> |
futures |
private SendQueueBuffer.Listener<SendQueueBuffer.OutboundBatchTask<R,Result>> |
onCompleted |
protected java.util.List<R> |
requests |
Constructor and Description |
---|
OutboundBatchTask() |
Modifier and Type | Method and Description |
---|---|
private QueueBufferFuture<R,Result> |
addIfAllowed(R request,
QueueBufferCallback<R,Result> callback)
Adds the request to the batch if capacity allows it.
|
QueueBufferFuture<R,Result> |
addRequest(R request,
QueueBufferCallback<R,Result> callback)
Adds a request to the batch if it is still open and has capacity.
|
private void |
failAll(java.lang.Exception e) |
protected boolean |
isFull()
Checks whether the buffer is now full.
|
protected boolean |
isOkToAdd(R request)
Checks whether it's okay to add the request to this buffer.
|
protected void |
onRequestAdded(R request)
A hook to be run when a request is successfully added to this buffer.
|
protected abstract void |
process(java.util.List<R> requests,
java.util.List<QueueBufferFuture<R,Result>> futures)
Processes the batch once closed.
|
void |
run() |
void |
setOnCompleted(SendQueueBuffer.Listener<SendQueueBuffer.OutboundBatchTask<R,Result>> value) |
protected final java.util.List<R extends AmazonWebServiceRequest> requests
protected final java.util.ArrayList<QueueBufferFuture<R extends AmazonWebServiceRequest,Result>> futures
private boolean closed
private volatile SendQueueBuffer.Listener<SendQueueBuffer.OutboundBatchTask<R extends AmazonWebServiceRequest,Result>> onCompleted
public void setOnCompleted(SendQueueBuffer.Listener<SendQueueBuffer.OutboundBatchTask<R,Result>> value)
public QueueBufferFuture<R,Result> addRequest(R request, QueueBufferCallback<R,Result> callback)
private QueueBufferFuture<R,Result> addIfAllowed(R request, QueueBufferCallback<R,Result> callback)
addRequest
with a
lock on this
held.request
- protected boolean isOkToAdd(R request)
addIfAllowed
with a lock on this
held.request
- the request to addprotected void onRequestAdded(R request)
addIfAllowed
with a lock on this
held.request
- the request that was addedprotected boolean isFull()
addIfAllowed
with a lock on
this
held.protected abstract void process(java.util.List<R> requests, java.util.List<QueueBufferFuture<R,Result>> futures)
this
.
However, it's passed a local copy of both the requests
and futures
lists
made while holding the lock.public final void run()
run
in interface java.lang.Runnable
private void failAll(java.lang.Exception e)