Skip to content

Commit 8974a30

Browse files
authored
util: Mark OutlierDetectionLb classes final
None of these classes were intended to be extended. Even non-public classes need final to prevent mocks from doing horrible things.
1 parent d88ef97 commit 8974a30

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

util/src/main/java/io/grpc/util/OutlierDetectionLoadBalancer.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ public void shutdown() {
189189
* This timer will be invoked periodically, according to configuration, and it will look for any
190190
* outlier subchannels.
191191
*/
192-
class DetectionTimer implements Runnable {
192+
final class DetectionTimer implements Runnable {
193193

194194
OutlierDetectionLoadBalancerConfig config;
195195
ChannelLogger logger;
@@ -217,7 +217,7 @@ public void run() {
217217
* This child helper wraps the provided helper so that it can hand out wrapped {@link
218218
* OutlierDetectionSubchannel}s and manage the address info map.
219219
*/
220-
class ChildHelper extends ForwardingLoadBalancerHelper {
220+
final class ChildHelper extends ForwardingLoadBalancerHelper {
221221

222222
private Helper delegate;
223223

@@ -259,7 +259,7 @@ public void updateBalancingState(ConnectivityState newState, SubchannelPicker ne
259259
}
260260
}
261261

262-
class OutlierDetectionSubchannel extends ForwardingSubchannel {
262+
final class OutlierDetectionSubchannel extends ForwardingSubchannel {
263263

264264
private final Subchannel delegate;
265265
private EndpointTracker endpointTracker;
@@ -398,7 +398,7 @@ protected Subchannel delegate() {
398398
/**
399399
* Wraps the actual listener so that state changes from the actual one can be intercepted.
400400
*/
401-
class OutlierDetectionSubchannelStateListener implements SubchannelStateListener {
401+
final class OutlierDetectionSubchannelStateListener implements SubchannelStateListener {
402402

403403
private final SubchannelStateListener delegate;
404404

@@ -428,7 +428,7 @@ public String toString() {
428428
* This picker delegates the actual picking logic to a wrapped delegate, but associates a {@link
429429
* ClientStreamTracer} with each pick to track the results of each subchannel stream.
430430
*/
431-
class OutlierDetectionPicker extends SubchannelPicker {
431+
final class OutlierDetectionPicker extends SubchannelPicker {
432432

433433
private final SubchannelPicker delegate;
434434

@@ -454,7 +454,7 @@ public PickResult pickSubchannel(PickSubchannelArgs args) {
454454
* Builds instances of a {@link ClientStreamTracer} that increments the call count in the
455455
* tracker for each closed stream.
456456
*/
457-
class ResultCountingClientStreamTracerFactory extends ClientStreamTracer.Factory {
457+
final class ResultCountingClientStreamTracerFactory extends ClientStreamTracer.Factory {
458458

459459
private final EndpointTracker tracker;
460460

@@ -498,7 +498,7 @@ public void streamClosed(Status status) {
498498
/**
499499
* Tracks additional information about the endpoint needed for outlier detection.
500500
*/
501-
static class EndpointTracker {
501+
static final class EndpointTracker {
502502

503503
private OutlierDetectionLoadBalancerConfig config;
504504
// Marked as volatile to assure that when the inactive counter is swapped in as the new active
@@ -642,7 +642,7 @@ public boolean maxEjectionTimeElapsed(long currentTimeNanos) {
642642
}
643643

644644
/** Tracks both successful and failed call counts. */
645-
private static class CallCounter {
645+
private static final class CallCounter {
646646
AtomicLong successCount = new AtomicLong();
647647
AtomicLong failureCount = new AtomicLong();
648648

@@ -663,7 +663,7 @@ public String toString() {
663663
/**
664664
* Maintains a mapping from endpoint (a set of addresses) to their trackers.
665665
*/
666-
static class EndpointTrackerMap extends ForwardingMap<Set<SocketAddress>, EndpointTracker> {
666+
static final class EndpointTrackerMap extends ForwardingMap<Set<SocketAddress>, EndpointTracker> {
667667
private final Map<Set<SocketAddress>, EndpointTracker> trackerMap;
668668

669669
EndpointTrackerMap() {
@@ -784,7 +784,7 @@ static List<OutlierEjectionAlgorithm> forConfig(OutlierDetectionLoadBalancerConf
784784
* required rate is not fixed, but is based on the mean and standard deviation of the success
785785
* rates of all of the addresses.
786786
*/
787-
static class SuccessRateOutlierEjectionAlgorithm implements OutlierEjectionAlgorithm {
787+
static final class SuccessRateOutlierEjectionAlgorithm implements OutlierEjectionAlgorithm {
788788

789789
private final OutlierDetectionLoadBalancerConfig config;
790790

@@ -869,7 +869,7 @@ static double standardDeviation(Collection<Double> values, double mean) {
869869
}
870870
}
871871

872-
static class FailurePercentageOutlierEjectionAlgorithm implements OutlierEjectionAlgorithm {
872+
static final class FailurePercentageOutlierEjectionAlgorithm implements OutlierEjectionAlgorithm {
873873

874874
private final OutlierDetectionLoadBalancerConfig config;
875875

@@ -970,7 +970,7 @@ private OutlierDetectionLoadBalancerConfig(Builder builder) {
970970
}
971971

972972
/** Builds a new {@link OutlierDetectionLoadBalancerConfig}. */
973-
public static class Builder {
973+
public static final class Builder {
974974
long intervalNanos = 10_000_000_000L; // 10s
975975
long baseEjectionTimeNanos = 30_000_000_000L; // 30s
976976
long maxEjectionTimeNanos = 300_000_000_000L; // 300s
@@ -1035,7 +1035,7 @@ public OutlierDetectionLoadBalancerConfig build() {
10351035
}
10361036

10371037
/** The configuration for success rate ejection. */
1038-
public static class SuccessRateEjection {
1038+
public static final class SuccessRateEjection {
10391039

10401040
public final int stdevFactor;
10411041
public final int enforcementPercentage;
@@ -1094,7 +1094,7 @@ public SuccessRateEjection build() {
10941094
}
10951095

10961096
/** The configuration for failure percentage ejection. */
1097-
public static class FailurePercentageEjection {
1097+
public static final class FailurePercentageEjection {
10981098
public final int threshold;
10991099
public final int enforcementPercentage;
11001100
public final int minimumHosts;

0 commit comments

Comments
 (0)