本文整理汇总了Java中com.twitter.util.Future.map方法的典型用法代码示例。如果您正苦于以下问题:Java Future.map方法的具体用法?Java Future.map怎么用?Java Future.map使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.twitter.util.Future
的用法示例。
在下文中一共展示了Future.map方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: executeOp
import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
protected Future<WriteResponse> executeOp(AsyncLogWriter writer,
Sequencer sequencer,
Object txnLock) {
// write a control record if heartbeat is the first request of the recovered log segment.
if (writeControlRecord) {
long txnId;
Future<DLSN> writeResult;
synchronized (txnLock) {
txnId = sequencer.nextId();
writeResult = ((BKAsyncLogWriter) writer).writeControlRecord(new LogRecord(txnId, HEARTBEAT_DATA));
}
return writeResult.map(new AbstractFunction1<DLSN, WriteResponse>() {
@Override
public WriteResponse apply(DLSN value) {
return ResponseUtils.writeSuccess().setDlsn(value.serialize(dlsnVersion));
}
});
} else {
return Future.value(ResponseUtils.writeSuccess());
}
}
示例2: mapConstN
import com.twitter.util.Future; //导入方法依赖的package包/类
@Benchmark
public String mapConstN() throws Exception {
Future<String> f = constFuture;
for (int i = 0; i < N.n; i++)
f = f.map(mapF);
return Await.result(f);
}
示例3: mapPromiseN
import com.twitter.util.Future; //导入方法依赖的package包/类
@Benchmark
public String mapPromiseN() throws Exception {
Promise<String> p = new Promise<String>();
Future<String> f = p;
for (int i = 0; i < N.n; i++)
f = f.map(mapF);
p.setValue(string);
return Await.result(f);
}
示例4: setValueN
import com.twitter.util.Future; //导入方法依赖的package包/类
@Benchmark
public String setValueN() throws Exception {
Promise<String> p = new Promise<String>();
Future<String> f = p;
for (int i = 0; i < N.n; i++)
f = f.map(mapF);
p.setValue(string);
return Await.result(f);
}
示例5: rollLogSegmentIfNecessary
import com.twitter.util.Future; //导入方法依赖的package包/类
synchronized protected Future<BKLogSegmentWriter> rollLogSegmentIfNecessary(
final BKLogSegmentWriter segmentWriter,
long startTxId,
boolean bestEffort,
boolean allowMaxTxID) {
final BKLogWriteHandler writeHandler;
try {
writeHandler = getWriteHandler();
} catch (IOException e) {
return Future.exception(e);
}
Future<BKLogSegmentWriter> rollPromise;
if (null != segmentWriter && (writeHandler.shouldStartNewSegment(segmentWriter) || forceRolling)) {
rollPromise = closeOldLogSegmentAndStartNewOneWithPermit(
segmentWriter, writeHandler, startTxId, bestEffort, allowMaxTxID);
} else if (null == segmentWriter) {
rollPromise = asyncStartNewLogSegment(writeHandler, startTxId, allowMaxTxID);
} else {
rollPromise = Future.value(segmentWriter);
}
return rollPromise.map(new AbstractFunction1<BKLogSegmentWriter, BKLogSegmentWriter>() {
@Override
public BKLogSegmentWriter apply(BKLogSegmentWriter newSegmentWriter) {
if (segmentWriter == newSegmentWriter) {
return newSegmentWriter;
}
truncateLogSegmentsIfNecessary(writeHandler);
return newSegmentWriter;
}
});
}
示例6: executeOp
import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
protected Future<WriteResponse> executeOp(AsyncLogWriter writer,
Sequencer sequencer,
Object txnLock) {
Future<Void> result = streamManager.createStreamAsync(streamName());
return result.map(new AbstractFunction1<Void, WriteResponse>() {
@Override
public WriteResponse apply(Void value) {
return ResponseUtils.writeSuccess();
}
});
}
示例7: executeOp
import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
protected Future<WriteResponse> executeOp(AsyncLogWriter writer,
Sequencer sequencer,
Object txnLock) {
Future<Void> result = streamManager.deleteAndRemoveAsync(streamName());
return result.map(new AbstractFunction1<Void, WriteResponse>() {
@Override
public WriteResponse apply(Void value) {
return ResponseUtils.writeSuccess();
}
});
}
示例8: executeOp
import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
protected Future<WriteResponse> executeOp(AsyncLogWriter writer,
Sequencer sequencer,
Object txnLock) {
if (!stream.equals(writer.getStreamName())) {
logger.error("Write: Stream Name Mismatch in the Stream Map {}, {}", stream, writer.getStreamName());
return Future.exception(new IllegalStateException("The stream mapping is incorrect, fail the request"));
}
long txnId;
Future<DLSN> writeResult;
synchronized (txnLock) {
txnId = sequencer.nextId();
LogRecord record = new LogRecord(txnId, payload);
if (isRecordSet) {
record.setRecordSet();
}
writeResult = writer.write(record);
}
return writeResult.map(new AbstractFunction1<DLSN, WriteResponse>() {
@Override
public WriteResponse apply(DLSN value) {
successRecordCounter.inc();
return ResponseUtils.writeSuccess().setDlsn(value.serialize(dlsnVersion));
}
});
}
示例9: executeOp
import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
protected Future<WriteResponse> executeOp(AsyncLogWriter writer,
Sequencer sequencer,
Object txnLock) {
Future<Void> result = streamManager.closeAndRemoveAsync(streamName());
return result.map(new AbstractFunction1<Void, WriteResponse>() {
@Override
public WriteResponse apply(Void value) {
return ResponseUtils.writeSuccess();
}
});
}
示例10: asyncWrite
import com.twitter.util.Future; //导入方法依赖的package包/类
private synchronized Future<DLSN> asyncWrite(final LogRecord record,
boolean flush) {
// The passed in writer may be stale since we acquire the writer outside of sync
// lock. If we recently rolled and the new writer is cached, use that instead.
Future<DLSN> result = null;
BKLogSegmentWriter w;
try {
w = getCachedLogSegmentWriter();
} catch (WriteException we) {
return Future.exception(we);
}
if (null != rollingFuture) {
if (streamFailFast) {
result = Future.exception(new StreamNotReadyException("Rolling log segment"));
} else {
result = queueRequest(record, flush);
}
} else if (shouldRollLog(w)) {
// insert a last record, so when it called back, we will trigger a log segment rolling
startQueueingRequests();
if (null != w) {
LastPendingLogRecord lastLogRecordInCurrentSegment = new LastPendingLogRecord(record, flush);
w.asyncWrite(record, true).addEventListener(lastLogRecordInCurrentSegment);
result = lastLogRecordInCurrentSegment.promise;
} else { // no log segment yet. roll the log segment and issue pending requests.
result = queueRequest(record, flush);
rollLogSegmentAndIssuePendingRequests(record);
}
} else {
result = w.asyncWrite(record, flush);
}
// use map here rather than onSuccess because we want lastTxId to be updated before
// satisfying the future
return result.map(new AbstractFunction1<DLSN, DLSN>() {
@Override
public DLSN apply(DLSN dlsn) {
setLastTxId(record.getTransactionId());
return dlsn;
}
});
}