2222import  static  java .util .concurrent .TimeUnit .NANOSECONDS ;
2323
2424import  com .google .common .annotations .VisibleForTesting ;
25+ import  com .google .common .base .Ticker ;
2526import  com .google .common .collect .ForwardingMap ;
2627import  com .google .common .collect .ImmutableList ;
2728import  com .google .common .collect .ImmutableSet ;
3940import  io .grpc .Status ;
4041import  io .grpc .SynchronizationContext ;
4142import  io .grpc .SynchronizationContext .ScheduledHandle ;
42- import  io .grpc .internal .TimeProvider ;
4343import  java .net .SocketAddress ;
4444import  java .util .ArrayList ;
4545import  java .util .Collection ;
@@ -82,7 +82,7 @@ public final class OutlierDetectionLoadBalancer extends LoadBalancer {
8282  private  final  SynchronizationContext  syncContext ;
8383  private  final  Helper  childHelper ;
8484  private  final  GracefulSwitchLoadBalancer  switchLb ;
85-   private  TimeProvider   timeProvider ;
85+   private  Ticker   ticker ;
8686  private  final  ScheduledExecutorService  timeService ;
8787  private  ScheduledHandle  detectionTimerHandle ;
8888  private  Long  detectionTimerStartNanos ;
@@ -95,14 +95,14 @@ public final class OutlierDetectionLoadBalancer extends LoadBalancer {
9595  /** 
9696   * Creates a new instance of {@link OutlierDetectionLoadBalancer}. 
9797   */ 
98-   public  OutlierDetectionLoadBalancer (Helper  helper , TimeProvider   timeProvider ) {
98+   public  OutlierDetectionLoadBalancer (Helper  helper , Ticker   ticker ) {
9999    logger  = helper .getChannelLogger ();
100100    childHelper  = new  ChildHelper (checkNotNull (helper , "helper" ));
101101    switchLb  = new  GracefulSwitchLoadBalancer (childHelper );
102102    endpointTrackerMap  = new  EndpointTrackerMap ();
103103    this .syncContext  = checkNotNull (helper .getSynchronizationContext (), "syncContext" );
104104    this .timeService  = checkNotNull (helper .getScheduledExecutorService (), "timeService" );
105-     this .timeProvider  = timeProvider ;
105+     this .ticker  = ticker ;
106106    logger .log (ChannelLogLevel .DEBUG , "OutlierDetection lb created." );
107107  }
108108
@@ -151,7 +151,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
151151        // If a timer has started earlier we cancel it and use the difference between the start 
152152        // time and now as the interval. 
153153        initialDelayNanos  = Math .max (0L ,
154-             config .intervalNanos  - (timeProvider . currentTimeNanos () - detectionTimerStartNanos ));
154+             config .intervalNanos  - (ticker . read () - detectionTimerStartNanos ));
155155      }
156156
157157      // If a timer has been previously created we need to cancel it and reset all the call counters 
@@ -201,7 +201,7 @@ final class DetectionTimer implements Runnable {
201201
202202    @ Override 
203203    public  void  run () {
204-       detectionTimerStartNanos  = timeProvider . currentTimeNanos ();
204+       detectionTimerStartNanos  = ticker . read ();
205205
206206      endpointTrackerMap .swapCounters ();
207207
@@ -638,7 +638,7 @@ public boolean maxEjectionTimeElapsed(long currentTimeNanos) {
638638              config .baseEjectionTimeNanos  * ejectionTimeMultiplier ,
639639              maxEjectionDurationSecs );
640640
641-       return  currentTimeNanos  >  maxEjectionTimeNanos ;
641+       return  currentTimeNanos  -  maxEjectionTimeNanos  >  0 ;
642642    }
643643
644644    /** Tracks both successful and failed call counts. */ 
0 commit comments