Search in sources :

Example 1 with ClearBacklogCallback

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

the class ManagedCursorImpl method clearBacklog.

@Override
public void clearBacklog() throws InterruptedException, ManagedLedgerException {
    class Result {

        ManagedLedgerException exception = null;
    }
    final Result result = new Result();
    final CountDownLatch counter = new CountDownLatch(1);
    asyncClearBacklog(new ClearBacklogCallback() {

        @Override
        public void clearBacklogComplete(Object ctx) {
            counter.countDown();
        }

        @Override
        public void clearBacklogFailed(ManagedLedgerException exception, Object ctx) {
            result.exception = exception;
            counter.countDown();
        }
    }, null);
    if (!counter.await(ManagedLedgerImpl.AsyncOperationTimeoutSeconds, TimeUnit.SECONDS)) {
        throw new ManagedLedgerException("Timeout during clear backlog operation");
    }
    if (result.exception != null) {
        throw result.exception;
    }
}
Also used : ClearBacklogCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ClearBacklogCallback) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with ClearBacklogCallback

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

the class PersistentReplicator method clearBacklog.

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

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

        @Override
        public void clearBacklogFailed(ManagedLedgerException exception, Object ctx) {
            log.error("[{}][{} -> {}] Failed to clear backlog", topicName, localCluster, remoteCluster, 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)

Example 3 with ClearBacklogCallback

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

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)

Example 4 with ClearBacklogCallback

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

the class PersistentReplicator method clearBacklog.

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

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

        @Override
        public void clearBacklogFailed(ManagedLedgerException exception, Object ctx) {
            log.error("[{}][{} -> {}] Failed to clear backlog", topicName, localCluster, remoteCluster, 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)

Example 5 with ClearBacklogCallback

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

the class ManagedCursorImpl method clearBacklog.

@Override
public void clearBacklog() throws InterruptedException, ManagedLedgerException {
    class Result {

        ManagedLedgerException exception = null;
    }
    final Result result = new Result();
    final CountDownLatch counter = new CountDownLatch(1);
    asyncClearBacklog(new ClearBacklogCallback() {

        @Override
        public void clearBacklogComplete(Object ctx) {
            counter.countDown();
        }

        @Override
        public void clearBacklogFailed(ManagedLedgerException exception, Object ctx) {
            result.exception = exception;
            counter.countDown();
        }
    }, null);
    if (!counter.await(ManagedLedgerImpl.AsyncOperationTimeoutSeconds, TimeUnit.SECONDS)) {
        throw new ManagedLedgerException("Timeout during clear backlog operation");
    }
    if (result.exception != null) {
        throw result.exception;
    }
}
Also used : ClearBacklogCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ClearBacklogCallback) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) ManagedLedgerImpl.createManagedLedgerException(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.createManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch)

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