Java Code Examples for com.google.common.base.Ticker#read()

The following examples show how to use com.google.common.base.Ticker#read() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DatabaseShardManager.java    From presto with Apache License 2.0 6 votes vote down vote up
public DatabaseShardManager(
        IDBI dbi,
        DaoSupplier<ShardDao> shardDaoSupplier,
        NodeSupplier nodeSupplier,
        AssignmentLimiter assignmentLimiter,
        Ticker ticker,
        Duration startupGracePeriod)
{
    this.dbi = requireNonNull(dbi, "dbi is null");
    this.shardDaoSupplier = requireNonNull(shardDaoSupplier, "shardDaoSupplier is null");
    this.dao = shardDaoSupplier.onDemand();
    this.nodeSupplier = requireNonNull(nodeSupplier, "nodeSupplier is null");
    this.assignmentLimiter = requireNonNull(assignmentLimiter, "assignmentLimiter is null");
    this.ticker = requireNonNull(ticker, "ticker is null");
    this.startupGracePeriod = requireNonNull(startupGracePeriod, "startupGracePeriod is null");
    this.startTime = ticker.read();
}
 
Example 2
Source File: DriftMethodInvocation.java    From drift with Apache License 2.0 5 votes vote down vote up
private DriftMethodInvocation(
        MethodInvoker invoker,
        MethodMetadata metadata,
        Map<String, String> headers,
        List<Object> parameters,
        RetryPolicy retryPolicy,
        AddressSelector<A> addressSelector,
        Optional<String> addressSelectionContext,
        MethodInvocationStat stat,
        Ticker ticker)
{
    this.invoker = requireNonNull(invoker, "methodHandler is null");
    this.metadata = requireNonNull(metadata, "metadata is null");
    this.headers = requireNonNull(headers, "headers is null");
    this.parameters = requireNonNull(parameters, "parameters is null");
    this.retryPolicy = requireNonNull(retryPolicy, "retryPolicy is null");
    this.addressSelector = requireNonNull(addressSelector, "addressSelector is null");
    this.addressSelectionContext = requireNonNull(addressSelectionContext, "addressSelectionContext is null");
    this.stat = requireNonNull(stat, "stat is null");
    this.ticker = requireNonNull(ticker, "ticker is null");
    this.startTime = ticker.read();

    // if this invocation is canceled, cancel the tasks
    super.addListener(() -> {
        if (super.isCancelled()) {
            onCancel(wasInterrupted());
        }
    }, directExecutor());
}
 
Example 3
Source File: SyncQueryData.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public long getTotalDurationNanos(Ticker ticker) {
    // TODO analyze worst case due to lack of atomicity
    if (activeCount > 0) {
        long currTick = ticker.read();
        return sumOfEndTicks + currTick * activeCount - sumOfStartTicks;
    }
    return sumOfEndTicks - sumOfStartTicks;
}
 
Example 4
Source File: AsyncQueryData.java    From glowroot with Apache License 2.0 5 votes vote down vote up
public long getTotalDurationNanos(Ticker ticker) {
    // TODO analyze worst case due to lack of atomicity, especially because it's possible for
    // async query to be active at the end of a transaction
    if (activeCount.get() > 0) {
        long currTick = ticker.read();
        return sumOfEndTicks.get() + currTick * activeCount.get() - sumOfStartTicks.get();
    }
    return sumOfEndTicks.get() - sumOfStartTicks.get();
}
 
Example 5
Source File: DatasetVersion.java    From dremio-oss with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static DatasetVersion forTesting(Ticker ticker) {
  long t = ticker.read();
  long r = Holder.numberGenerator.nextLong();
  return new DatasetVersion(t, r);
}
 
Example 6
Source File: RelativeTicker.java    From yql-plus with Apache License 2.0 4 votes vote down vote up
public RelativeTicker(Ticker base) {
    this.base = base;
    this.start = base.read();
}