Search in sources :

Example 1 with OpenReadOnlyCursorCallback

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

the class ManagedLedgerFactoryImpl method openReadOnlyCursor.

@Override
public ReadOnlyCursor openReadOnlyCursor(String managedLedgerName, Position startPosition, ManagedLedgerConfig config) throws InterruptedException, ManagedLedgerException {
    class Result {

        ReadOnlyCursor c = null;

        ManagedLedgerException e = null;
    }
    final Result r = new Result();
    final CountDownLatch latch = new CountDownLatch(1);
    asyncOpenReadOnlyCursor(managedLedgerName, startPosition, config, new OpenReadOnlyCursorCallback() {

        @Override
        public void openReadOnlyCursorComplete(ReadOnlyCursor cursor, Object ctx) {
            r.c = cursor;
            latch.countDown();
        }

        @Override
        public void openReadOnlyCursorFailed(ManagedLedgerException exception, Object ctx) {
            r.e = exception;
            latch.countDown();
        }
    }, null);
    latch.await();
    if (r.e != null) {
        throw r.e;
    }
    return r.c;
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) OpenReadOnlyCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenReadOnlyCursorCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 2 with OpenReadOnlyCursorCallback

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

the class ManagedLedgerFactoryImpl method asyncOpenReadOnlyCursor.

@Override
public void asyncOpenReadOnlyCursor(String managedLedgerName, Position startPosition, ManagedLedgerConfig config, OpenReadOnlyCursorCallback callback, Object ctx) {
    if (closed) {
        callback.openReadOnlyCursorFailed(new ManagedLedgerException.ManagedLedgerFactoryClosedException(), ctx);
        return;
    }
    checkArgument(startPosition instanceof PositionImpl);
    ReadOnlyManagedLedgerImpl roManagedLedger = new ReadOnlyManagedLedgerImpl(this, bookkeeperFactory.get(new EnsemblePlacementPolicyConfig(config.getBookKeeperEnsemblePlacementPolicyClassName(), config.getBookKeeperEnsemblePlacementPolicyProperties())), store, config, scheduledExecutor, managedLedgerName);
    roManagedLedger.initializeAndCreateCursor((PositionImpl) startPosition).thenAccept(roCursor -> callback.openReadOnlyCursorComplete(roCursor, ctx)).exceptionally(ex -> {
        Throwable t = ex;
        if (t instanceof CompletionException) {
            t = ex.getCause();
        }
        if (t instanceof ManagedLedgerException) {
            callback.openReadOnlyCursorFailed((ManagedLedgerException) t, ctx);
        } else {
            callback.openReadOnlyCursorFailed(new ManagedLedgerException(t), ctx);
        }
        return null;
    });
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ScheduledFuture(java.util.concurrent.ScheduledFuture) CloseCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback) State(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.State) LoggerFactory(org.slf4j.LoggerFactory) MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) MessageRangeInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.MessageRangeInfo) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) LongProperty(org.apache.bookkeeper.mledger.proto.MLDataFormats.LongProperty) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Runnables.catchingAndLoggingThrowables(org.apache.pulsar.common.util.Runnables.catchingAndLoggingThrowables) Map(java.util.Map) Stat(org.apache.pulsar.metadata.api.Stat) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) LedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.LedgerInfo) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) PositionInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.PositionInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Futures(org.apache.bookkeeper.mledger.util.Futures) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Position(org.apache.bookkeeper.mledger.Position) MLDataFormats(org.apache.bookkeeper.mledger.proto.MLDataFormats) BookKeeper(org.apache.bookkeeper.client.BookKeeper) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) SessionEvent(org.apache.pulsar.metadata.api.extended.SessionEvent) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) DeleteLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteLedgerCallback) Getter(lombok.Getter) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerFactoryMXBean(org.apache.bookkeeper.mledger.ManagedLedgerFactoryMXBean) ManagedLedgerInfoCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback) CompletableFuture(java.util.concurrent.CompletableFuture) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) Supplier(java.util.function.Supplier) OpenReadOnlyCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenReadOnlyCursorCallback) ArrayList(java.util.ArrayList) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) DateFormatter(org.apache.pulsar.common.util.DateFormatter) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Predicates(com.google.common.base.Predicates) ExecutorService(java.util.concurrent.ExecutorService) MessageRange(org.apache.bookkeeper.mledger.proto.MLDataFormats.MessageRange) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) ManagedLedgerInitializeLedgerCallback(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.ManagedLedgerInitializeLedgerCallback) Logger(org.slf4j.Logger) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) OpenLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback) CursorInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.CursorInfo) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) CompletionException(java.util.concurrent.CompletionException) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig)

