@Override public void doSearch() throws InterruptedException, ParseException, TimeoutException { VisitorSession session = visitorSessionFactory.createVisitorSession(params); try { if ( !session.waitUntilDone(query.getTimeout())) { log.log(LogLevel.DEBUG, "Visitor returned from waitUntilDone without being completed for " + query + " with selection " + params.getDocumentSelection()); session.abort(); throw new TimeoutException("Query timed out in " + VdsStreamingSearcher.class.getName()); } } finally { session.destroy(); log.log(LogLevel.DEBUG, () -> session.getTrace().toString()); } query.trace(session.getTrace().toString(), false, 9); if (params.getControlHandler().getResult().code == VisitorControlHandler.CompletionCode.SUCCESS) { if (log.isLoggable(LogLevel.DEBUG)) { log.log(LogLevel.DEBUG, "VdsVisitor completed successfully for " + query + " with selection " + params.getDocumentSelection()); } } else { throw new IllegalArgumentException("Query failed: " // TODO: Is it necessary to use a runtime exception? + params.getControlHandler().getResult().code + ": " + params.getControlHandler().getResult().message); } }
private static void throwIfFatalVisitingError(VisitorControlHandler handler, RestUri restUri) throws RestApiException { final VisitorControlHandler.Result result = handler.getResult(); if (result.getCode() == VisitorControlHandler.CompletionCode.TIMEOUT) { if (! handler.hasVisitedAnyBuckets()) { throw new RestApiException(Response.createErrorResponse(500, "Timed out", restUri, RestUri.apiErrorCodes.TIME_OUT)); } // else: some progress has been made, let client continue with new token. } else if (result.getCode() != VisitorControlHandler.CompletionCode.SUCCESS) { throw new RestApiException(Response.createErrorResponse(400, result.toString(), RestUri.apiErrorCodes.VISITOR_ERROR)); } }