void checkReadCompletion() { if (entries.size() < count && cursor.hasMoreEntries()) { // We still have more entries to read from the next ledger, schedule a new async operation if (nextReadPosition.getLedgerId() != readPosition.getLedgerId()) { cursor.ledger.startReadOperationOnLedger(nextReadPosition); } // Schedule next read in a different thread cursor.ledger.getExecutor().execute(safeRun(() -> { readPosition = cursor.ledger.startReadOperationOnLedger(nextReadPosition); cursor.ledger.asyncReadEntries(OpReadEntry.this); })); } else { // The reading was already completed, release resources and trigger callback try { cursor.readOperationCompleted(); } finally { cursor.ledger.getExecutor().executeOrdered(cursor.ledger.getName(), safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle(); })); } } }
@Override public void readEntriesFailed(ManagedLedgerException status, Object ctx) { cursor.readOperationCompleted(); if (!entries.isEmpty()) { // There were already some entries that were read before, we can return them cursor.ledger.getExecutor().submit(safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle(); })); } else { if (!(status instanceof TooManyRequestsException)) { log.warn("[{}][{}] read failed from ledger at position:{} : {}", cursor.ledger.getName(), cursor.getName(), readPosition, status.getMessage()); } else { if (log.isDebugEnabled()) { log.debug("[{}][{}] read throttled failed from ledger at position:{}", cursor.ledger.getName(), cursor.getName(), readPosition); } } callback.readEntriesFailed(status, ctx); cursor.ledger.mbean.recordReadEntriesError(); recycle(); } }
void checkReadCompletion() { if (entries.size() < count && cursor.hasMoreEntries()) { // We still have more entries to read from the next ledger, schedule a new async operation if (nextReadPosition.getLedgerId() != readPosition.getLedgerId()) { cursor.ledger.startReadOperationOnLedger(nextReadPosition); } // Schedule next read in a different thread cursor.ledger.getExecutor().submit(safeRun(() -> { readPosition = cursor.ledger.startReadOperationOnLedger(nextReadPosition); cursor.ledger.asyncReadEntries(OpReadEntry.this); })); } else { // The reading was already completed, release resources and trigger callback cursor.readOperationCompleted(); cursor.ledger.getExecutor().submit(safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle(); })); } }
void checkReadCompletion() { if (entries.size() < count && cursor.hasMoreEntries()) { // We still have more entries to read from the next ledger, schedule a new async operation if (nextReadPosition.getLedgerId() != readPosition.getLedgerId()) { cursor.ledger.startReadOperationOnLedger(nextReadPosition); } // Schedule next read in a different thread cursor.ledger.getExecutor().execute(safeRun(() -> { readPosition = cursor.ledger.startReadOperationOnLedger(nextReadPosition); cursor.ledger.asyncReadEntries(OpReadEntry.this); })); } else { // The reading was already completed, release resources and trigger callback try { cursor.readOperationCompleted(); } finally { cursor.ledger.getExecutor().executeOrdered(cursor.ledger.getName(), safeRun(() -> { callback.readEntriesComplete(entries, ctx); recycle(); })); } } }