Search in sources :

Example 1 with ZKLogMetadataForWriter

use of com.twitter.distributedlog.impl.metadata.ZKLogMetadataForWriter in project distributedlog by twitter.

the class BKDistributedLogManager method asyncCreateWriteHandler.

Future<BKLogWriteHandler> asyncCreateWriteHandler(final boolean lockHandler) {
    final ZooKeeper zk;
    try {
        zk = writerZKC.get();
    } catch (InterruptedException e) {
        LOG.error("Failed to initialize zookeeper client : ", e);
        return Future.exception(new DLInterruptedException("Failed to initialize zookeeper client", e));
    } catch (ZooKeeperClient.ZooKeeperConnectionException e) {
        return Future.exception(FutureUtils.zkException(e, uri.getPath()));
    }
    boolean ownAllocator = null == ledgerAllocator;
    // Fetching Log Metadata
    Future<ZKLogMetadataForWriter> metadataFuture = ZKLogMetadataForWriter.of(uri, name, streamIdentifier, zk, writerZKC.getDefaultACL(), ownAllocator, conf.getCreateStreamIfNotExists() || ownAllocator);
    return metadataFuture.flatMap(new AbstractFunction1<ZKLogMetadataForWriter, Future<BKLogWriteHandler>>() {

        @Override
        public Future<BKLogWriteHandler> apply(ZKLogMetadataForWriter logMetadata) {
            Promise<BKLogWriteHandler> createPromise = new Promise<BKLogWriteHandler>();
            createWriteHandler(logMetadata, lockHandler, createPromise);
            return createPromise;
        }
    });
}
Also used : DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException) ZKLogMetadataForWriter(com.twitter.distributedlog.impl.metadata.ZKLogMetadataForWriter) Promise(com.twitter.util.Promise) ZooKeeper(org.apache.zookeeper.ZooKeeper) Future(com.twitter.util.Future) DLInterruptedException(com.twitter.distributedlog.exceptions.DLInterruptedException)

Aggregations

DLInterruptedException (com.twitter.distributedlog.exceptions.DLInterruptedException)1 ZKLogMetadataForWriter (com.twitter.distributedlog.impl.metadata.ZKLogMetadataForWriter)1 Future (com.twitter.util.Future)1 Promise (com.twitter.util.Promise)1 ZooKeeper (org.apache.zookeeper.ZooKeeper)1