# `Infinitomata`
[🔗](https://github.com/am-kantox/finitomata/blob/v0.41.0/lib/infinitomata.ex#L1)

The sibling of `Finitomata`, but runs transparently in the cluster.

If you want to use a _stateful consistent hash ring_ like [`libring`](https://hexdocs.pm/libring),
  implement the behaviour `Finitomata.ClusterInfo` wrapping calls to it and 
  invoke `Finitomata.ClusterInfo.init(Impl)` before using `Infinitomata.start_fsm/4`.

The example of such an implementation for `libring` (assuming the named ring `@ring`
  has been started in the supervision tree) follows.

```elixir
defmodule MyApp.ClusterInfo do
  @moduledoc false
  @behaviour Finitomata.ClusterInfo

  @impl Finitomata.ClusterInfo
  def nodes(_fini_id), do: HashRing.nodes(@ring) -- [node()]

  @impl Finitomata.ClusterInfo
  def whois(_fini_id, id), do: HashRing.key_to_node(@ring, id)
end
```

## Consistency model

`Infinitomata` keeps a per-node view of the cluster-wide _FSM_ registry that is
  **eventually consistent**. Membership changes are propagated via `:pg` and reconciled
  by `synch/2`, which merges local and remote views (last writer wins per _FSM_ name).
  A call addressed to an _FSM_ that has not propagated to the local view yet is retried;
  on a failed remote call the node re-synchronizes and backs off before retrying. Tune
  the retry behaviour via the `:infinitomata_attempts`, `:infinitomata_poll_interval`,
  `:infinitomata_rpc_timeout`, `:infinitomata_backoff_base`, and `:infinitomata_backoff_max`
  application config keys.

# `count`
*since 0.16.0* 

Count of children

# `random`
*since 0.18.0* 

Returns the random _FSM_ from the pool

# `start_fsm`
*since 0.15.0* 

```elixir
@spec start_fsm(Finitomata.id(), Finitomata.fsm_name(), module(), any()) ::
  DynamicSupervisor.on_start_child()
```

Starts the _FSM_ in the distributed environment. See `Finitomata.start_fsm/4` for docs and options

# `start_link`
*since 0.16.0* 

# `synch`
*since 0.19.0* 

```elixir
@spec synch(Finitomata.id(), [node()] | false) :: :ok
```

Synchronizes the local `Infinitomata` instance with the cluster

---

*Consult [api-reference.md](api-reference.md) for complete listing*
