-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Creata a forwarding class for HealthCheckingLoadBalancerUtil to allow…
… existing users migrate.
- Loading branch information
Showing
1 changed file
with
68 additions
and
0 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
services/src/main/java/io/grpc/services/HealthCheckingLoadBalancerUtil.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,68 @@ | ||
/* | ||
* Copyright 2018 The gRPC 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.grpc.services; | ||
|
||
import io.grpc.ExperimentalApi; | ||
import io.grpc.LoadBalancer; | ||
import io.grpc.LoadBalancer.Helper; | ||
|
||
/** | ||
* Utility for enabling | ||
* <a href="https://github.com/grpc/proposal/blob/master/A17-client-side-health-checking.md"> | ||
* client-side health checking</a> for {@link LoadBalancer}s. | ||
* | ||
* @deprecated Use {@link io.grpc.protobuf.services.HealthCheckingLoadBalancerUtil} instead. | ||
*/ | ||
@Deprecated | ||
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/5025") | ||
public class HealthCheckingLoadBalancerUtil { | ||
private HealthCheckingLoadBalancerUtil() { | ||
} | ||
|
||
/** | ||
* Creates a health-checking-capable LoadBalancer. This method is used to implement | ||
* health-checking-capable {@link io.grpc.LoadBalancer.Factory}s, which will typically written | ||
* this way: | ||
* | ||
* <pre> | ||
* public class HealthCheckingFooLbFactory extends LoadBalancer.Factory { | ||
* // This is the original balancer implementation that doesn't have health checking | ||
* private final LoadBalancer.Factory fooLbFactory; | ||
* | ||
* ... | ||
* | ||
* // Returns the health-checking-capable version of FooLb | ||
* public LoadBalancer newLoadBalancer(Helper helper) { | ||
* return HealthCheckingLoadBalancerUtil.newHealthCheckingLoadBalancer(fooLbFactory, helper); | ||
* } | ||
* } | ||
* </pre> | ||
* | ||
* <p>As a requirement for the original LoadBalancer, it must call | ||
* {@code Helper.createSubchannel()} from the {@link Helper#getSynchronizationContext() | ||
* Synchronization Context}, or {@code createSubchannel()} will throw. | ||
* | ||
* @param factory the original factory that implements load-balancing logic without health | ||
* checking | ||
* @param helper the helper passed to the resulting health-checking LoadBalancer. | ||
*/ | ||
public static LoadBalancer newHealthCheckingLoadBalancer( | ||
LoadBalancer.Factory factory, Helper helper) { | ||
return io.grpc.protobuf.services.HealthCheckingLoadBalancerUtil.newHealthCheckingLoadBalancer( | ||
factory, helper); | ||
} | ||
} |