@Override public void asyncReadEntry(ReadHandle lh, long firstEntry, long lastEntry, boolean isSlowestReader, final ReadEntriesCallback callback, Object ctx) { lh.readAsync(firstEntry, lastEntry).whenComplete( (ledgerEntries, exception) -> { if (exception != null) { callback.readEntriesFailed(createManagedLedgerException(exception), ctx); return; } List<Entry> entries = Lists.newArrayList(); long totalSize = 0; try { for (LedgerEntry e : ledgerEntries) { // Insert the entries at the end of the list (they will be unsorted for now) EntryImpl entry = EntryImpl.create(e); entries.add(entry); totalSize += entry.getLength(); } } finally { ledgerEntries.close(); } mlFactoryMBean.recordCacheMiss(entries.size(), totalSize); ml.mbean.addReadEntriesSample(entries.size(), totalSize); callback.readEntriesComplete(entries, null); }); }
private static ReadHandle getLedgerHandle() { final ReadHandle lh = mock(ReadHandle.class); final LedgerEntry ledgerEntry = mock(LedgerEntry.class, Mockito.CALLS_REAL_METHODS); doReturn(Unpooled.wrappedBuffer(new byte[10])).when(ledgerEntry).getEntryBuffer(); doReturn((long) 10).when(ledgerEntry).getLength(); doAnswer((invocation) -> { Object[] args = invocation.getArguments(); long firstEntry = (Long) args[0]; long lastEntry = (Long) args[1]; Vector<LedgerEntry> entries = new Vector<LedgerEntry>(); for (int i = 0; i <= (lastEntry - firstEntry); i++) { entries.add(ledgerEntry); } LedgerEntries ledgerEntries = mock(LedgerEntries.class); doAnswer((invocation2) -> entries.iterator()).when(ledgerEntries).iterator(); return CompletableFuture.completedFuture(ledgerEntries); }).when(lh).readAsync(anyLong(), anyLong()); return lh; }
ledgerEntries.close();
@Override public void onSuccess(LedgerEntries entries) { cb.readComplete( Code.OK, LedgerHandle.this, IteratorUtils.asEnumeration( Iterators.transform(entries.iterator(), le -> { LedgerEntry entry = new LedgerEntry((LedgerEntryImpl) le); le.close(); return entry; })), ctx); }
@Override public void onSuccess(LedgerEntries ledgerEntries) { long entryId = -1L; for (org.apache.bookkeeper.client.api.LedgerEntry entry : ledgerEntries) { resultList.add(new LedgerEntry((LedgerEntryImpl) entry)); entryId = entry.getEntryId(); } try { ledgerEntries.close(); } catch (Exception e) { // bk should not throw any exceptions here } ++entryId; readNext(entryId); }
@Override public void asyncReadEntry(ReadHandle lh, long firstEntry, long lastEntry, boolean isSlowestReader, final ReadEntriesCallback callback, Object ctx) { lh.readAsync(firstEntry, lastEntry).whenComplete( (ledgerEntries, exception) -> { if (exception != null) { callback.readEntriesFailed(createManagedLedgerException(exception), ctx); return; } List<Entry> entries = Lists.newArrayList(); long totalSize = 0; try { for (LedgerEntry e : ledgerEntries) { // Insert the entries at the end of the list (they will be unsorted for now) EntryImpl entry = EntryImpl.create(e); entries.add(entry); totalSize += entry.getLength(); } } finally { ledgerEntries.close(); } mlFactoryMBean.recordCacheMiss(entries.size(), totalSize); ml.mbean.addReadEntriesSample(entries.size(), totalSize); callback.readEntriesComplete(entries, null); }); }
ledgerEntries.close();