Search in sources :

Example 1 with UpdatePropertiesCallback

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

the class ManagedLedgerImpl method updateProperties.

private void updateProperties(Map<String, String> properties, boolean isDelete, String deleteKey) throws InterruptedException, ManagedLedgerException {
    final CountDownLatch latch = new CountDownLatch(1);
    class Result {

        ManagedLedgerException exception = null;
    }
    final Result result = new Result();
    this.asyncUpdateProperties(properties, isDelete, deleteKey, new UpdatePropertiesCallback() {

        @Override
        public void updatePropertiesComplete(Map<String, String> properties, Object ctx) {
            latch.countDown();
        }

        @Override
        public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) {
            result.exception = exception;
            latch.countDown();
        }
    }, null);
    if (!latch.await(AsyncOperationTimeoutSeconds, TimeUnit.SECONDS)) {
        throw new ManagedLedgerException("Timeout during update managedLedger's properties");
    }
    if (result.exception != null) {
        log.error("[{}] Update managedLedger's properties failed", name, result.exception);
        throw result.exception;
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) UpdatePropertiesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.UpdatePropertiesCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with UpdatePropertiesCallback

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

the class PersistentTopic method setTopicEpoch.

@Override
protected CompletableFuture<Long> setTopicEpoch(long newEpoch) {
    CompletableFuture<Long> future = new CompletableFuture<>();
    ledger.asyncSetProperty(TOPIC_EPOCH_PROPERTY_NAME, String.valueOf(newEpoch), new UpdatePropertiesCallback() {

        @Override
        public void updatePropertiesComplete(Map<String, String> properties, Object ctx) {
            log.info("[{}] Updated topic epoch to {}", getName(), newEpoch);
            future.complete(newEpoch);
        }

        @Override
        public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) {
            log.warn("[{}] Failed to update topic epoch to {}: {}", getName(), newEpoch, exception.getMessage());
            future.completeExceptionally(exception);
        }
    }, null);
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) UpdatePropertiesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.UpdatePropertiesCallback) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 3 with UpdatePropertiesCallback

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

the class PersistentTopic method setTopicEpoch.

@Override
protected CompletableFuture<Long> setTopicEpoch(long newEpoch) {
    CompletableFuture<Long> future = new CompletableFuture<>();
    ledger.asyncSetProperty(TOPIC_EPOCH_PROPERTY_NAME, String.valueOf(newEpoch), new UpdatePropertiesCallback() {

        @Override
        public void updatePropertiesComplete(Map<String, String> properties, Object ctx) {
            log.info("[{}] Updated topic epoch to {}", getName(), newEpoch);
            future.complete(newEpoch);
        }

        @Override
        public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) {
            log.warn("[{}] Failed to update topic epoch to {}: {}", getName(), newEpoch, exception.getMessage());
            future.completeExceptionally(exception);
        }
    }, null);
    return future;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) UpdatePropertiesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.UpdatePropertiesCallback) AtomicLong(java.util.concurrent.atomic.AtomicLong)

Example 4 with UpdatePropertiesCallback

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

the class ManagedLedgerImpl method updateProperties.

private void updateProperties(Map<String, String> properties, boolean isDelete, String deleteKey) throws InterruptedException, ManagedLedgerException {
    final CountDownLatch latch = new CountDownLatch(1);
    class Result {

        ManagedLedgerException exception = null;
    }
    final Result result = new Result();
    this.asyncUpdateProperties(properties, isDelete, deleteKey, new UpdatePropertiesCallback() {

        @Override
        public void updatePropertiesComplete(Map<String, String> properties, Object ctx) {
            latch.countDown();
        }

        @Override
        public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) {
            result.exception = exception;
            latch.countDown();
        }
    }, null);
    if (!latch.await(AsyncOperationTimeoutSeconds, TimeUnit.SECONDS)) {
        throw new ManagedLedgerException("Timeout during update managedLedger's properties");
    }
    if (result.exception != null) {
        log.error("[{}] Update managedLedger's properties failed", name, result.exception);
        throw result.exception;
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) UpdatePropertiesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.UpdatePropertiesCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 5 with UpdatePropertiesCallback

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

the class ManagedLedgerImpl method updateProperties.

private void updateProperties(Map<String, String> properties, boolean isDelete, String deleteKey) throws InterruptedException, ManagedLedgerException {
    final CountDownLatch latch = new CountDownLatch(1);
    class Result {

        ManagedLedgerException exception = null;
    }
    final Result result = new Result();
    this.asyncUpdateProperties(properties, isDelete, deleteKey, new UpdatePropertiesCallback() {

        @Override
        public void updatePropertiesComplete(Map<String, String> properties, Object ctx) {
            latch.countDown();
        }

        @Override
        public void updatePropertiesFailed(ManagedLedgerException exception, Object ctx) {
            result.exception = exception;
            latch.countDown();
        }
    }, null);
    if (!latch.await(AsyncOperationTimeoutSeconds, TimeUnit.SECONDS)) {
        throw new ManagedLedgerException("Timeout during update managedLedger's properties");
    }
    if (result.exception != null) {
        log.error("[{}] Update managedLedger's properties failed", name, result.exception);
        throw result.exception;
    }
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) UpdatePropertiesCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.UpdatePropertiesCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

UpdatePropertiesCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.UpdatePropertiesCallback)6 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)6 CompletableFuture (java.util.concurrent.CompletableFuture)3 CountDownLatch (java.util.concurrent.CountDownLatch)3 AtomicLong (java.util.concurrent.atomic.AtomicLong)3