Struct foca::Foca

source · []
pub struct Foca<T, C, RNG, B: BroadcastHandler<T>> { /* private fields */ }
Expand description

Foca is the main interaction point of this crate.

It manages the cluster members and executes the SWIM protocol. It’s intended as a low-level guts-exposed safe view into the protocol allowing any kind of Identity and transport to be used.

Most interactions with Foca require the caller to provide a Runtime type, which is simply a way to turn the result of an operation inside out (think callbacks, or an out parameter like void* out). This allows Foca to avoid deciding anything related to how it interacts with the operating system.

Implementations

Create a new Foca instance with custom broadcasts disabled.

This is a simple shortcut for Foca::with_custom_broadcast using the NoCustomBroadcast type to deny any form of custom broadcast.

Initialize a new Foca instance.

Getter for the current identity.

Re-enable joining a cluster with the same identity after being declared Down.

This is intended to be use by implementations that decide not to opt-in on auto-rejoining: once Foca detects its Down you’ll only be able to receive messages (which will likely stop after a short while since the cluster things you are down).

Whatever is controlling the running Foca will then have to wait for at least Config::remove_down_after before attempting a rejoin. Then you can call this method followed by a [Foca::announce(T)] to go back to the cluster.

Change the current identity.

Foca will declare its previous identity as Down and immediatelly notify the cluster about the changes.

Notice that changing your identity does not guarantee a successful (re)join. After changing it and disseminating the updates Foca will only know it’s actually accepted after receiving a message addressed to it.

Watch for Notification::Active if you want more confidence about a successful (re)join.

Intended to be used when identities carry metadata that occasionally changes.

Iterate over the currently active cluster members.

Returns the number of active members in the cluster.

May only be used as a bound for Foca::iter_members if no Foca method that takes &mut self is called in-between.

Applies cluster updates to this foca instance.

This is for advanced usage. It’s intended as a way to unlock more elaborate synchronization protocols: implementations may choose to unify their cluster knowledge (say: a streaming join protocol or a periodic sync) and use Foca::apply_many as a way to feed Foca this new (external) knowledge.

Attempt to join the cluster dst belongs to.

Sends a Message::Announce to dst. If accepted, we’ll receive a Message::Feed as reply.

Disseminate updates/broadcasts to cluster members.

This instructs Foca to pick Config::num_indirect_probes random active members and send a Message::Gossip containing cluster updates.

Intended for more complex scenarios where an implementation wants to attempt reducing the time it takes for information to propagate thoroughly.

Only disseminate custom broadcasts to cluster members

This instructs Foca to pick Config::num_indirect_probes random active members that pass the BroadcastHandler::should_add_broadcast_data check. It guarantees custom broadcast dissemination if there are candidate members available.

No cluster update will be sent with these messages. Intended to be used in tandem with a non-default should_add_broadcast_data.

Leave the cluster by declaring our own identity as down.

If there are active members, we select a few are selected and notify them of our exit so that the cluster learns about it quickly.

This is the cleanest way to terminate a running Foca.

Register some data to be broadcast along with Foca messages.

Calls into this instance’s BroadcastHandler and reacts accordingly.

React to a previously scheduled timer event.

See Runtime::submit_after.

Reports the current length of the cluster updates queue.

Updates are transmitted Config::max_transmissions times at most or until we learn new information about the same member.

Repports the current length of the custom broadcast queue.

Custom broadcasts are transmitted Config::max_transmissions times at most or until they get invalidated by another custom broadcast.

Replaces the current configuration with a new one.

Most of the time a static configuration is more than enough, but for use-cases where the cluster size can drastically change during normal operations, changing the configuration parameters is a nicer alternative to recreating the Foca instance.

Presently, attempting to change Config::probe_period or Config::probe_rtt results in Error::InvalidConfig; For such cases it’s recommended to recreate your Foca instance. When an error occurrs, every configuration parameter remains unchanged.

Handle data received from the network.

Data larger than the configured limit will be rejected. Errors are expected if you’re receiving arbitrary data (which very likely if you are listening to a socket address).

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more

Instruments this type with the current Span, returning an Instrumented wrapper. Read more

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more