public Deferred<SuggestIndexResponse>.Promise indexFromQueryLog(final QueryLogReader queryLogReader, final int docPerReq,
            final long requestInterval) {
        final Deferred<SuggestIndexResponse> deferred = new Deferred<>();
        threadPool.execute(() -> {
            final long start = System.currentTimeMillis();
            int numberOfSuggestDocs = 0;
            int numberOfInputDocs = 0;
            final List<Throwable> errors = new ArrayList<>();

            final List<QueryLog> queryLogs = new ArrayList<>(docPerReq);
            try {
                QueryLog queryLog = queryLogReader.read();
                while (queryLog != null) {
                    if (Thread.currentThread().isInterrupted()) {
                        break;
                    }
                    queryLogs.add(queryLog);
                    queryLog = queryLogReader.read();
                    if ((queryLog == null && !queryLogs.isEmpty()) || queryLogs.size() >= docPerReq) {
                        final SuggestIndexResponse res = indexFromQueryLog(queryLogs.toArray(new QueryLog[queryLogs.size()]));
                        errors.addAll(res.getErrors());
                        numberOfSuggestDocs += res.getNumberOfSuggestDocs();
                        numberOfInputDocs += res.getNumberOfInputDocs();
                        queryLogs.clear();

                        Thread.sleep(requestInterval);
                    }
                }
                deferred.resolve(
                        new SuggestIndexResponse(numberOfSuggestDocs, numberOfInputDocs, errors, System.currentTimeMillis() - start));
            } catch (final Throwable t) {
                deferred.reject(t);
            } finally {
                queryLogReader.close();
            }
        });
        return deferred.promise();
    }
public Deferred < SuggestIndexResponse > . Promise indexFromQueryLog ( final QueryLogReader queryLogReader , final int docPerReq , final long requestInterval ) { final Deferred < SuggestIndexResponse > deferred = new Deferred < > ( ) ; threadPool . execute ( ( ) -> { final long start = System . currentTimeMillis ( ) ; int numberOfSuggestDocs = 0 ; int numberOfInputDocs = 0 ; final List < Throwable > errors = new ArrayList < > ( ) ; final List < QueryLog > queryLogs = new ArrayList < > ( docPerReq ) ; try { QueryLog queryLog = queryLogReader . read ( ) ; while ( queryLog != null ) { if ( Thread . currentThread ( ) . isInterrupted ( ) ) { break ; } queryLogs . add ( queryLog ) ; queryLog = queryLogReader . read ( ) ; if ( ( queryLog == null && ! queryLogs . isEmpty ( ) ) || queryLogs . size ( ) >= docPerReq ) { final SuggestIndexResponse res = indexFromQueryLog ( queryLogs . toArray ( new QueryLog [ queryLogs . size ( ) ] ) ) ; errors . addAll ( res . getErrors ( ) ) ; numberOfSuggestDocs += res . getNumberOfSuggestDocs ( ) ; numberOfInputDocs += res . getNumberOfInputDocs ( ) ; queryLogs . clear ( ) ; Thread . sleep ( requestInterval ) ; } } deferred . resolve ( new SuggestIndexResponse ( numberOfSuggestDocs , numberOfInputDocs , errors , System . currentTimeMillis ( ) - start ) ) ; } catch ( final Throwable t ) { deferred . reject ( t ) ; } finally { queryLogReader . close ( ) ; } } ) ; return deferred . promise ( ) ; }
TODO replace queryLogReader with lambda reader