use of org.elasticsearch.plugins.changes.beans.IndexChangeWatcher in project elasticsearch-changes-plugin by derryx.
the class ChangesAction method handleRequest.
@Override
protected void handleRequest(RestRequest request, RestChannel channel, Client client) throws Exception {
logger.debug("Request");
List<String> indices = Arrays.asList(splitIndices(request.param("index")));
if (indices.isEmpty()) {
indices = new ArrayList<String>(changes.keySet());
}
boolean wait = request.paramAsBoolean("wait", Boolean.FALSE);
long timeout = request.paramAsLong("timeout", 15 * 60 * 1000);
// Wait for trigger
if (wait) {
IndexChangeWatcher watcher = addWatcher(indices, timeout);
boolean changeDetected = watcher.aquire();
removeWatcher(indices);
if (!changeDetected) {
channel.sendResponse(new BytesRestResponse(RestStatus.NOT_FOUND, "No change detected during timeout interval"));
return;
}
if (watcher.getChange() == null || watcher.getChange().getType() == null) {
channel.sendResponse(new BytesRestResponse(RestStatus.NOT_FOUND, "No more shards available to trigger waiting watch"));
return;
}
}
XContentBuilder builder = createXContentBuilderForChanges(request, indices);
channel.sendResponse(new BytesRestResponse(OK, builder));
}
Aggregations