本文整理汇总了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;
}
}
示例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();
}
});
}
示例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();
}
});
}
}
示例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);
}
示例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);
}
示例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();
}
示例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);
}
});
}
示例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;
}
});
}
});
}
示例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;
}
}