-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract inner types from RoundRobinLoadBalancer (#2724)
Motivation: The RoundRobinLoadBalancer contains a bunch of code that is doing a good deal more than load balancing, namely it's doing pooling, circuit breaking, and other things. This both makes the implementation hard to read and reason about and makes the inner pieces difficult to reuse for future load balancer implementation. Modifications: - Extract the types into their own files. - Hide a bit of the internal state to start to define abstraction boundaries. Note that this is pretty minimal so far, just accessors etc, so to keep this PR mechanical in nature.
- Loading branch information
1 parent
53ae438
commit f00a486
Showing
5 changed files
with
618 additions
and
530 deletions.
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
servicetalk-loadbalancer/src/main/java/io/servicetalk/loadbalancer/Exceptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/* | ||
* Copyright © 2021-2023 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.servicetalk.loadbalancer; | ||
|
||
import io.servicetalk.client.api.ConnectionRejectedException; | ||
import io.servicetalk.client.api.NoActiveHostException; | ||
import io.servicetalk.client.api.NoAvailableHostException; | ||
import io.servicetalk.concurrent.internal.ThrowableUtils; | ||
|
||
final class Exceptions { | ||
|
||
static final class StacklessNoAvailableHostException extends NoAvailableHostException { | ||
private static final long serialVersionUID = 5942960040738091793L; | ||
|
||
private StacklessNoAvailableHostException(final String message) { | ||
super(message); | ||
} | ||
|
||
@Override | ||
public Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
|
||
static StacklessNoAvailableHostException newInstance(String message, Class<?> clazz, String method) { | ||
return ThrowableUtils.unknownStackTrace(new StacklessNoAvailableHostException(message), clazz, method); | ||
} | ||
} | ||
|
||
static final class StacklessNoActiveHostException extends NoActiveHostException { | ||
|
||
private static final long serialVersionUID = 7500474499335155869L; | ||
|
||
private StacklessNoActiveHostException(final String message) { | ||
super(message); | ||
} | ||
|
||
@Override | ||
public Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
|
||
static StacklessNoActiveHostException newInstance(String message, Class<?> clazz, String method) { | ||
return ThrowableUtils.unknownStackTrace(new StacklessNoActiveHostException(message), clazz, method); | ||
} | ||
} | ||
|
||
static final class StacklessConnectionRejectedException extends ConnectionRejectedException { | ||
private static final long serialVersionUID = -4940708893680455819L; | ||
|
||
private StacklessConnectionRejectedException(final String message) { | ||
super(message); | ||
} | ||
|
||
@Override | ||
public Throwable fillInStackTrace() { | ||
return this; | ||
} | ||
|
||
static StacklessConnectionRejectedException newInstance(String message, Class<?> clazz, String method) { | ||
return ThrowableUtils.unknownStackTrace(new StacklessConnectionRejectedException(message), clazz, method); | ||
} | ||
} | ||
|
||
private Exceptions() { | ||
// no instances | ||
} | ||
} |
40 changes: 40 additions & 0 deletions
40
servicetalk-loadbalancer/src/main/java/io/servicetalk/loadbalancer/HealthCheckConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright © 2021-2023 Apple Inc. and the ServiceTalk project authors | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package io.servicetalk.loadbalancer; | ||
|
||
import io.servicetalk.concurrent.api.Executor; | ||
|
||
import java.time.Duration; | ||
|
||
final class HealthCheckConfig { | ||
final Executor executor; | ||
final Duration healthCheckInterval; | ||
final Duration jitter; | ||
final int failedThreshold; | ||
final long healthCheckResubscribeLowerBound; | ||
final long healthCheckResubscribeUpperBound; | ||
|
||
HealthCheckConfig(final Executor executor, final Duration healthCheckInterval, final Duration healthCheckJitter, | ||
final int failedThreshold, final long healthCheckResubscribeLowerBound, | ||
final long healthCheckResubscribeUpperBound) { | ||
this.executor = executor; | ||
this.healthCheckInterval = healthCheckInterval; | ||
this.failedThreshold = failedThreshold; | ||
this.jitter = healthCheckJitter; | ||
this.healthCheckResubscribeLowerBound = healthCheckResubscribeLowerBound; | ||
this.healthCheckResubscribeUpperBound = healthCheckResubscribeUpperBound; | ||
} | ||
} |
Oops, something went wrong.