macula_rpc_router (macula v0.20.5)
View SourceRPC call routing strategies. Selects which provider to use for a call (local or remote).
Summary
Functions
Create new router state.
Select local handler (returns first one).
Select provider using stateless strategy. For local_first, random, and closest strategies.
Select provider using closest strategy (requires local node ID).
Select provider using stateful strategy (for round_robin).
Select random remote provider.
Types
-type provider_info() :: macula_rpc_dht:provider_info().
-type registration() :: macula_rpc_registry:registration().
-type router_state() :: #{strategy := strategy(), round_robin_index := non_neg_integer()}.
-type strategy() :: local_first | round_robin | random | closest.
Functions
-spec new_state(strategy()) -> router_state().
Create new router state.
-spec select_local([registration()]) -> {ok, registration()} | not_found.
Select local handler (returns first one).
-spec select_provider(strategy(), [registration()], [provider_info()]) -> {local, registration()} | {remote, provider_info()} | {error, no_provider}.
Select provider using stateless strategy. For local_first, random, and closest strategies.
-spec select_provider_closest(binary(), [registration()], [provider_info()]) -> {local, registration()} | {remote, provider_info()} | {error, no_provider}.
Select provider using closest strategy (requires local node ID).
-spec select_provider_stateful(router_state(), [registration()], [provider_info()]) -> {{local, registration()} | {remote, provider_info()} | {error, no_provider}, router_state()}.
Select provider using stateful strategy (for round_robin).
-spec select_remote_random([provider_info()]) -> {ok, provider_info()} | not_found.
Select random remote provider.