public static EntryImpl create(LedgerEntry ledgerEntry) { EntryImpl entry = RECYCLER.get(); entry.ledgerId = ledgerEntry.getLedgerId(); entry.entryId = ledgerEntry.getEntryId(); entry.data = ledgerEntry.getEntryBuffer(); entry.data.retain(); entry.setRefCnt(1); return entry; }
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; }
public static LedgerEntryImpl duplicate(LedgerEntry entry) { return create( entry.getLedgerId(), entry.getEntryId(), entry.getLength(), entry.getEntryBuffer().retainedSlice()); }
/** * {@inheritDoc} */ @Override public LedgerEntry getEntry(long entryId) { checkNotNull(entries, "entries has been recycled"); long firstId = entries.get(0).getEntryId(); long lastId = entries.get(entries.size() - 1).getEntryId(); if (entryId < firstId || entryId > lastId) { throw new IndexOutOfBoundsException("required index: " + entryId + " is out of bounds: [ " + firstId + ", " + lastId + " ]."); } return entries.get((int) (entryId - firstId)); }
MockOffloadReadHandle(ReadHandle toCopy) throws Exception { id = toCopy.getId(); long lac = toCopy.getLastAddConfirmed(); try (LedgerEntries entries = toCopy.read(0, lac)) { for (LedgerEntry e : entries) { this.entries.add(e.getEntryBuffer().retainedSlice()); } } metadata = new MockMetadata(toCopy.getLedgerMetadata()); }
/** * {@inheritDoc} */ @Override public void close() { this.lac = -1L; if (null != entry) { entry.close(); entry = null; } recycleHandle.recycle(this); } }
@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 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); }
public static EntryImpl create(LedgerEntry ledgerEntry) { EntryImpl entry = RECYCLER.get(); entry.ledgerId = ledgerEntry.getLedgerId(); entry.entryId = ledgerEntry.getEntryId(); entry.data = ledgerEntry.getEntryBuffer(); entry.data.retain(); entry.setRefCnt(1); return entry; }