Java Code Examples for org.apache.bookkeeper.client.LedgerHandle#asyncClose()
The following examples show how to use
org.apache.bookkeeper.client.LedgerHandle#asyncClose() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TwoPhaseCompactor.java From pulsar with Apache License 2.0 | 5 votes |
private CompletableFuture<Void> closeLedger(LedgerHandle lh) { CompletableFuture<Void> bkf = new CompletableFuture<>(); lh.asyncClose((rc, ledger, ctx) -> { if (rc != BKException.Code.OK) { bkf.completeExceptionally(BKException.create(rc)); } else { bkf.complete(null); } }, null); return bkf; }
Example 2
Source File: BookkeeperSchemaStorage.java From pulsar with Apache License 2.0 | 5 votes |
@NotNull private CompletableFuture<Void> closeLedger(LedgerHandle ledgerHandle) { CompletableFuture<Void> future = new CompletableFuture<>(); ledgerHandle.asyncClose((rc, handle, ctx) -> { if (rc != BKException.Code.OK) { future.completeExceptionally(bkException("Failed to close ledger", rc, ledgerHandle.getId(), -1)); } else { future.complete(null); } }, null); return future; }
Example 3
Source File: ManagedLedgerImpl.java From pulsar with Apache License 2.0 | 4 votes |
@Override public synchronized void asyncTerminate(TerminateCallback callback, Object ctx) { if (state == State.Fenced) { callback.terminateFailed(new ManagedLedgerFencedException(), ctx); return; } else if (state == State.Terminated) { if (log.isDebugEnabled()) { log.debug("[{}] Ignoring request to terminate an already terminated managed ledger", name); } callback.terminateComplete(lastConfirmedEntry, ctx); return; } log.info("[{}] Terminating managed ledger", name); state = State.Terminated; LedgerHandle lh = currentLedger; if (log.isDebugEnabled()) { log.debug("[{}] Closing current writing ledger {}", name, lh.getId()); } mbean.startDataLedgerCloseOp(); lh.asyncClose((rc, lh1, ctx1) -> { if (log.isDebugEnabled()) { log.debug("[{}] Close complete for ledger {}: rc = {}", name, lh.getId(), rc); } mbean.endDataLedgerCloseOp(); if (rc != BKException.Code.OK) { callback.terminateFailed(createManagedLedgerException(rc), ctx); } else { lastConfirmedEntry = new PositionImpl(lh.getId(), lh.getLastAddConfirmed()); // Store the new state in metadata store.asyncUpdateLedgerIds(name, getManagedLedgerInfo(), ledgersStat, new MetaStoreCallback<Void>() { @Override public void operationComplete(Void result, Stat stat) { ledgersStat = stat; log.info("[{}] Terminated managed ledger at {}", name, lastConfirmedEntry); callback.terminateComplete(lastConfirmedEntry, ctx); } @Override public void operationFailed(MetaStoreException e) { log.error("[{}] Failed to terminate managed ledger: {}", name, e.getMessage()); callback.terminateFailed(new ManagedLedgerException(e), ctx); } }); } }, null); }
Example 4
Source File: ManagedLedgerImpl.java From pulsar with Apache License 2.0 | 4 votes |
@Override public synchronized void asyncClose(final CloseCallback callback, final Object ctx) { State state = STATE_UPDATER.get(this); if (state == State.Fenced) { factory.close(this); callback.closeFailed(new ManagedLedgerFencedException(), ctx); return; } else if (state == State.Closed) { if (log.isDebugEnabled()) { log.debug("[{}] Ignoring request to close a closed managed ledger", name); } callback.closeComplete(ctx); return; } log.info("[{}] Closing managed ledger", name); factory.close(this); STATE_UPDATER.set(this, State.Closed); LedgerHandle lh = currentLedger; if (lh == null) { // No ledger to close, proceed with next step closeAllCursors(callback, ctx); return; } if (log.isDebugEnabled()) { log.debug("[{}] Closing current writing ledger {}", name, lh.getId()); } mbean.startDataLedgerCloseOp(); lh.asyncClose((rc, lh1, ctx1) -> { if (log.isDebugEnabled()) { log.debug("[{}] Close complete for ledger {}: rc = {}", name, lh.getId(), rc); } mbean.endDataLedgerCloseOp(); if (rc != BKException.Code.OK) { callback.closeFailed(createManagedLedgerException(rc), ctx); return; } closeAllCursors(callback, ctx); }, null); if (this.timeoutTask != null) { this.timeoutTask.cancel(false); } }