예제 #1
0
 /**
  * checks if the stats that we used to compute drop rate is stale or not. Stale meaning, we use a
  * certain interval (configured to be 5 seconds) to count the number of calls, latency, etc during
  * that 5 seconds. So every 5 seconds we'll want to refresh the window of interval for counting.
  *
  * <p>So if it's stale, we'll call CallTrackerImpl to refresh the window
  *
  * @param now
  */
 private void checkStale(long now) {
   if (_callTrackerStats.stale(now)) {
     // this code is a bit strange at first i.e. why it's not _callTrackerStats =
     // _callTracker.getCallStats();
     // but instead it's just _callTracker.getCallStats(); even though getCallStats returns a new
     // Object.
     // but this is fine because getCallStats() will eventually call Tracker.rolloverStats() which
     // has a listener!
     // the listener is actually {@see DegraderImpl.rollOverStats(CallTracker.CallStats)} which
     // will update
     // _callTrackerStats with the new stats. So we're fine.
     _callTracker.getCallStats();
   }
 }
예제 #2
0
  public DegraderImpl(Config config) {
    _config = new ImmutableConfig(config);
    _name = _config.getName();
    _clock = config.getClock();
    _callTracker = config.getCallTracker();
    _callTrackerStats = _callTracker.getCallStats();
    _maxDropDuration = config.getMaxDropDuration();

    reset();

    // Added cast below for backward compatibilty. Remove when possible
    _callTracker.addStatsRolloverEventListener(
        new CallTracker.StatsRolloverEventListener() {
          public void onStatsRollover(CallTracker.StatsRolloverEvent event) {
            rolloverStats(event.getCallStats());
          }
        });
  }