当前位置: 首页>>代码示例>>Java>>正文


Java Future.flatMap方法代码示例

本文整理汇总了Java中com.twitter.util.Future.flatMap方法的典型用法代码示例。如果您正苦于以下问题:Java Future.flatMap方法的具体用法?Java Future.flatMap怎么用?Java Future.flatMap使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.twitter.util.Future的用法示例。


在下文中一共展示了Future.flatMap方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: doGetLogSegmentWriter

import com.twitter.util.Future; //导入方法依赖的package包/类
private Future<BKLogSegmentWriter> doGetLogSegmentWriter(final long firstTxid,
                                                         final boolean bestEffort,
                                                         final boolean rollLog,
                                                         final boolean allowMaxTxID) {
    if (encounteredError) {
        return Future.exception(new WriteException(bkDistributedLogManager.getStreamName(),
                "writer has been closed due to error."));
    }
    Future<BKLogSegmentWriter> writerFuture = asyncGetLedgerWriter(!disableRollOnSegmentError);
    if (null == writerFuture) {
        return rollLogSegmentIfNecessary(null, firstTxid, bestEffort, allowMaxTxID);
    } else if (rollLog) {
        return writerFuture.flatMap(new AbstractFunction1<BKLogSegmentWriter, Future<BKLogSegmentWriter>>() {
            @Override
            public Future<BKLogSegmentWriter> apply(BKLogSegmentWriter writer) {
                return rollLogSegmentIfNecessary(writer, firstTxid, bestEffort, allowMaxTxID);
            }
        });
    } else {
        return writerFuture;
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:23,代码来源:BKAsyncLogWriter.java

示例2: flushAndCommit

import com.twitter.util.Future; //导入方法依赖的package包/类
Future<Long> flushAndCommit() {
    Future<BKLogSegmentWriter> writerFuture;
    synchronized (this) {
        if (null != this.rollingFuture) {
            writerFuture = this.rollingFuture;
        } else {
            writerFuture = getCachedLogWriterFuture();
        }
    }
    if (null == writerFuture) {
        return Future.value(getLastTxId());
    }
    return writerFuture.flatMap(new AbstractFunction1<BKLogSegmentWriter, Future<Long>>() {
        @Override
        public Future<Long> apply(BKLogSegmentWriter writer) {
            return writer.flushAndCommit();
        }
    });
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:20,代码来源:BKAsyncLogWriter.java

示例3: asyncCloseAndComplete

import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
protected Future<Void> asyncCloseAndComplete() {
    Future<BKLogSegmentWriter> logSegmentWriterFuture;
    synchronized (this) {
        logSegmentWriterFuture = this.rollingFuture;
    }

    if (null == logSegmentWriterFuture) {
        return super.asyncCloseAndComplete();
    } else {
        return logSegmentWriterFuture.flatMap(new AbstractFunction1<BKLogSegmentWriter, Future<Void>>() {
            @Override
            public Future<Void> apply(BKLogSegmentWriter segmentWriter) {
                return BKAsyncLogWriter.super.asyncCloseAndComplete();
            }
        });
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:19,代码来源:BKAsyncLogWriter.java

示例4: flatMapConstN

import com.twitter.util.Future; //导入方法依赖的package包/类
@Benchmark
public String flatMapConstN() throws Exception {
  Future<String> f = constFuture;
  for (int i = 0; i < N.n; i++)
    f = f.flatMap(flatMapF);
  return Await.result(f);
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:TwitterFutureBenchmark.java

示例5: flatMapPromiseN

import com.twitter.util.Future; //导入方法依赖的package包/类
@Benchmark
public String flatMapPromiseN() throws Exception {
  Promise<String> p = new Promise<String>();
  Future<String> f = p;
  for (int i = 0; i < N.n; i++)
    f = f.flatMap(flatMapF);
  p.setValue(string);
  return Await.result(f);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:TwitterFutureBenchmark.java

示例6: testReaderLockCloseInAcquireCallback

import com.twitter.util.Future; //导入方法依赖的package包/类
@Test(timeout = 60000)
public void testReaderLockCloseInAcquireCallback() throws Exception {
    final String name = runtime.getMethodName();
    DistributedLogManager dlm = createNewDLM(conf, name);
    BKAsyncLogWriter writer = (BKAsyncLogWriter)(dlm.startAsyncLogSegmentNonPartitioned());
    writer.write(DLMTestUtil.getLogRecordInstance(1L));
    writer.closeAndComplete();

    final CountDownLatch latch = new CountDownLatch(1);

    Future<AsyncLogReader> futureReader1 = dlm.getAsyncLogReaderWithLock(DLSN.InitialDLSN);
    futureReader1.flatMap(new ExceptionalFunction<AsyncLogReader, Future<Void>>() {
        @Override
        public Future<Void> applyE(AsyncLogReader reader) throws IOException {
            return reader.asyncClose().map(new AbstractFunction1<Void, Void>() {
                @Override
                public Void apply(Void result) {
                    latch.countDown();
                    return null;
                }
            });
        }
    });

    latch.await();
    dlm.close();
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:28,代码来源:TestAsyncReaderLock.java

示例7: asTryList

import com.twitter.util.Future; //导入方法依赖的package包/类
private Future<List<Try<DLSN>>> asTryList(Future<List<Future<DLSN>>> futureList) {
    return futureList.flatMap(new AbstractFunction1<List<Future<DLSN>>, Future<List<Try<DLSN>>>>() {
        @Override
        public Future<List<Try<DLSN>>> apply(List<Future<DLSN>> results) {
            return Future$.MODULE$.collectToTry(results);
        }
    });
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:9,代码来源:BulkWriteOp.java

示例8: openAsyncLogWriter

import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
public Future<AsyncLogWriter> openAsyncLogWriter() {
    try {
        checkClosedOrInError("startLogSegmentNonPartitioned");
    } catch (AlreadyClosedException e) {
        return Future.exception(e);
    }

    Future<BKLogWriteHandler> createWriteHandleFuture;
    synchronized (this) {
        // 1. create the locked write handler
        createWriteHandleFuture = asyncCreateWriteHandler(true);
    }
    return createWriteHandleFuture.flatMap(new AbstractFunction1<BKLogWriteHandler, Future<AsyncLogWriter>>() {
        @Override
        public Future<AsyncLogWriter> apply(final BKLogWriteHandler writeHandler) {
            final BKAsyncLogWriter writer;
            synchronized (BKDistributedLogManager.this) {
                // 2. create the writer with the handler
                writer = new BKAsyncLogWriter(
                        conf,
                        dynConf,
                        BKDistributedLogManager.this,
                        writeHandler,
                        featureProvider,
                        statsLogger);
            }
            // 3. recover the incomplete log segments
            return writeHandler.recoverIncompleteLogSegments()
                    .map(new AbstractFunction1<Long, AsyncLogWriter>() {
                        @Override
                        public AsyncLogWriter apply(Long lastTxId) {
                            // 4. update last tx id if successfully recovered
                            writer.setLastTxId(lastTxId);
                            return writer;
                        }
                    }).onFailure(new AbstractFunction1<Throwable, BoxedUnit>() {
                        @Override
                        public BoxedUnit apply(Throwable cause) {
                            // 5. close the writer if recovery failed
                            writer.asyncAbort();
                            return BoxedUnit.UNIT;
                        }
                    });
        }
    });
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:48,代码来源:BKDistributedLogManager.java

示例9: asyncGetLedgerWriter

import com.twitter.util.Future; //导入方法依赖的package包/类
synchronized protected Future<BKLogSegmentWriter> asyncGetLedgerWriter(boolean resetOnError) {
    final BKLogSegmentWriter ledgerWriter = getCachedLogWriter();
    Future<BKLogSegmentWriter> ledgerWriterFuture = getCachedLogWriterFuture();
    if (null == ledgerWriterFuture || null == ledgerWriter) {
        return null;
    }

    // Handle the case where the last call to write actually caused an error in the log
    if ((ledgerWriter.isLogSegmentInError() || forceRecovery) && resetOnError) {
        // Close the ledger writer so that we will recover and start a new log segment
        Future<Void> closeFuture;
        if (ledgerWriter.isLogSegmentInError()) {
            closeFuture = ledgerWriter.asyncAbort();
        } else {
            closeFuture = ledgerWriter.asyncClose();
        }
        return closeFuture.flatMap(
                new AbstractFunction1<Void, Future<BKLogSegmentWriter>>() {
            @Override
            public Future<BKLogSegmentWriter> apply(Void result) {
                removeCachedLogWriter();

                if (ledgerWriter.isLogSegmentInError()) {
                    return Future.value(null);
                }

                BKLogWriteHandler writeHandler;
                try {
                    writeHandler = getWriteHandler();
                } catch (IOException e) {
                    return Future.exception(e);
                }
                if (null != writeHandler && forceRecovery) {
                    return writeHandler.completeAndCloseLogSegment(ledgerWriter)
                            .map(new AbstractFunction1<LogSegmentMetadata, BKLogSegmentWriter>() {
                        @Override
                        public BKLogSegmentWriter apply(LogSegmentMetadata completedLogSegment) {
                            return null;
                        }
                    });
                } else {
                    return Future.value(null);
                }
            }
        });
    } else {
        return ledgerWriterFuture;
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:50,代码来源:BKAbstractLogWriter.java


注:本文中的com.twitter.util.Future.flatMap方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。