22
22
import static java .util .concurrent .TimeUnit .NANOSECONDS ;
23
23
24
24
import com .google .common .annotations .VisibleForTesting ;
25
+ import com .google .common .base .Ticker ;
25
26
import com .google .common .collect .ForwardingMap ;
26
27
import com .google .common .collect .ImmutableList ;
27
28
import com .google .common .collect .ImmutableSet ;
39
40
import io .grpc .Status ;
40
41
import io .grpc .SynchronizationContext ;
41
42
import io .grpc .SynchronizationContext .ScheduledHandle ;
42
- import io .grpc .internal .TimeProvider ;
43
43
import java .net .SocketAddress ;
44
44
import java .util .ArrayList ;
45
45
import java .util .Collection ;
@@ -82,7 +82,7 @@ public final class OutlierDetectionLoadBalancer extends LoadBalancer {
82
82
private final SynchronizationContext syncContext ;
83
83
private final Helper childHelper ;
84
84
private final GracefulSwitchLoadBalancer switchLb ;
85
- private TimeProvider timeProvider ;
85
+ private Ticker ticker ;
86
86
private final ScheduledExecutorService timeService ;
87
87
private ScheduledHandle detectionTimerHandle ;
88
88
private Long detectionTimerStartNanos ;
@@ -95,14 +95,14 @@ public final class OutlierDetectionLoadBalancer extends LoadBalancer {
95
95
/**
96
96
* Creates a new instance of {@link OutlierDetectionLoadBalancer}.
97
97
*/
98
- public OutlierDetectionLoadBalancer (Helper helper , TimeProvider timeProvider ) {
98
+ public OutlierDetectionLoadBalancer (Helper helper , Ticker ticker ) {
99
99
logger = helper .getChannelLogger ();
100
100
childHelper = new ChildHelper (checkNotNull (helper , "helper" ));
101
101
switchLb = new GracefulSwitchLoadBalancer (childHelper );
102
102
endpointTrackerMap = new EndpointTrackerMap ();
103
103
this .syncContext = checkNotNull (helper .getSynchronizationContext (), "syncContext" );
104
104
this .timeService = checkNotNull (helper .getScheduledExecutorService (), "timeService" );
105
- this .timeProvider = timeProvider ;
105
+ this .ticker = ticker ;
106
106
logger .log (ChannelLogLevel .DEBUG , "OutlierDetection lb created." );
107
107
}
108
108
@@ -151,7 +151,7 @@ public Status acceptResolvedAddresses(ResolvedAddresses resolvedAddresses) {
151
151
// If a timer has started earlier we cancel it and use the difference between the start
152
152
// time and now as the interval.
153
153
initialDelayNanos = Math .max (0L ,
154
- config .intervalNanos - (timeProvider . currentTimeNanos () - detectionTimerStartNanos ));
154
+ config .intervalNanos - (ticker . read () - detectionTimerStartNanos ));
155
155
}
156
156
157
157
// 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 {
201
201
202
202
@ Override
203
203
public void run () {
204
- detectionTimerStartNanos = timeProvider . currentTimeNanos ();
204
+ detectionTimerStartNanos = ticker . read ();
205
205
206
206
endpointTrackerMap .swapCounters ();
207
207
@@ -638,7 +638,7 @@ public boolean maxEjectionTimeElapsed(long currentTimeNanos) {
638
638
config .baseEjectionTimeNanos * ejectionTimeMultiplier ,
639
639
maxEjectionDurationSecs );
640
640
641
- return currentTimeNanos > maxEjectionTimeNanos ;
641
+ return currentTimeNanos - maxEjectionTimeNanos > 0 ;
642
642
}
643
643
644
644
/** Tracks both successful and failed call counts. */
0 commit comments