throw new NuxeoException("Timed out scrollId"); cursorResult.touch(); List<R> results = new ArrayList<>(cursorResult.getBatchSize()); synchronized (cursorResult) { if (!cursorResult.hasNext()) { unregisterCursor(scrollId); return emptyResult(); while (results.size() < cursorResult.getBatchSize()) { if (!cursorResult.hasNext()) { cursorResult.close(); break; } else { O obj = cursorResult.next(); R result = extractor.apply(obj); if (result == null) {
/** * Registers the input {@link C} and generates a new <code>scrollId</code> to associate with. * * @return the scrollId associated to the cursor. */ public String registerCursor(C cursor, int batchSize, int keepAliveSeconds) { return registerCursorResult(new CursorResult<>(cursor, batchSize, keepAliveSeconds)); }
protected boolean isScrollTimedOut(String scrollId, CursorResult<C, O> cursorResult) { if (cursorResult.timedOut()) { if (unregisterCursor(scrollId)) { log.warn("Scroll '" + scrollId + "' timed out"); } return true; } return false; }
/** * Unregisters cursor associated to the input <code>scrollId</code>. * * @param scrollId The scoll id of {@link CursorResult} to unregister * @return Whether or not the cursor was unregistered. */ public boolean unregisterCursor(String scrollId) { CursorResult<C, O> cursorResult = cursorResults.remove(scrollId); if (cursorResult != null) { cursorResult.close(); return true; } return false; }
@Override public LogEntry next() { if (cursor != null && !cursor.hasNext() && !end) { // try to run a next scroll runNextPage(); } return super.next(); }
/** * Clear and close all cursors owned by this service. */ public void clear() { Iterator<CursorResult<C, O>> values = cursorResults.values().iterator(); while (values.hasNext()) { values.next().close(); values.remove(); } }
@Override public SearchHit next() { if (cursor != null && !cursor.hasNext() && !end) { // try to run a next scroll runNextScroll(); } return super.next(); }
@Override public void close() { end = true; // Call super close to clear cursor super.close(); }
/** * Registers the input {@link C} associated to the input <code>scrollId</code>. * * @return the scrollId associated to the cursor. */ public String registerCursor(String scrollId, C cursor, int batchSize, int keepAliveSeconds) { return registerCursorResult(scrollId, new CursorResult<>(cursor, batchSize, keepAliveSeconds)); }
@Override public void close() { ClearScrollRequest request = new ClearScrollRequest(); request.addScrollId(scrollId); esClient.clearScroll(request); end = true; // Call super close to clear cursor super.close(); }