@Override public void asyncAddEntry(byte[] data, int offset, int length, AsyncCallback.AddCallback callback, Object ctx) { lh.asyncAddEntry(data, offset, length, callback, ctx); }
public void initiate() { ByteBuf duplicateBuffer = data.retainedDuplicate(); // duplicatedBuffer has refCnt=1 at this point lastInitTime = System.nanoTime(); ledger.asyncAddEntry(duplicateBuffer, this, ctx); // Internally, asyncAddEntry() is refCnt neutral to respect to the passed buffer and it will keep a ref on it // until is done using it. We need to release this buffer here to balance the 1 refCnt added at the creation // time. duplicateBuffer.release(); }
lh.asyncAddEntry(pi.toByteArray(), (rc, lh1, entryId, ctx) -> { if (rc == BKException.Code.OK) { if (log.isDebugEnabled()) {
@Override public void asyncAddEntry(ByteBuf entry, AsyncCallback.AddCallback callback, Object ctx) { lh.asyncAddEntry(entry, callback, ctx); }
/** * Add entry asynchronously to an open ledger. * * @param data * array of bytes to be written * @param cb * object implementing callbackinterface * @param ctx * some control object */ public void asyncAddEntry(final byte[] data, final AddCallback cb, final Object ctx) { asyncAddEntry(data, 0, data.length, cb, ctx); }
@Override public void writeEntry(long ledgerID, long entryID, byte[] data, Consumer<Integer> cb) { LedgerHandle handle; handle = openHandles.get(ledgerID); if (handle == null) { cb.accept(BKException.Code.WriteException); return; } handle.asyncAddEntry(entryID, data, (rc, lh, entryId, ctx) -> { cb.accept(rc); }, null); }
public void initiate() { ByteBuf duplicateBuffer = RecyclableDuplicateByteBuf.create(data); // duplicatedBuffer has refCnt=1 at this point ledger.asyncAddEntry(duplicateBuffer, this, ctx); // Internally, asyncAddEntry() is refCnt neutral to respect to the passed buffer and it will keep a ref on it // until is done using it. We need to release this buffer here to balance the 1 refCnt added at the creation // time. duplicateBuffer.release(); }
public void initiate() { ByteBuf duplicateBuffer = data.retainedDuplicate(); // duplicatedBuffer has refCnt=1 at this point ledger.asyncAddEntry(duplicateBuffer, this, ctx); // Internally, asyncAddEntry() is refCnt neutral to respect to the passed buffer and it will keep a ref on it // until is done using it. We need to release this buffer here to balance the 1 refCnt added at the creation // time. duplicateBuffer.release(); }
/** * Add entry asynchronously to an open ledger, using an offset and range. * * @param data * array of bytes to be written * @param offset * offset from which to take bytes from data * @param length * number of bytes to take from data * @param cb * object implementing callbackinterface * @param ctx * some control object * @throws ArrayIndexOutOfBoundsException if offset or length is negative or * offset and length sum to a value higher than the length of data. */ public void asyncAddEntry(final byte[] data, final int offset, final int length, final AddCallback cb, final Object ctx) { if (offset < 0 || length < 0 || (offset + length) > data.length) { throw new ArrayIndexOutOfBoundsException( "Invalid values for offset(" + offset + ") or length(" + length + ")"); } asyncAddEntry(Unpooled.wrappedBuffer(data, offset, length), cb, ctx); }
/** * {@inheritDoc} */ @Override public CompletableFuture<Long> appendAsync(ByteBuf data) { SyncAddCallback callback = new SyncAddCallback(); asyncAddEntry(data, callback, null); return callback; }
private CompletableFuture<Void> addToCompactedLedger(LedgerHandle lh, RawMessage m) { CompletableFuture<Void> bkf = new CompletableFuture<>(); ByteBuf serialized = m.serialize(); lh.asyncAddEntry(serialized, (rc, ledger, eid, ctx) -> { if (rc != BKException.Code.OK) { bkf.completeExceptionally(BKException.create(rc)); } else { bkf.complete(null); } }, null); serialized.release(); return bkf; }
@NotNull private CompletableFuture<Long> addEntry(LedgerHandle ledgerHandle, SchemaStorageFormat.SchemaEntry entry) { final CompletableFuture<Long> future = new CompletableFuture<>(); ledgerHandle.asyncAddEntry(entry.toByteArray(), (rc, handle, entryId, ctx) -> { if (rc != BKException.Code.OK) { future.completeExceptionally(bkException("Failed to add entry", rc, ledgerHandle.getId(), -1)); } else { future.complete(entryId); } }, null ); return future; }
/** * Add entry synchronously to an open ledger. * * @param data * array of bytes to be written to the ledger * @param offset * offset from which to take bytes from data * @param length * number of bytes to take from data * @return the entryId of the new inserted entry */ public long addEntry(byte[] data, int offset, int length) throws InterruptedException, BKException { if (LOG.isDebugEnabled()) { LOG.debug("Adding entry {}", data); } SyncAddCallback callback = new SyncAddCallback(); asyncAddEntry(data, offset, length, callback, null); return SyncCallbackUtils.waitForResult(callback); }
public CompletableFuture<LogSequenceNumber> writeEntry(LogEntry edit) { // BK will release the buffer after handling the entry ByteBuf serialize = edit.serializeAsByteBuf(); CompletableFuture<LogSequenceNumber> res = new CompletableFuture<>(); this.out.asyncAddEntry(serialize, (int rc, LedgerHandle lh, long offset, Object o) -> { if (rc == BKException.Code.OK) { if (edit.type != LogEntryType.NOOP) { // do not take into account NOOPs lastApplicationWriteTs = System.currentTimeMillis(); } res.complete(new LogSequenceNumber(lh.getId(), offset)); } else { errorOccurredDuringWrite = true; res.completeExceptionally(new LogNotAvailableException(BKException.create(rc))); } }, null); return res; }
w.getWriteLedger().ledger.asyncAddEntry(w.data.array(), w.data.arrayOffset(), w.data.getLength(), this::addCallback, w); } catch (Throwable ex) {
lh.asyncAddEntry(pi.toByteArray(), (rc, lh1, entryId, ctx) -> { if (rc == BKException.Code.OK) { if (log.isDebugEnabled()) {
lh.asyncAddEntry(pi.toByteArray(), (rc, lh1, entryId, ctx) -> { if (rc == BKException.Code.OK) { if (log.isDebugEnabled()) {