public interface LoadBalancingPolicy extends AutoCloseable
Modifier and Type | Interface and Description |
---|---|
static interface |
LoadBalancingPolicy.DistanceReporter
An object that the policy uses to signal decisions it makes about node distances.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Called when the cluster that this policy is associated with closes.
|
void |
init(Map<InetSocketAddress,Node> nodes,
LoadBalancingPolicy.DistanceReporter distanceReporter,
Set<InetSocketAddress> contactPoints)
Initializes this policy with the nodes discovered during driver initialization.
|
Queue<Node> |
newQueryPlan(Request request,
Session session)
Returns the coordinators to use for a new query.
|
void |
onAdd(Node node)
Called when a node is added to the cluster.
|
void |
onDown(Node node)
Called when a node is determined to be down.
|
void |
onRemove(Node node)
Called when a node is removed from the cluster.
|
void |
onUp(Node node)
Called when a node is determined to be up.
|
void init(@NonNull Map<InetSocketAddress,Node> nodes, @NonNull LoadBalancingPolicy.DistanceReporter distanceReporter, @NonNull Set<InetSocketAddress> contactPoints)
This method is guaranteed to be called exactly once per instance, and before any other method in this class.
nodes
- the nodes discovered by the driver when it connected to the cluster. When this
method is invoked, their state is guaranteed to be either NodeState.UP
or NodeState.UNKNOWN
. Node states may be updated concurrently while this method executes, but
if so you will receive a notification.distanceReporter
- an object that will be used by the policy to signal distance changes.contactPoints
- the set of contact points that the driver was initialized with (see SessionBuilder.addContactPoints(Collection)
). This is provided for reference, in case the
policy needs to handle those nodes in a particular way. Each address in this set should
normally have a corresponding entry in nodes
, except for contact points that were
down or invalid. If no contact points were provided, the driver defaults to 127.0.0.1:9042,
but the set will be empty.@NonNull Queue<Node> newQueryPlan(@Nullable Request request, @Nullable Session session)
Each new query will call this method, and try the returned nodes sequentially.
request
- the request that is being routed. Note that this can be null for some internal
uses.session
- the session that is executing the request. Note that this can be null for some
internal uses.ConcurrentLinkedQueue
is a good choice.void onAdd(@NonNull Node node)
The new node will have the state NodeState.UNKNOWN
. The actual state will be known
when:
void onUp(@NonNull Node node)
void onDown(@NonNull Node node)
void onRemove(@NonNull Node node)
void close()
close
in interface AutoCloseable
Copyright © 2017–2018. All rights reserved.