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


Java Future.ensure方法代码示例

本文整理汇总了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);
    }
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:20,代码来源:MonitoredFuturePool.java

示例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);
}
 
开发者ID:traneio,项目名称:future,代码行数:8,代码来源:TwitterFutureBenchmark.java

示例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);
}
 
开发者ID:traneio,项目名称:future,代码行数:10,代码来源:TwitterFutureBenchmark.java

示例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;
        }
    });
}
 
开发者ID:twitter,项目名称:distributedlog,代码行数:63,代码来源:BKLogSegmentWriter.java


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