RpcLoadBalancer.LoadBalancer.SelectionAlgorithm behaviour
(rpc_load_balancer v0.3.0)
Copy Markdown
View Source
Behaviour for load balancer node selection.
Summary
Functions
Returns the union of caches required by every algorithm passed in.
Returns the cache modules an algorithm needs.
Types
Callbacks
@callback caches() :: [module()]
@callback child_specs(load_balancer_name(), opts :: keyword()) :: [ Supervisor.child_spec() ]
@callback choose_from_nodes(load_balancer_name(), [node()], opts :: keyword()) :: node()
@callback choose_nodes(load_balancer_name(), [node()], pos_integer(), opts :: keyword()) :: [node()]
@callback init(load_balancer_name(), opts :: keyword()) :: :ok
@callback local?() :: boolean()
@callback on_node_change( load_balancer_name(), {:joined | :left, [node()]} ) :: :ok
@callback release_node(load_balancer_name(), node()) :: :ok
Functions
Returns the union of caches required by every algorithm passed in.
Used by RpcLoadBalancer.Application to start exactly the cache
agents the configured algorithms need — no more, no less.
Returns the cache modules an algorithm needs.
Algorithms that don't require any caches can omit the caches/0
callback entirely; we treat that as [].
@spec child_specs(module(), load_balancer_name(), keyword()) :: [ Supervisor.child_spec() ]
@spec choose_from_nodes(module(), load_balancer_name(), [node()], keyword()) :: node()
@spec choose_nodes(module(), load_balancer_name(), [node()], pos_integer(), keyword()) :: [node()]
@spec get_algorithm(load_balancer_name()) :: {:ok, module() | nil} | {:error, ErrorMessage.t()}
@spec init(module(), load_balancer_name(), keyword()) :: :ok
@spec on_node_change(module(), load_balancer_name(), {:joined | :left, [node()]}) :: :ok
@spec put_algorithm(load_balancer_name(), module()) :: :ok | {:error, ErrorMessage.t()}
@spec release_node(module(), load_balancer_name(), node()) :: :ok