Guava Ticker - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Guava Ticker class.

This code example shows how to use the following methods:read
 
      if (retryAfter.matches("^[0-9]+$"))
         return Optional.of(new RetryAfterException(in, Integer.parseInt(retryAfter)));
      try { 
         long retryTimeMillis = dateCodec.toDate(retryAfter).getTime();
         long currentTimeMillis = NANOSECONDS.toMillis(ticker.read());
         return Optional.of(new RetryAfterException(in, (int) MILLISECONDS.toSeconds(retryTimeMillis
               - currentTimeMillis)));
      } catch (IllegalArgumentException e) {
         // ignored 
      } 
      return Optional.absent();
   } 
 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
    } 
 
    public MinuteBucketIdProvider(Ticker ticker)
    { 
        this.ticker = ticker;
        this.initialValue = ticker.read();
    } 
 
    @Override 
    public int get() 
    { 
        return (int) ((ticker.read() - initialValue) / ONE_MINUTE_IN_NANOS);
    } 
 
    public long getLastSystemTimeMillis() 
    { 
        long nanosSinceBoundary = (ticker.read() - initialValue) % ONE_MINUTE_IN_NANOS;
        return currentTimeMillis() - TimeUnit.NANOSECONDS.toMillis(nanosSinceBoundary);
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
        TimeTracker(Ticker ticker) {
            this.ticker = ticker;
        } 
 
        void recordCurrentTime() { 
            lastRead = ticker.read();
        } 
 
        long timePassed() { 
            return ticker.read() - lastRead;
        } 
    } 
} 
5
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
        return Math.exp(alpha * (timestampInSeconds - landmarkInSeconds));
    } 
 
    private long getTickInSeconds() 
    { 
        return TimeUnit.NANOSECONDS.toSeconds(ticker.read());
    } 
 
    public DecayCounterSnapshot snapshot() 
    { 
        return new DecayCounterSnapshot(getCount(), getRate()); 
    } 
 
    @Override 
    public String toString()
    { 
        return toStringHelper(this)
                .add("count", getCount())
                .add("rate", getRate())
                .toString();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
        return Math.exp(alpha * (timestampInSeconds - landmarkInSeconds));
    } 
 
    private long getTickInSeconds() 
    { 
        return TimeUnit.NANOSECONDS.toSeconds(ticker.read());
    } 
 
    public DecayCounterSnapshot snapshot() 
    { 
        return new DecayCounterSnapshot(getCount(), getRate()); 
    } 
 
    @Override 
    public String toString()
    { 
        return toStringHelper(this)
                .add("count", getCount())
                .add("rate", getRate())
                .toString();
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
  } 
 
  @Override 
  public Double doSample() {
    T newSample = inputAccessor.get();
    long newTimestamp = ticker.read();
 
    double rate = 0;
    if (!samples.isEmpty()) {
      Pair<Long, Double> oldestSample = samples.peekLast();
 
      double dy = newSample.doubleValue() - oldestSample.getSecond();
      double dt = newTimestamp - oldestSample.getFirst();
      rate = dt == 0 ? 0 : (NANOS_PER_SEC * scaleFactor * dy) / dt;
    } 
 
    if (samples.remainingCapacity() == 0) samples.removeLast();
    samples.addFirst(Pair.of(newTimestamp, newSample.doubleValue()));
 
    return rate;
3
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
        this.scaleFactor = scaleFactor;
        samples = new LinkedBlockingDeque<Pair<Long, Double>>(windowSize);
    } 
     
    public double add(T newSample) {
        long newTimestamp = ticker.read();
 
        double rate = 0;
        if (!samples.isEmpty()) {
          Pair<Long, Double> oldestSample = samples.peekLast();
 
          double dy = newSample.doubleValue() - oldestSample.getSecond();
          double dt = newTimestamp - oldestSample.getFirst();
          rate = dt == 0 ? 0 : (NANOS_PER_SEC * scaleFactor * dy) / dt;
        } 
 
        if (samples.remainingCapacity() == 0) samples.removeLast();
        samples.addFirst(new Pair(newTimestamp, newSample.doubleValue()));
     
        return rate;
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
        ZoneHistory zoneHistory = getZoneHistory(loc);
        return doHasFailed(loc, zoneHistory);
    } 
 
    protected long currentTimeMillis() { 
        return TimeUnit.NANOSECONDS.toMillis(ticker.read());
    } 
     
    protected ZoneHistory getZoneHistory(Location loc) { 
        ZoneHistory zoneHistory = zoneHistories.get(loc);
        if (zoneHistory == null) {
            ZoneHistory newZoneHistory = newZoneHistory(loc);
            ZoneHistory oldZoneHistory = zoneHistories.putIfAbsent(loc, newZoneHistory);
            zoneHistory = (oldZoneHistory != null) ? oldZoneHistory : newZoneHistory;
        } 
        return zoneHistory;
    } 
 
    protected ZoneHistory newZoneHistory(Location loc) { 
        return new ZoneHistory(); 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
    this.nextRefillTime = -1;
  } 
 
  public synchronized long refill() 
  { 
    long now = ticker.read();
    if (now < nextRefillTime) {
      return 0; 
    } 
    nextRefillTime = now + periodInNanos;
    return numTokens;
  } 
} 
 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
This code example shows how to use the following methods:read
        this.backoffDelayIntervalsNanos = new long[backoffDelayIntervals.length];
        for (int i = 0; i < backoffDelayIntervals.length; i++) {
            this.backoffDelayIntervalsNanos[i] = backoffDelayIntervals[i].roundTo(NANOSECONDS);
        } 
 
        this.lastSuccessTime = this.ticker.read();
    } 
 
    public synchronized long getFailureCount() 
    { 
        return failureCount;
    } 
 
    public synchronized Duration getTimeSinceLastSuccess() 
    { 
        long lastSuccessfulRequest = this.lastSuccessTime;
        long value = ticker.read() - lastSuccessfulRequest;
        return new Duration(value, NANOSECONDS).convertToMostSuccinctTimeUnit();
    } 
 
4
CodeRank
Experience pair programming with AI  Get Codota for Java
See Code Examples for Guava Ticker Methods: