/** * Add entry synchronously to an open ledger. * * @param data array of bytes to be written * @return the id of the newly appended entry */ default long append(ByteBuffer data) throws BKException, InterruptedException { return append(Unpooled.wrappedBuffer(data)); }
/** * Add an entry synchronously to an open ledger. * * @param data array of bytes to be written * @param offset the offset in the bytes array * @param length the length of the bytes to be appended * @return the entry id of this newly appended entry */ default long append(byte[] data, int offset, int length) throws BKException, InterruptedException { return append(Unpooled.wrappedBuffer(data, offset, length)); }
/** * Add an entry synchronously to an open ledger. * * @param data array of bytes to be written * @return the entry id of this newly appended entry */ default long append(byte[] data) throws BKException, InterruptedException { return append(Unpooled.wrappedBuffer(data)); }
@Override protected void run(BookKeeper bk, Flags flags) throws Exception { byte[] data = new byte[100]; // test data try (WriteHandle wh = result(bk.newCreateLedgerOp() .withEnsembleSize(flags.ensembleSize) .withWriteQuorumSize(flags.writeQuorumSize) .withAckQuorumSize(flags.ackQuorumSize) .withDigestType(DigestType.CRC32C) .withPassword(new byte[0]) .execute())) { System.out.println("Ledger ID: " + wh.getId()); long lastReport = System.nanoTime(); for (int i = 0; i < flags.numEntries; i++) { wh.append(data); if (TimeUnit.SECONDS.convert(System.nanoTime() - lastReport, TimeUnit.NANOSECONDS) > 1) { System.out.println(i + " entries written"); lastReport = System.nanoTime(); } } System.out.println(flags.numEntries + " entries written to ledger " + wh.getId()); } } }