Top Description Inners Fields Constructors Methods
io.grpc

public abstract Class LoadBalancerProvider

extends Factory
Class Inheritance
Annotations
@ExperimentalApi:https://github.com/grpc/grpc-java/issues/1771
Imports
com.google.common.base.MoreObjects, io.grpc.NameResolver.ConfigOrError, java.util.Map

Provider of LoadBalancers. Each provider is bounded to a load-balancing policy name.

Implementations can be automatically discovered by gRPC via Java's SPI mechanism. For automatic discovery, the implementation must have a zero-argument constructor and include a resource named META-INF/services/io.grpc.LoadBalancerProvider in their JAR. The file's contents should be the implementation's class name. Implementations that need arguments in their constructor can be manually registered by LoadBalancerRegistry#register.

Implementations should not throw. If they do, it may interrupt class loading. If exceptions may reasonably occur for implementation-specific reasons, implementations should generally handle the exception gracefully and return false from isAvailable().

Since
1.17.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private static class

Field Summary

Modifier and TypeField and Description
private static final NameResolver.ConfigOrError
UNKNOWN_CONFIG

A sentinel value indicating that service config is not supported.

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public final boolean
equals(Object
the reference object with which to compare.
other
)

Overrides java.lang.Object.equals.

Uses identity equality.
public abstract String
getPolicyName()

Returns the load-balancing policy name associated with this provider, which makes it selectable via LoadBalancerRegistry#getProvider.

public abstract int
getPriority()

A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration.

public final int
hashCode()

Overrides java.lang.Object.hashCode.

Returns a hash code value for the object.
public abstract boolean
isAvailable()

Whether this provider is available for use, taking the current environment into consideration.

public NameResolver.ConfigOrError

Returns:

a tuple of the fully parsed and validated balancer configuration, else the Status.
parseLoadBalancingPolicyConfig
(Map<String, ?>
The Map representation of the load balancing policy choice.
rawLoadBalancingPolicyConfig
)

Parses the config for the Load Balancing policy unpacked from the service config.

public final String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from io.grpc.LoadBalancer.Factory:
newLoadBalancer

Field Detail

UNKNOWN_CONFIGback to summary
private static final NameResolver.ConfigOrError UNKNOWN_CONFIG

A sentinel value indicating that service config is not supported. This can be used to indicate that parsing of the service config is neither right nor wrong, but doesn't have any meaning.

Constructor Detail

LoadBalancerProviderback to summary
public LoadBalancerProvider()

Method Detail

equalsback to summary
public final boolean equals(Object other)

Overrides java.lang.Object.equals.

Uses identity equality.

Parameters
other:Object

Doc from java.lang.Object.equals.

the reference object with which to compare.

Returns:boolean

Doc from java.lang.Object.equals.

true if this object is the same as the obj argument; false otherwise.

Annotations
@Override
getPolicyNameback to summary
public abstract String getPolicyName()

Returns the load-balancing policy name associated with this provider, which makes it selectable via LoadBalancerRegistry#getProvider. This is called only when the class is loaded. It shouldn't change, and there is no point doing so.

The policy name should consist of only lower case letters letters, underscore and digits, and can only start with letters.

getPriorityback to summary
public abstract int getPriority()

A priority, from 0 to 10 that this provider should be used, taking the current environment into consideration. 5 should be considered the default, and then tweaked based on environment detection. A priority of 0 does not imply that the provider wouldn't work; just that it should be last in line.

hashCodeback to summary
public final int hashCode()

Overrides java.lang.Object.hashCode.

Doc from java.lang.Object.hashCode.

Returns a hash code value for the object. This method is supported for the benefit of hash tables such as those provided by java.util.HashMap.

The general contract of hashCode is:

  • Whenever it is invoked on the same object more than once during an execution of a Java application, the hashCode method must consistently return the same integer, provided no information used in equals comparisons on the object is modified. This integer need not remain consistent from one execution of an application to another execution of the same application.
  • If two objects are equal according to the equals method, then calling the hashCode method on each of the two objects must produce the same integer result.
  • It is not required that if two objects are unequal according to the equals method, then calling the hashCode method on each of the two objects must produce distinct integer results. However, the programmer should be aware that producing distinct integer results for unequal objects may improve the performance of hash tables.
Returns:int

a hash code value for this object.

Annotations
@Override
isAvailableback to summary
public abstract boolean isAvailable()

Whether this provider is available for use, taking the current environment into consideration. If false, newLoadBalancer is not safe to be called.

parseLoadBalancingPolicyConfigback to summary
public NameResolver.ConfigOrError parseLoadBalancingPolicyConfig(Map<String, ?> rawLoadBalancingPolicyConfig)

Parses the config for the Load Balancing policy unpacked from the service config. This will return a ConfigOrError which contains either the successfully parsed config, or the Status representing the failure to parse. Implementations are expected to not throw exceptions but return a Status representing the failure. If successful, the load balancing policy config should be immutable.

Parameters
rawLoadBalancingPolicyConfig:Map<String, ?>

The Map representation of the load balancing policy choice.

Returns:NameResolver.ConfigOrError

a tuple of the fully parsed and validated balancer configuration, else the Status.

Since
1.20.0
See Also
A24-lb-policy-config.md
toStringback to summary
public final String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override
io.grpc back to summary

private final Class LoadBalancerProvider.UnknownConfig

extends Object
Class Inheritance

Constructor Summary

AccessConstructor and Description
pack-priv

Method Summary

Modifier and TypeMethod and Description
public String
toString()

Overrides java.lang.Object.toString.

Returns a string representation of the object.
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAllwaitwaitwait

Constructor Detail

UnknownConfigback to summary
pack-priv UnknownConfig()

Method Detail

toStringback to summary
public String toString()

Overrides java.lang.Object.toString.

Doc from java.lang.Object.toString.

Returns a string representation of the object.

Returns:String

a string representation of the object.

Annotations
@Override