use of org.codelibs.elasticsearch.idxproxy.sender.RequestSender in project elasticsearch-indexing-proxy by codelibs.
the class IndexingProxyService method launchRequestSender.
private void launchRequestSender(final String index, final long filePosition, final long version, final ActionListener<Map<String, Object>> listener) {
if (logger.isDebugEnabled()) {
logger.debug("Launching RequestSender(" + index + ")");
}
final Map<String, Object> source = new HashMap<>();
source.put(IndexingProxyPlugin.NODE_NAME, nodeName());
source.put(IndexingProxyPlugin.FILE_POSITION, filePosition);
source.put(IndexingProxyPlugin.TIMESTAMP, new Date());
source.put(DOC_TYPE, "index");
final IndexRequestBuilder builder = client.prepareIndex(IndexingProxyPlugin.INDEX_NAME, IndexingProxyPlugin.TYPE_NAME, index).setSource(source).setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
if (version > 0) {
builder.setVersion(version);
} else {
builder.setCreate(true);
}
builder.execute(wrap(res -> {
if (res.getResult() == Result.CREATED || res.getResult() == Result.UPDATED) {
final RequestSender sender = new RequestSender(settings, client, threadPool, namedWriteableRegistry, nodeName(), dataPath, index, dataFileFormat, docSenderMap, logger);
final RequestSender oldSender = docSenderMap.put(index, sender);
if (oldSender != null) {
oldSender.terminate();
}
threadPool.schedule(TimeValue.ZERO, Names.GENERIC, sender);
listener.onResponse(source);
} else {
listener.onFailure(new ElasticsearchException("Failed to update .idxproxy index: " + res));
}
}, listener::onFailure));
}
Aggregations