本文整理汇总了Java中com.basho.riak.client.api.commands.kv.FetchValue类的典型用法代码示例。如果您正苦于以下问题:Java FetchValue类的具体用法?Java FetchValue怎么用?Java FetchValue使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
FetchValue类属于com.basho.riak.client.api.commands.kv包,在下文中一共展示了FetchValue类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: get
import com.basho.riak.client.api.commands.kv.FetchValue; //导入依赖的package包/类
@Override
public Reader get( EntityReference entityReference )
{
try
{
Location location = new Location( namespace, entityReference.identity().toString() );
FetchValue fetch = new FetchValue.Builder( location ).build();
FetchValue.Response response = riakClient.execute( fetch );
if( response.isNotFound() )
{
throw new EntityNotFoundException( entityReference );
}
String jsonState = response.getValue( String.class );
return new StringReader( jsonState );
}
catch( InterruptedException | ExecutionException ex )
{
throw new EntityStoreException( "Unable to get Entity " + entityReference.identity(), ex );
}
}
示例2: get
import com.basho.riak.client.api.commands.kv.FetchValue; //导入依赖的package包/类
@Override
public void get(Buffer keys, Callback<Buffer> callback) {
List<Location> locations = new ArrayList<Location>();
BufferIterator it = keys.iterator();
while (it.hasNext()) {
Buffer keyView = it.next();
Location location = new Location(_ns, new String(keyView.data()));
locations.add(location);
}
MultiFetch multifetch = new MultiFetch.Builder().addLocations(locations).build();
try {
MultiFetch.Response response = _client.execute(multifetch);
java.util.Map<Location, byte[]> alignedResults = new HashMap<Location, byte[]>();
List<RiakFuture<FetchValue.Response, Location>> l = response.getResponses();
for (int i = 0; i < l.size(); i++) {
FetchValue.Response fetchResponse = l.get(i).get();
List<RiakObject> objs = fetchResponse.getValues();
if (!objs.isEmpty()) {
alignedResults.put(fetchResponse.getLocation(), objs.get(0).getValue().getValue());
}
}
final Buffer result = _graph.newBuffer();
for (int i = 0; i < locations.size(); i++) {
if (i != 0) {
result.write(Constants.BUFFER_SEP);
}
byte[] resolved = alignedResults.get(locations.get(i));
if (resolved != null) {
result.writeAll(resolved);
}
}
callback.on(result);
} catch (Exception e) {
e.printStackTrace();
}
/*
_client.executeAsync(multifetch).addListener(new RiakFutureListener<MultiFetch.Response, List<Location>>() {
@Override
public void handle(RiakFuture<MultiFetch.Response, List<Location>> f) {
try {
System.out.println("BEFORE GET");
MultiFetch.Response resp = f.get();
java.util.Map<Location, byte[]> alignedResults = new HashMap<Location, byte[]>();
List<RiakFuture<FetchValue.Response, Location>> l = resp.getResponses();
for (int i = 0; i < l.size(); i++) {
FetchValue.Response response = l.get(i).get();
List<RiakObject> objs = response.getValues();
if (!objs.isEmpty()) {
alignedResults.put(response.getLocation(), objs.get(0).getValue().getValue());
}
}
final Buffer result = _graph.newBuffer();
for (int i = 0; i < locations.size(); i++) {
if (i != 0) {
result.write(Constants.BUFFER_SEP);
}
byte[] resolved = alignedResults.get(locations.get(i));
if (resolved != null) {
result.writeAll(resolved);
}
}
System.out.println("AFTER GET");
callback.on(result);
} catch (Exception e) {
e.printStackTrace();
callback.on(null);
}
}
});*/
}