Search in sources :

Example 6 with ClearBacklogCallback

use of org.apache.bookkeeper.mledger.AsyncCallbacks.ClearBacklogCallback in project incubator-pulsar by apache.

the class PersistentSubscription method clearBacklog.

@Override
public CompletableFuture<Void> clearBacklog() {
    CompletableFuture<Void> future = new CompletableFuture<>();
    if (log.isDebugEnabled()) {
        log.debug("[{}][{}] Backlog size before clearing: {}", topicName, subName, cursor.getNumberOfEntriesInBacklog());
    }
    cursor.asyncClearBacklog(new ClearBacklogCallback() {

        @Override
        public void clearBacklogComplete(Object ctx) {
            if (log.isDebugEnabled()) {
                log.debug("[{}][{}] Backlog size after clearing: {}", topicName, subName, cursor.getNumberOfEntriesInBacklog());
            }
            future.complete(null);
        }

        @Override
        public void clearBacklogFailed(ManagedLedgerException exception, Object ctx) {
            log.error("[{}][{}] Failed to clear backlog", topicName, subName, exception);
            future.completeExceptionally(exception);
        }
    }, null);
    return future;
}
Also used : ClearBacklogCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ClearBacklogCallback) CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException)

Aggregations

ClearBacklogCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.ClearBacklogCallback)6 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)6 CompletableFuture (java.util.concurrent.CompletableFuture)4 CountDownLatch (java.util.concurrent.CountDownLatch)2 ManagedLedgerException.getManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException)1 ManagedLedgerImpl.createManagedLedgerException (org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.createManagedLedgerException)1