private synchronized Optional<QueryResults> getCachedResult(long token, UriInfo uriInfo) { // is the a repeated request for the last results? String requestedPath = uriInfo.getAbsolutePath().getPath(); if (requestedPath.equals(lastResultPath)) { if (submissionFuture.isDone()) { // tell query manager we are still interested in the query queryManager.recordHeartbeat(queryId); } return Optional.of(lastResult); } if (token < resultId.get()) { throw new WebApplicationException(Response.Status.GONE); } // if this is not a request for the next results, return not found if (lastResult.getNextUri() == null || !requestedPath.equals(lastResult.getNextUri().getPath())) { // unknown token throw new WebApplicationException(Response.Status.NOT_FOUND); } return Optional.empty(); }
private synchronized ListenableFuture<?> getFutureStateChange() { // ensure the query has been submitted submissionFuture.submitQuery(); // if query query submission has not finished, wait for it to finish if (!submissionFuture.isDone()) { return submissionFuture; } // if the exchange client is open, wait for data if (!exchangeClient.isClosed()) { return exchangeClient.isBlocked(); } // otherwise, wait for the query to finish queryManager.recordHeartbeat(queryId); try { return queryDoneFuture(queryManager.getQueryState(queryId)); } catch (NoSuchElementException e) { return immediateFuture(null); } }
public static void waitForQueryState(DistributedQueryRunner queryRunner, QueryId queryId, Set<QueryState> expectedQueryStates) throws InterruptedException { QueryManager queryManager = queryRunner.getCoordinator().getQueryManager(); do { // Heartbeat all the running queries, so they don't die while we're waiting for (BasicQueryInfo queryInfo : queryManager.getQueries()) { if (queryInfo.getState() == RUNNING) { queryManager.recordHeartbeat(queryInfo.getQueryId()); } } MILLISECONDS.sleep(500); } while (!expectedQueryStates.contains(queryManager.getQueryState(queryId))); }
queryManager.recordHeartbeat(queryId);
public synchronized QueryResults getResults(long token, UriInfo uriInfo, Duration maxWaitTime) throws InterruptedException { // is the a repeated request for the last results? String requestedPath = uriInfo.getAbsolutePath().getPath(); if (lastResultPath != null && requestedPath.equals(lastResultPath)) { // tell query manager we are still interested in the query queryManager.getQueryInfo(queryId); queryManager.recordHeartbeat(queryId); return lastResult; } if (token < resultId.get()) { throw new WebApplicationException(Status.GONE); } // if this is not a request for the next results, return not found if (lastResult.getNextUri() == null || !requestedPath.equals(lastResult.getNextUri().getPath())) { // unknown token throw new WebApplicationException(Status.NOT_FOUND); } return getNextResults(uriInfo, maxWaitTime); }
public static void waitForQueryState(DistributedQueryRunner queryRunner, QueryId queryId, Set<QueryState> expectedQueryStates) throws InterruptedException { QueryManager queryManager = queryRunner.getCoordinator().getQueryManager(); do { // Heartbeat all the running queries, so they don't die while we're waiting for (BasicQueryInfo queryInfo : queryManager.getQueries()) { if (queryInfo.getState() == RUNNING) { queryManager.recordHeartbeat(queryInfo.getQueryId()); } } MILLISECONDS.sleep(500); } while (!expectedQueryStates.contains(queryManager.getQueryState(queryId))); }
queryManager.recordHeartbeat(queryId); maxWait = queryManager.waitForStateChange(queryId, queryInfo.getState(), maxWait); queryInfo = queryManager.getQueryInfo(queryId);
queryManager.recordHeartbeat(queryId);