本文整理汇总了Java中com.twitter.util.Future.ensure方法的典型用法代码示例。如果您正苦于以下问题:Java Future.ensure方法的具体用法?Java Future.ensure怎么用?Java Future.ensure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.twitter.util.Future
的用法示例。
在下文中一共展示了Future.ensure方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: apply
import com.twitter.util.Future; //导入方法依赖的package包/类
@Override
public <T> Future<T> apply(Function0<T> function0) {
if (traceTaskExecution) {
taskPendingCounter.inc();
Stopwatch taskEnqueueStopwatch = Stopwatch.createStarted();
Future<T> futureResult = futurePool.apply(new TimedFunction0<T>(function0));
taskEnqueueTime.registerSuccessfulEvent(taskEnqueueStopwatch.elapsed(TimeUnit.MICROSECONDS));
futureResult.ensure(new com.twitter.util.Function0<BoxedUnit>() {
@Override
public BoxedUnit apply() {
taskPendingCounter.dec();
return null;
}
});
return futureResult;
} else {
return futurePool.apply(function0);
}
}
示例2: ensureConstN
import com.twitter.util.Future; //导入方法依赖的package包/类
@Benchmark
public Void ensureConstN() throws Exception {
Future<Void> f = constVoidFuture;
for (int i = 0; i < N.n; i++)
f = f.ensure(ensureF);
return Await.result(f);
}
示例3: ensurePromiseN
import com.twitter.util.Future; //导入方法依赖的package包/类
@Benchmark
public Void ensurePromiseN() throws Exception {
Promise<Void> p = new Promise<>();
Future<Void> f = p;
for (int i = 0; i < N.n; i++)
f = f.ensure(ensureF);
p.setValue(null);
return Await.result(f);
}
示例4: writeUserRecord
import com.twitter.util.Future; //导入方法依赖的package包/类
synchronized private Future<DLSN> writeUserRecord(LogRecord record) throws IOException {
if (null != closeFuture) {
throw new WriteException(fullyQualifiedLogSegment, BKException.getMessage(BKException.Code.LedgerClosedException));
}
if (BKException.Code.OK != transmitResult.get()) {
// Failfast if the stream already encountered error with safe retry on the client
throw new WriteException(fullyQualifiedLogSegment, BKException.getMessage(transmitResult.get()));
}
if (streamEnded) {
throw new EndOfStreamException("Writing to a stream after it has been marked as completed");
}
if ((record.getTransactionId() < 0) ||
(record.getTransactionId() == DistributedLogConstants.MAX_TXID)) {
throw new TransactionIdOutOfOrderException(record.getTransactionId());
}
// Inject write delay if configured to do so
writeDelayInjector.inject();
// Will check write rate limits and throw if exceeded.
writeLimiter.acquire();
pendingWrites.inc();
// The count represents the number of user records up to the
// current record
// Increment the record count only when writing a user log record
// Internally generated log records don't increment the count
// writeInternal will always set a count regardless of whether it was
// incremented or not.
Future<DLSN> future = null;
try {
// increment the position for the record to write
// if the record is failed to write, it would be decremented.
positionWithinLogSegment++;
int numRecords = 1;
if (record.isRecordSet()) {
numRecords = LogRecordSet.numRecords(record);
}
future = writeInternal(record);
// after the record (record set) is written, the position should be
// moved for {numRecords}, but since we already moved the record by 1
// so advance the position for other {numRecords - 1}.
positionWithinLogSegment += (numRecords - 1);
} catch (IOException ex) {
writeLimiter.release();
pendingWrites.dec();
positionWithinLogSegment--;
throw ex;
}
// Track outstanding requests and return the future.
return future.ensure(new Function0<BoxedUnit>() {
public BoxedUnit apply() {
pendingWrites.dec();
writeLimiter.release();
return null;
}
});
}