Search in sources :

Example 1 with OffloadCallback

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

the class PersistentTopic method triggerOffload.

public synchronized void triggerOffload(MessageIdImpl messageId) throws AlreadyRunningException {
    if (currentOffload.isDone()) {
        CompletableFuture<MessageIdImpl> promise = currentOffload = new CompletableFuture<>();
        log.info("[{}] Starting offload operation at messageId {}", topic, messageId);
        getManagedLedger().asyncOffloadPrefix(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId()), new OffloadCallback() {

            @Override
            public void offloadComplete(Position pos, Object ctx) {
                PositionImpl impl = (PositionImpl) pos;
                log.info("[{}] Completed successfully offload operation at messageId {}", topic, messageId);
                promise.complete(new MessageIdImpl(impl.getLedgerId(), impl.getEntryId(), -1));
            }

            @Override
            public void offloadFailed(ManagedLedgerException exception, Object ctx) {
                log.warn("[{}] Failed offload operation at messageId {}", topic, messageId, exception);
                promise.completeExceptionally(exception);
            }
        }, null);
    } else {
        throw new AlreadyRunningException("Offload already in progress");
    }
}
Also used : AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OffloadCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) BatchMessageIdImpl(org.apache.pulsar.client.impl.BatchMessageIdImpl) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl)

Example 2 with OffloadCallback

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

the class ManagedLedgerImpl method offloadPrefix.

@Override
public Position offloadPrefix(Position pos) throws InterruptedException, ManagedLedgerException {
    CompletableFuture<Position> promise = new CompletableFuture<>();
    asyncOffloadPrefix(pos, new OffloadCallback() {

        @Override
        public void offloadComplete(Position offloadedTo, Object ctx) {
            promise.complete(offloadedTo);
        }

        @Override
        public void offloadFailed(ManagedLedgerException e, Object ctx) {
            promise.completeExceptionally(e);
        }
    }, null);
    try {
        return promise.get(AsyncOperationTimeoutSeconds, TimeUnit.SECONDS);
    } catch (TimeoutException te) {
        throw new ManagedLedgerException("Timeout during managed ledger offload operation");
    } catch (ExecutionException e) {
        log.error("[{}] Error offloading. pos = {}", name, pos, e.getCause());
        throw ManagedLedgerException.getManagedLedgerException(e.getCause());
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OffloadCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 3 with OffloadCallback

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

the class ManagedLedgerImpl method offloadPrefix.

@Override
public Position offloadPrefix(Position pos) throws InterruptedException, ManagedLedgerException {
    CompletableFuture<Position> promise = new CompletableFuture<>();
    asyncOffloadPrefix(pos, new OffloadCallback() {

        @Override
        public void offloadComplete(Position offloadedTo, Object ctx) {
            promise.complete(offloadedTo);
        }

        @Override
        public void offloadFailed(ManagedLedgerException e, Object ctx) {
            promise.completeExceptionally(e);
        }
    }, null);
    try {
        return promise.get(AsyncOperationTimeoutSeconds, TimeUnit.SECONDS);
    } catch (TimeoutException te) {
        throw new ManagedLedgerException("Timeout during managed ledger offload operation");
    } catch (ExecutionException e) {
        log.error("[{}] Error offloading. pos = {}", name, pos, e.getCause());
        throw ManagedLedgerException.getManagedLedgerException(e.getCause());
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OffloadCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException)

Example 4 with OffloadCallback

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

the class PersistentTopic method triggerOffload.

public synchronized void triggerOffload(MessageIdImpl messageId) throws AlreadyRunningException {
    if (currentOffload.isDone()) {
        CompletableFuture<MessageIdImpl> promise = currentOffload = new CompletableFuture<>();
        log.info("[{}] Starting offload operation at messageId {}", topic, messageId);
        getManagedLedger().asyncOffloadPrefix(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId()), new OffloadCallback() {

            @Override
            public void offloadComplete(Position pos, Object ctx) {
                PositionImpl impl = (PositionImpl) pos;
                log.info("[{}] Completed successfully offload operation at messageId {}", topic, messageId);
                promise.complete(new MessageIdImpl(impl.getLedgerId(), impl.getEntryId(), -1));
            }

            @Override
            public void offloadFailed(ManagedLedgerException exception, Object ctx) {
                log.warn("[{}] Failed offload operation at messageId {}", topic, messageId, exception);
                promise.completeExceptionally(exception);
            }
        }, null);
    } else {
        throw new AlreadyRunningException("Offload already in progress");
    }
}
Also used : AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OffloadCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) BatchMessageIdImpl(org.apache.pulsar.client.impl.BatchMessageIdImpl) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl)

Example 5 with OffloadCallback

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

the class PersistentTopic method triggerOffload.

public synchronized void triggerOffload(MessageIdImpl messageId) throws AlreadyRunningException {
    if (currentOffload.isDone()) {
        CompletableFuture<MessageIdImpl> promise = currentOffload = new CompletableFuture<>();
        log.info("[{}] Starting offload operation at messageId {}", topic, messageId);
        getManagedLedger().asyncOffloadPrefix(PositionImpl.get(messageId.getLedgerId(), messageId.getEntryId()), new OffloadCallback() {

            @Override
            public void offloadComplete(Position pos, Object ctx) {
                PositionImpl impl = (PositionImpl) pos;
                log.info("[{}] Completed successfully offload operation at messageId {}", topic, messageId);
                promise.complete(new MessageIdImpl(impl.getLedgerId(), impl.getEntryId(), -1));
            }

            @Override
            public void offloadFailed(ManagedLedgerException exception, Object ctx) {
                log.warn("[{}] Failed offload operation at messageId {}", topic, messageId, exception);
                promise.completeExceptionally(exception);
            }
        }, null);
    } else {
        throw new AlreadyRunningException("Offload already in progress");
    }
}
Also used : AlreadyRunningException(org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) OffloadCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback) InitialPosition(org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition) Position(org.apache.bookkeeper.mledger.Position) PositionImpl(org.apache.bookkeeper.mledger.impl.PositionImpl) BatchMessageIdImpl(org.apache.pulsar.client.impl.BatchMessageIdImpl) MessageIdImpl(org.apache.pulsar.client.impl.MessageIdImpl)

Aggregations

OffloadCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OffloadCallback)6 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)6 Position (org.apache.bookkeeper.mledger.Position)6 InitialPosition (org.apache.pulsar.common.api.proto.CommandSubscribe.InitialPosition)6 CompletableFuture (java.util.concurrent.CompletableFuture)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 PositionImpl (org.apache.bookkeeper.mledger.impl.PositionImpl)3 AlreadyRunningException (org.apache.pulsar.broker.service.BrokerServiceException.AlreadyRunningException)3 BatchMessageIdImpl (org.apache.pulsar.client.impl.BatchMessageIdImpl)3 MessageIdImpl (org.apache.pulsar.client.impl.MessageIdImpl)3