View Source partisan_peer_service_manager behaviour (partisan v5.0.0-beta.21)
Link to this section Summary
Functions
Tries to create a new connection to a node, but only if required. If successful it stores the new connection record in the partisan_peer_connections table.
Create a new connection to a node specified by NodeSpec and options Opts. If a new connection is created it will be stored in the partisan_peer_connections table.
Nodes and for each call function Fun passing the node as argumentNodes and for each call function Fun passing the node as argumentServerRef that is either local or located at remote process when the remote node is connected via disterl. Trying to send a message to a remote server reference when the process is located at a node connected with Partisan will return ok but will not succeed.Mod implements callback supports_capability/1 returns the result of calling the callback passing argument Arg. Otherwise, returns false.Link to this section Types
-type connect_opts() :: #{prune => boolean()}.
-type forward_opts() :: #{ack => boolean(), causal_label => atom(), channel => partisan:channel(), clock => any(), partition_key => non_neg_integer(), transitive => boolean()} | [{ack, boolean()} | {causal_label, atom()} | {channel, partisan:channel()} | {clock, any()} | {partition_key, non_neg_integer()} | {transitive, boolean()}].
-type on_event_fun() :: fun(() -> ok) | fun((node()) -> ok) | fun((node(), partisan:channel()) -> ok).
-type partitions() :: [{reference(), partisan:node_spec()}].
-type server_ref() :: partisan_remote_ref:p() | partisan_remote_ref:encoded_pid() | partisan_remote_ref:n() | partisan_remote_ref:encoded_name() | pid() | (RegName :: atom()) | {RegName :: atom(), node()} | {global, atom()} | {via, module(), ViaName :: atom()}.
Link to this section Callbacks
-callback cast_message(ServerRef :: server_ref(), Msg :: partisan:message()) -> ok.
-callback cast_message(ServerRef :: server_ref(), Msg :: partisan:message(), Opts :: forward_opts()) -> ok.
-callback cast_message(Node :: node(), ServerRef :: server_ref(), Msg :: partisan:message(), Opts :: forward_opts()) -> ok.
-callback decode(term()) -> term().
-callback forward_message(ServerRef :: server_ref(), Msg :: partisan:message()) -> ok.
-callback forward_message(ServerRef :: server_ref(), Msg :: partisan:message(), Opts :: forward_opts()) -> ok.
-callback forward_message(Node :: node(), ServerRef :: server_ref(), Msg :: partisan:message(), Opts :: forward_opts()) -> ok.
-callback get_local_state() -> term().
-callback inject_partition(partisan:node_spec(), ttl()) -> {ok, reference()} | {error, not_implemented}.
-callback join(partisan:node_spec()) -> ok.
-callback leave() -> ok.
-callback leave(partisan:node_spec()) -> ok.
-callback members() -> [node()].
-callback members_for_orchestration() -> [partisan:node_spec()].
-callback on_down(node(), on_event_fun()) -> ok | {error, not_implemented}.
-callback on_down(node(), on_event_fun(), #{channel => partisan:channel()}) -> ok | {error, not_implemented}.
-callback on_up(node(), on_event_fun()) -> ok | {error, not_implemented}.
-callback on_up(node(), on_event_fun(), #{channel => partisan:channel()}) -> ok | {error, not_implemented}.
-callback partitions() -> {ok, partitions()} | {error, not_implemented}.
-callback receive_message(node(), partisan:channel(), partisan:message()) -> ok.
-callback reserve(atom()) -> ok | {error, no_available_slots}.
-callback resolve_partition(reference()) -> ok | {error, not_implemented}.
-callback send_message(node(), partisan:message()) -> ok.
-callback start_link() -> {ok, pid()} | ignore | {error, term()}.
-callback supports_capability(Arg :: atom()) -> boolean().
-callback sync_join(partisan:node_spec()) -> ok | {error, not_implemented}.
-callback update_members([node()]) -> ok | {error, not_implemented}.
Link to this section Functions
-spec connect(Node :: partisan:node_spec()) -> ok.
Tries to create a new connection to a node, but only if required. If successful it stores the new connection record in the partisan_peer_connections table.
connect/2 with options #{prune => false}.
-spec connect(Node :: partisan:node_spec(), connect_opts()) -> ok | {ok, StaleSpecs :: [partisan:node_spec()]}.
Create a new connection to a node specified by NodeSpec and options Opts. If a new connection is created it will be stored in the partisan_peer_connections table.
If option prune is true returns the tuple {ok, L :: [ partisan:node_spec()]} where list L is the list of nodes specifications for all stale nodes. Otherwise returns ok.
A specification is stale if there is another specification for the same node for which we already have one or more active connections. A stale specification will exist when a node has crashed (without leaving the cluster) and later on returned with a different IP address i.e. a normal situation on cloud orchestration platforms. In this case the membership set (partisan_membership_set) will have two node specifications for the same node (with differing values for the listen_addrs property).
partisan_membership_set.
Nodes and for each call function Fun passing the node as argument
Nodes and for each call function Fun passing the node as argument
-spec mynode() -> atom().
-spec myself() -> partisan:node_spec().
-spec process_forward(ServerRef :: server_ref(), Msg :: any()) -> ok.
ServerRef that is either local or located at remote process when the remote node is connected via disterl. Trying to send a message to a remote server reference when the process is located at a node connected with Partisan will return ok but will not succeed.
-spec send_message(node(), partisan:message()) -> ok.
-spec supports_capability(Mode :: module(), Arg :: atom()) -> boolean().
Mod implements callback supports_capability/1 returns the result of calling the callback passing argument Arg. Otherwise, returns false.