public final class MultiFetch extends RiakCommand<ResponseType,List<Location>>
Riak itself does not support pipelining of requests. MutliFetch addresses this issue by using a thread to parallelize and manage a set of async fetch operations for a given set of keys.
The result of executing this command is a List
of RiakFuture
objects, each one representing a single
fetch operation. The returned RiakFuture
that contains that list completes
when all the FetchValue operations contained have finished.
MultiFetch multifetch = ...;
MultiFetch.Response response = client.execute(multifetch);
List<MyPojo> myResults = new ArrayList<MyPojo>();
for (RiakFuture<FetchValue.Response, Location> f : response)
{
try
{
FetchValue.Response response = f.get();
myResults.add(response.getValue(MyPojo.class));
}
catch (ExecutionException e)
{
// log error, etc.
}
}
The maximum number of concurrent requests defaults to 10. This can be changed when constructing the operation.
Be aware that because requests are being parallelized performance is also dependent on the client's underlying connection pool. If there are no connections available performance will suffer initially as connections will need to be established or worse they could time out.
Be aware that for responsiveness to the caller thread, the requests are run on a Daemon worker thread. Shutting down the client JVM before the future is complete will result in unexpected behavior, and an incomplete result.
Modifier and Type | Class and Description |
---|---|
static class |
MultiFetch.Builder
Used to construct a MutiFetch command.
|
static class |
MultiFetch.Response
The response from Riak for a MultiFetch command.
|
Modifier and Type | Field and Description |
---|---|
protected Map<RiakOption<?>,Object> |
options |
Modifier and Type | Method and Description |
---|---|
protected FetchValue.Builder |
createBaseBuilderType(Location location) |
protected MultiFetch.Response |
createResponseType(List<RiakFuture<FetchValue.Response,Location>> riakFutures) |
boolean |
equals(Object o) |
protected RiakFuture<ResponseType,List<Location>> |
executeAsync(RiakCluster cluster) |
protected RiakFuture<FetchValue.Response,Location> |
executeBaseCommandAsync(FetchValue command,
RiakCluster cluster) |
int |
hashCode() |
String |
toString() |
execute, execute
protected final Map<RiakOption<?>,Object> options
protected MultiFetch.Response createResponseType(List<RiakFuture<FetchValue.Response,Location>> riakFutures)
protected FetchValue.Builder createBaseBuilderType(Location location)
protected RiakFuture<FetchValue.Response,Location> executeBaseCommandAsync(FetchValue command, RiakCluster cluster)
protected RiakFuture<ResponseType,List<Location>> executeAsync(RiakCluster cluster)
executeAsync
in class RiakCommand<ResponseType extends Iterable<RiakFuture<BaseResponseType,Location>>,List<Location>>
Copyright © 2016. All rights reserved.