本文整理汇总了Java中org.elasticsearch.action.ListenableActionFuture.addListener方法的典型用法代码示例。如果您正苦于以下问题:Java ListenableActionFuture.addListener方法的具体用法?Java ListenableActionFuture.addListener怎么用?Java ListenableActionFuture.addListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.ListenableActionFuture
的用法示例。
在下文中一共展示了ListenableActionFuture.addListener方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: bind
import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
protected <T extends ActionResponse> AsyncFuture<T> bind(
final ListenableActionFuture<T> actionFuture
) {
final ResolvableFuture<T> future = async.future();
actionFuture.addListener(new ActionListener<T>() {
@Override
public void onResponse(T result) {
future.resolve(result);
}
@Override
public void onFailure(Exception e) {
future.fail(e);
}
});
return future;
}
示例2: toGuava
import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
static <T> ListenableFuture<T> toGuava(ListenableActionFuture<T> elasticFuture) {
final SettableFuture<T> future = SettableFuture.create();
elasticFuture.addListener(new ActionListener<T>() {
@Override public void onResponse(T t) {
future.set(t);
}
@Override public void onFailure(Throwable e) {
future.setException(e);
}
});
return future;
}
示例3: configure
import org.elasticsearch.action.ListenableActionFuture; //导入方法依赖的package包/类
public AsyncFuture<Void> configure() {
final IndicesAdminClient indices = client.getClient().admin().indices();
log.info("[{}] updating template for {}", templateName, index.template());
final PutIndexTemplateRequestBuilder put = indices.preparePutTemplate(templateName);
put.setSettings(type.getSettings());
put.setTemplate(index.template());
for (final Map.Entry<String, Map<String, Object>> mapping : type.getMappings().entrySet()) {
put.addMapping(mapping.getKey(), mapping.getValue());
}
final ResolvableFuture<Void> future = async.future();
final ListenableActionFuture<PutIndexTemplateResponse> target = put.execute();
target.addListener(new ActionListener<PutIndexTemplateResponse>() {
@Override
public void onResponse(final PutIndexTemplateResponse response) {
if (!response.isAcknowledged()) {
future.fail(new Exception("request not acknowledged"));
return;
}
future.resolve(null);
}
@Override
public void onFailure(Exception e) {
future.fail(e);
}
});
future.onCancelled(() -> target.cancel(false));
return future;
}