log.debug(" Read entry {} from ledger {} for cursor {}", lastEntry, ledgerId, cursorName); MLDataFormats.PositionInfo positionInfo = MLDataFormats.PositionInfo.parseFrom(ledgerEntry.getEntry()); lastAckedMessagePosition = new PositionImpl(positionInfo); if (log.isDebugEnabled()) {
while (entries.hasMoreElements()) { LedgerEntry entry = entries.nextElement(); dumpedEntries.add(new String(entry.getEntry(), UTF_8));
@Test public void simpleTest() throws Exception { LedgerHandle ledger = bkc.createLedger(DigestType.MAC, SECRET.getBytes()); long ledgerId = ledger.getId(); log.info("Writing to ledger: {}", ledgerId); for (int i = 0; i < 10; i++) { String content = "entry-" + i; ledger.addEntry(content.getBytes(Encoding)); } ledger.close(); ledger = bkc.openLedger(ledgerId, DigestType.MAC, SECRET.getBytes()); Enumeration<LedgerEntry> entries = ledger.readEntries(0, 9); while (entries.hasMoreElements()) { LedgerEntry entry = entries.nextElement(); String content = new String(entry.getEntry(), Encoding); log.info("Entry {} lenght={} content='{}'", entry.getEntryId(), entry.getLength(), content); } ledger.close(); }
LedgerEntry entry = seq.nextElement(); PositionInfo positionInfo; positionInfo = PositionInfo.parseFrom(entry.getEntry()); individualDeletedMessagesCount.set(positionInfo.getIndividualDeletedMessagesCount()); } catch (Exception e) {
/** * Format the entry into a readable format. * * @param entry * ledgerentry to print * @param printMsg * Whether printing the message body */ private void formatEntry(LedgerEntry entry, boolean printMsg) { long ledgerId = entry.getLedgerId(); long entryId = entry.getEntryId(); long entrySize = entry.getLength(); System.out.println("--------- Lid=" + ledgerIdFormatter.formatLedgerId(ledgerId) + ", Eid=" + entryId + ", EntrySize=" + entrySize + " ---------"); if (printMsg) { entryFormatter.formatEntry(entry.getEntry()); } }
PositionInfo positionInfo; try { positionInfo = PositionInfo.parseFrom(entry.getEntry()); } catch (InvalidProtocolBufferException e) { callback.operationFailed(new ManagedLedgerException(e));
log.debug(" Read entry {} from ledger {} for cursor {}", lastEntry, ledgerId, cursorName); MLDataFormats.PositionInfo positionInfo = MLDataFormats.PositionInfo.parseFrom(ledgerEntry.getEntry()); lastAckedMessagePosition = new PositionImpl(positionInfo); if (log.isDebugEnabled()) {
while (entries.hasMoreElements()) { LedgerEntry entry = entries.nextElement(); assertEquals("hello world", new String(entry.getEntry(), UTF_8)); ++i;
log.debug(" Read entry {} from ledger {} for cursor {}", lastEntry, ledgerId, cursorName); MLDataFormats.PositionInfo positionInfo = MLDataFormats.PositionInfo.parseFrom(ledgerEntry.getEntry()); lastAckedMessagePosition = new PositionImpl(positionInfo); if (log.isDebugEnabled()) {
while (entries.hasMoreElements()) { LedgerEntry entry = entries.nextElement(); assertEquals("hello world", new String(entry.getEntry(), UTF_8)); ++i;
byte[] data = entry.getEntry();
static CompletableFuture<SchemaStorageFormat.SchemaEntry> parseSchemaEntry(LedgerEntry ledgerEntry) { CompletableFuture<SchemaStorageFormat.SchemaEntry> result = new CompletableFuture<>(); try { result.complete(SchemaStorageFormat.SchemaEntry.parseFrom(ledgerEntry.getEntry())); } catch (IOException e) { result.completeExceptionally(e); } return result; }
while (entries.hasNext()) { LedgerEntry entry = entries.next(); output.put(Long.valueOf(entry.getEntryId()).toString(), new String(entry.getEntry(), US_ASCII));
@Override public void readEntries( long ledgerID, long firstEntryID, long lastEntryID, BiConsumer<Integer, ArrayList<byte[]>> cb) { client.asyncOpenLedgerNoRecovery(ledgerID, BookKeeper.DigestType.CRC32, new byte[0], (rc, lh, ctx) -> { if (rc != 0) { cb.accept(rc, null); return; } System.out.format("Got handle for read %d -> %d on ledger %d%n", firstEntryID, lastEntryID, ledgerID); lh.asyncReadEntries(firstEntryID, lastEntryID, (rc1, lh1, seq, ctx1) -> { System.out.format("Read cb %d -> %d on ledger %d%n", firstEntryID, lastEntryID, ledgerID); ArrayList<byte[]> results = new ArrayList<>(); if (rc1 == 0) { while (seq.hasMoreElements()) { results.add(seq.nextElement().getEntry()); } System.out.format("About to close handle for read %d -> %d on ledger %d%n", firstEntryID, lastEntryID, ledgerID); } lh.asyncClose((rc2, lh2, ctx2) -> { System.out.format("Closed handle for read %d -> %d on ledger %d result %d%n", firstEntryID, lastEntryID, ledgerID, rc2); cb.accept(rc1 == 0 ? rc2 : rc1, results); }, null); }, null); }, null); } }
long entryId = e.getEntryId(); byte[] entryData = e.getEntry(); LogEntry statusEdit = LogEntry.deserialize(entryData);
/** * refill the buffer, we need to read more bytes. * * @return if we can refill or not */ private synchronized boolean refill() throws IOException { bytebuff.clear(); if (!ledgerSeq.hasMoreElements() && lastEntry >= lh.getLastAddConfirmed()) { return false; } if (!ledgerSeq.hasMoreElements()) { // do refill long last = Math.min(lastEntry + increment, lh.getLastAddConfirmed()); try { ledgerSeq = lh.readEntries(lastEntry + 1, last); } catch (BKException bk) { IOException ie = new IOException(bk.getMessage()); ie.initCause(bk); throw ie; } catch (InterruptedException ie) { Thread.currentThread().interrupt(); } lastEntry = last; } LedgerEntry le = ledgerSeq.nextElement(); bbytes = le.getEntry(); bytebuff = ByteBuffer.wrap(bbytes); return true; }
while (entries.hasMoreElements()) { LedgerEntry entry = entries.nextElement(); String actualMsg = new String(entry.getEntry(), UTF_8); String expectedMsg = "entry-" + (i++); if (!expectedMsg.equals(actualMsg)) {
byte[] data = entry.getEntry(); final long dataLength = data.length; numEntriesRead.inc();
PositionInfo positionInfo; try { positionInfo = PositionInfo.parseFrom(entry.getEntry()); } catch (InvalidProtocolBufferException e) { callback.operationFailed(new ManagedLedgerException(e));
PositionInfo positionInfo; try { positionInfo = PositionInfo.parseFrom(entry.getEntry()); } catch (InvalidProtocolBufferException e) { callback.operationFailed(new ManagedLedgerException(e));