/** {@inheritDoc} */ @Override public FijiResult<T> next() { final State oldState = mState.get(); Preconditions.checkState(oldState == State.OPEN, "Cannot get element from FijiResultScanner in state %s.", oldState); final Result next = mNextResult; if (null == next) { throw new NoSuchElementException(); } mNextResult = getNextResult(); try { return HBaseFijiResult.create( mEidFactory.getEntityIdFromHBaseRowKey(next.getRow()), mRequest, next, mTable, mLayout, mColumnNameTranslator, mDecoderProvider); } catch (IOException e) { throw new FijiIOException(e); } }
/** * Get the next HBase Result from the ResultScanner, reopening the scanner if necessary. * * @return the next HBase Result from the ResultScanner. */ private Result getNextResult() { for (int retries = 0; retries < MAX_RETRIES_ON_TIMEOUT; ++retries) { try { return mResultScanner.next(); } catch (LeaseException le) { reopenScanner(); } catch (ScannerTimeoutException ste) { reopenScanner(); } catch (IOException ioe) { throw new FijiIOException(ioe); } } throw new FijiIOException(String.format( "Unable to get Result from HBase scanner after %d attempts.", MAX_RETRIES_ON_TIMEOUT)); }
/** * Reopen the ResultScanner if mReopenScannerOnTimeout is true. The new ResultScanner should be * set to start where the old scanner left off. */ private void reopenScanner() { if (mReopenScannerOnTimeout) { LOG.debug("HBase scanner timed out: closing an reopening a new scanner."); final byte[] nextRow = (null == mNextResult) ? mScan.getStartRow() : leastGreaterThan(mNextResult.getRow()); mScan.setStartRow(nextRow); mResultScanner.close(); try { mResultScanner = mHTable.getScanner(mScan); } catch (IOException ioe) { throw new FijiIOException(ioe); } } else { throw new FijiIOException("HBase scanner timed out with automatic reopening disabled."); } }
return new HBaseFijiResultScanner<T>( request, mTable,
throw re; mNextResult = getNextResult();