use of org.apache.bookkeeper.mledger.AsyncCallbacks.TerminateCallback in project incubator-pulsar by apache.
the class PersistentTopic method terminate.
public CompletableFuture<MessageId> terminate() {
CompletableFuture<MessageId> future = new CompletableFuture<>();
ledger.asyncTerminate(new TerminateCallback() {
@Override
public void terminateComplete(Position lastCommittedPosition, Object ctx) {
producers.forEach(Producer::disconnect);
subscriptions.forEach((name, sub) -> sub.topicTerminated());
PositionImpl lastPosition = (PositionImpl) lastCommittedPosition;
MessageId messageId = new MessageIdImpl(lastPosition.getLedgerId(), lastPosition.getEntryId(), -1);
log.info("[{}] Topic terminated at {}", getName(), messageId);
future.complete(messageId);
}
@Override
public void terminateFailed(ManagedLedgerException exception, Object ctx) {
future.completeExceptionally(exception);
}
}, null);
return future;
}
use of org.apache.bookkeeper.mledger.AsyncCallbacks.TerminateCallback in project incubator-pulsar by apache.
the class ManagedLedgerImpl method terminate.
@Override
public Position terminate() throws InterruptedException, ManagedLedgerException {
final CountDownLatch counter = new CountDownLatch(1);
class Result {
Position lastPosition = null;
ManagedLedgerException exception = null;
}
final Result result = new Result();
asyncTerminate(new TerminateCallback() {
@Override
public void terminateComplete(Position lastPosition, Object ctx) {
result.lastPosition = lastPosition;
counter.countDown();
}
@Override
public void terminateFailed(ManagedLedgerException exception, Object ctx) {
result.exception = exception;
counter.countDown();
}
}, null);
if (!counter.await(AsyncOperationTimeoutSeconds, TimeUnit.SECONDS)) {
throw new ManagedLedgerException("Timeout during managed ledger terminate");
}
if (result.exception != null) {
log.error("[{}] Error terminating managed ledger", name, result.exception);
throw result.exception;
}
return result.lastPosition;
}
Aggregations