Packages
xandra
0.18.0-rc.2
0.19.4
0.19.3
0.19.2
0.19.1
0.19.0
0.18.1
0.18.0
0.18.0-rc.9
0.18.0-rc.8
0.18.0-rc.7
0.18.0-rc.6
0.18.0-rc.5
0.18.0-rc.4
0.18.0-rc.3
0.18.0-rc.2
0.18.0-rc.1
0.17.0
0.16.0
0.15.0
0.15.0-rc.1
0.14.0
0.13.1
0.13.0
0.12.0
0.11.0
0.10.1
0.10.0
0.9.2
0.9.1
0.9.0
0.8.0
0.7.2
0.7.1
0.7.0
0.6.1
0.6.0
0.5.1
0.5.0
0.4.3
0.4.2
0.4.1
0.4.0
0.3.2
0.3.1
0.3.0
0.2.0
0.1.0
Fast, simple, and robust Cassandra driver for Elixir.
Current section
Files
Jump to
Current section
Files
lib/xandra/cluster/load_balancing_policy.ex
defmodule Xandra.Cluster.LoadBalancingPolicy do
@moduledoc """
A behaviour for defining load-balancing policies.
A load-balancing policy is a way to tell Xandra which nodes to query when connected
to a cluster.
For example, a simple load-balancing policy is `Xandra.Cluster.LoadBalancingPolicy.Random`,
which picks a random node for each query out of the ones that are up.
"""
@moduledoc since: "0.15.0"
alias Xandra.Cluster.Host
@typedoc """
The state of the load-balancing policy.
Can be any term and is passed around to all callbacks.
"""
@type state() :: term()
@doc """
Called to initialize the load-balancing policy.
`options` is given by the user when configuring the cluster, and is specific to
the load-balancing policy.
"""
@callback init(options :: term()) :: state()
@doc """
Called when the Cassandra gossip marks `host` as "up".
"""
@callback host_up(state(), host :: Host.t()) :: state
@doc """
Called when Xandra successfully connects to `host`.
"""
@callback host_connected(state(), host :: Host.t()) :: state()
@doc """
Called when the Cassandra cluster marks `host` as "down".
"""
@callback host_down(state(), host :: Host.t()) :: state()
@doc """
Called when the Cassandra cluster reports a new host that joined.
"""
@callback host_added(state(), host :: Host.t()) :: state()
@doc """
Called when the Cassandra cluster reports a host that left the cluster.
"""
@callback host_removed(state(), host :: Host.t()) :: state()
@doc """
Called to return a "plan", which is an enumerable of hosts to query in order.
"""
@callback query_plan(state()) :: {Enumerable.t(Host.t()), state()}
@doc """
Called to return a "plan", which is an enumerable of hosts to start connections in order.
"""
@callback hosts_plan(state()) :: {Enumerable.t(Host.t()), state()}
end