Example 3 with OpenReadOnlyCursorCallback

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

the class ManagedLedgerFactoryImpl method openReadOnlyCursor.

@Override
public ReadOnlyCursor openReadOnlyCursor(String managedLedgerName, Position startPosition, ManagedLedgerConfig config) throws InterruptedException, ManagedLedgerException {
    class Result {

        ReadOnlyCursor c = null;

        ManagedLedgerException e = null;
    }
    final Result r = new Result();
    final CountDownLatch latch = new CountDownLatch(1);
    asyncOpenReadOnlyCursor(managedLedgerName, startPosition, config, new OpenReadOnlyCursorCallback() {

        @Override
        public void openReadOnlyCursorComplete(ReadOnlyCursor cursor, Object ctx) {
            r.c = cursor;
            latch.countDown();
        }

        @Override
        public void openReadOnlyCursorFailed(ManagedLedgerException exception, Object ctx) {
            r.e = exception;
            latch.countDown();
        }
    }, null);
    latch.await();
    if (r.e != null) {
        throw r.e;
    }
    return r.c;
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) OpenReadOnlyCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenReadOnlyCursorCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 4 with OpenReadOnlyCursorCallback

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

the class ManagedLedgerFactoryImpl method asyncOpenReadOnlyCursor.

@Override
public void asyncOpenReadOnlyCursor(String managedLedgerName, Position startPosition, ManagedLedgerConfig config, OpenReadOnlyCursorCallback callback, Object ctx) {
    if (closed) {
        callback.openReadOnlyCursorFailed(new ManagedLedgerException.ManagedLedgerFactoryClosedException(), ctx);
        return;
    }
    checkArgument(startPosition instanceof PositionImpl);
    ReadOnlyManagedLedgerImpl roManagedLedger = new ReadOnlyManagedLedgerImpl(this, bookkeeperFactory.get(new EnsemblePlacementPolicyConfig(config.getBookKeeperEnsemblePlacementPolicyClassName(), config.getBookKeeperEnsemblePlacementPolicyProperties())), store, config, scheduledExecutor, managedLedgerName);
    roManagedLedger.initializeAndCreateCursor((PositionImpl) startPosition).thenAccept(roCursor -> callback.openReadOnlyCursorComplete(roCursor, ctx)).exceptionally(ex -> {
        Throwable t = ex;
        if (t instanceof CompletionException) {
            t = ex.getCause();
        }
        if (t instanceof ManagedLedgerException) {
            callback.openReadOnlyCursorFailed((ManagedLedgerException) t, ctx);
        } else {
            callback.openReadOnlyCursorFailed(new ManagedLedgerException(t), ctx);
        }
        return null;
    });
}
Also used : DefaultThreadFactory(io.netty.util.concurrent.DefaultThreadFactory) ScheduledFuture(java.util.concurrent.ScheduledFuture) CloseCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.CloseCallback) State(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.State) LoggerFactory(org.slf4j.LoggerFactory) MetadataStore(org.apache.pulsar.metadata.api.MetadataStore) MessageRangeInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.MessageRangeInfo) MetaStoreCallback(org.apache.bookkeeper.mledger.impl.MetaStore.MetaStoreCallback) ManagedCursorInfo(org.apache.bookkeeper.mledger.proto.MLDataFormats.ManagedCursorInfo) LongProperty(org.apache.bookkeeper.mledger.proto.MLDataFormats.LongProperty) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) ManagedLedger(org.apache.bookkeeper.mledger.ManagedLedger) ManagedLedgerConfig(org.apache.bookkeeper.mledger.ManagedLedgerConfig) Runnables.catchingAndLoggingThrowables(org.apache.pulsar.common.util.Runnables.catchingAndLoggingThrowables) Map(java.util.Map) Stat(org.apache.pulsar.metadata.api.Stat) NullStatsLogger(org.apache.bookkeeper.stats.NullStatsLogger) LedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.LedgerInfo) OrderedScheduler(org.apache.bookkeeper.common.util.OrderedScheduler) PositionInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.PositionInfo) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Futures(org.apache.bookkeeper.mledger.util.Futures) CompletionException(java.util.concurrent.CompletionException) UUID(java.util.UUID) Position(org.apache.bookkeeper.mledger.Position) MLDataFormats(org.apache.bookkeeper.mledger.proto.MLDataFormats) BookKeeper(org.apache.bookkeeper.client.BookKeeper) Collectors(java.util.stream.Collectors) Executors(java.util.concurrent.Executors) BKException(org.apache.bookkeeper.client.BKException) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) CountDownLatch(java.util.concurrent.CountDownLatch) List(java.util.List) FutureUtil(org.apache.pulsar.common.util.FutureUtil) SessionEvent(org.apache.pulsar.metadata.api.extended.SessionEvent) StatsLogger(org.apache.bookkeeper.stats.StatsLogger) AsyncCallbacks(org.apache.bookkeeper.mledger.AsyncCallbacks) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) DeleteLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.DeleteLedgerCallback) Getter(lombok.Getter) ManagedLedgerFactory(org.apache.bookkeeper.mledger.ManagedLedgerFactory) ManagedLedgerFactoryMXBean(org.apache.bookkeeper.mledger.ManagedLedgerFactoryMXBean) ManagedLedgerInfoCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.ManagedLedgerInfoCallback) CompletableFuture(java.util.concurrent.CompletableFuture) MetadataStoreExtended(org.apache.pulsar.metadata.api.extended.MetadataStoreExtended) Supplier(java.util.function.Supplier) OpenReadOnlyCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenReadOnlyCursorCallback) ArrayList(java.util.ArrayList) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig) MetaStoreException(org.apache.bookkeeper.mledger.ManagedLedgerException.MetaStoreException) DateFormatter(org.apache.pulsar.common.util.DateFormatter) ManagedLedgerFactoryConfig(org.apache.bookkeeper.mledger.ManagedLedgerFactoryConfig) Predicates(com.google.common.base.Predicates) ExecutorService(java.util.concurrent.ExecutorService) MessageRange(org.apache.bookkeeper.mledger.proto.MLDataFormats.MessageRange) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) ManagedLedgerInitializeLedgerCallback(org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.ManagedLedgerInitializeLedgerCallback) Logger(org.slf4j.Logger) ManagedLedgerInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) TimeUnit(java.util.concurrent.TimeUnit) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap) OpenLedgerCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenLedgerCallback) CursorInfo(org.apache.bookkeeper.mledger.ManagedLedgerInfo.CursorInfo) ClientConfiguration(org.apache.bookkeeper.conf.ClientConfiguration) ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) CompletionException(java.util.concurrent.CompletionException) EnsemblePlacementPolicyConfig(org.apache.pulsar.common.policies.data.EnsemblePlacementPolicyConfig)

Example 5 with OpenReadOnlyCursorCallback

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

the class ManagedLedgerFactoryImpl method openReadOnlyCursor.

@Override
public ReadOnlyCursor openReadOnlyCursor(String managedLedgerName, Position startPosition, ManagedLedgerConfig config) throws InterruptedException, ManagedLedgerException {
    class Result {

        ReadOnlyCursor c = null;

        ManagedLedgerException e = null;
    }
    final Result r = new Result();
    final CountDownLatch latch = new CountDownLatch(1);
    asyncOpenReadOnlyCursor(managedLedgerName, startPosition, config, new OpenReadOnlyCursorCallback() {

        @Override
        public void openReadOnlyCursorComplete(ReadOnlyCursor cursor, Object ctx) {
            r.c = cursor;
            latch.countDown();
        }

        @Override
        public void openReadOnlyCursorFailed(ManagedLedgerException exception, Object ctx) {
            r.e = exception;
            latch.countDown();
        }
    }, null);
    latch.await();
    if (r.e != null) {
        throw r.e;
    }
    return r.c;
}
Also used : ManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException) ManagedLedgerException.getManagedLedgerException(org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException) ReadOnlyCursor(org.apache.bookkeeper.mledger.ReadOnlyCursor) OpenReadOnlyCursorCallback(org.apache.bookkeeper.mledger.AsyncCallbacks.OpenReadOnlyCursorCallback) CountDownLatch(java.util.concurrent.CountDownLatch)

Aggregations

CountDownLatch (java.util.concurrent.CountDownLatch)6 OpenReadOnlyCursorCallback (org.apache.bookkeeper.mledger.AsyncCallbacks.OpenReadOnlyCursorCallback)6 ManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException)6 ManagedLedgerException.getManagedLedgerException (org.apache.bookkeeper.mledger.ManagedLedgerException.getManagedLedgerException)6 ReadOnlyCursor (org.apache.bookkeeper.mledger.ReadOnlyCursor)6 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Predicates (com.google.common.base.Predicates)3 Maps (com.google.common.collect.Maps)3 DefaultThreadFactory (io.netty.util.concurrent.DefaultThreadFactory)3 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 Map (java.util.Map)3 CompletableFuture (java.util.concurrent.CompletableFuture)3 CompletionException (java.util.concurrent.CompletionException)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)3 ExecutorService (java.util.concurrent.ExecutorService)3 Executors (java.util.concurrent.Executors)3 ScheduledFuture (java.util.concurrent.ScheduledFuture)3