Package io.github.alexandrepiveteau.echo

Types

Link copied to clipboard
interface Exchange<I, O> : SendExchange<I, O> , ReceiveExchange<I, O>

An interface defining an Exchange, which is able to generate some flows that are used for bidirectional communication and transmission of data.

Link copied to clipboard
interface MutableSite<in T, out M> : Site<M>

A mutable version of Site, which allows the insertion of the events T through its event method. Each MutableSite is associated with a globally unique SiteIdentifier, which will be used when yielding events.

Link copied to clipboard
fun interface ReceiveExchange<out I, in O>

An interface defining an asymmetrical replication site, biased towards receiving data.

Link copied to clipboard
fun interface SendExchange<in I, out O>

An interface defining an asymmetrical replication site, biased towards sending data.

Link copied to clipboard
interface Site<out M> : Exchange<Message.Incoming, Message.Outgoing>

An interface describing a Site in the distributed system. When collected, it will emit the latest aggregated model.

Link copied to clipboard
enum SyncStrategy : Enum<SyncStrategy>

An enumeration defining the strategy that will implement the replication protocol. A SyncStrategy defines the behavior for both sides of the replication protocol.

Functions

Link copied to clipboard
fun <I, O> ReceiveExchange<I, O>.asReceiveExchange(): ReceiveExchange<I, O>

Returns the ReceiveExchange.

Link copied to clipboard
fun <I, O> SendExchange<I, O>.asSendExchange(): SendExchange<I, O>

Returns the SendExchange.

Link copied to clipboard
fun <I, O> Exchange<I, O>.buffer(capacity: Int = Channel.BUFFERED): Exchange<I, O>

Transforms an Exchange by buffering its contents. This buffers the underlying flows in both directions.

Link copied to clipboard
fun exchange(log: MutableEventLog, strategy: SyncStrategy = SyncStrategy.Continuous): Exchange<Message.Incoming, Message.Outgoing>
fun exchange(vararg events: Pair<EventIdentifier, ByteArray>, strategy: SyncStrategy = SyncStrategy.Continuous): Exchange<Message.Incoming, Message.Outgoing>

Creates a new Exchange with a backing event log.

Link copied to clipboard
fun <I, O> Exchange<I, O>.flowOn(context: CoroutineContext): Exchange<I, O>

Transforms an Exchange by making it flow on a specific dispatcher. The same CoroutineContext will be used in both directions for the communicating Flows.

fun <T, M> MutableSite<T, M>.flowOn(context: CoroutineContext): MutableSite<T, M>

Transforms a MutableSite by making it flow on a specific dispatcher. The same CoroutineContext will be used in both directions for the communicating Flows.

Link copied to clipboard
fun <T, M1, M2> MutableSite<T, M1>.map(f: (M1) -> M2): MutableSite<T, M2>

Transforms a MutableSite to make it return a different kind of model. This may be particularly useful when creating abstractions backed by a MutableSite that should not expose some implementation details.

Link copied to clipboard
inline fun <M, T> mutableSite(    identifier: SiteIdentifier,     history: MutableHistory<M>,     strategy: SyncStrategy = SyncStrategy.Continuous): MutableSite<T, M>
inline fun <M, T> mutableSite(    identifier: SiteIdentifier,     initial: M,     projection: OneWayProjection<M, T>,     vararg events: Pair<EventIdentifier, T>,     strategy: SyncStrategy = SyncStrategy.Continuous): MutableSite<T, M>

Creates a new MutableSite for the provided SiteIdentifier, with a backing log. Additionally, this overload takes a OneWayProjection and lets you specify a projection to apply to the data, to have custom MutableSite.event arguments.

inline fun <T> mutableSite(    identifier: SiteIdentifier,     vararg events: Pair<EventIdentifier, T>,     strategy: SyncStrategy = SyncStrategy.Continuous): MutableSite<T, Unit>

Creates a new MutableSite for the provided SiteIdentifier, with a backing history. The current model value of the site will always be Unit, since it does not perform aggregations.

inline fun <M, T, R> mutableSite(    identifier: SiteIdentifier,     history: MutableHistory<R>,     strategy: SyncStrategy = SyncStrategy.Continuous,     noinline transform: (R) -> M): MutableSite<T, M>
inline fun <M, T, R> mutableSite(    identifier: SiteIdentifier,     initial: R,     projection: OneWayProjection<R, T>,     vararg events: Pair<EventIdentifier, T>,     strategy: SyncStrategy = SyncStrategy.Continuous,     noinline transform: (R) -> M): MutableSite<T, M>

Creates a new MutableSite for the provided SiteIdentifier, with a backing mutable history. Additionally, this overload takes a OneWayProjection and lets you specify a projection to apply to the data, to have custom MutableSite.event arguments.

inline fun <M, T, C> mutableSite(    identifier: SiteIdentifier,     initial: M,     projection: TwoWayProjection<M, T, C>,     vararg events: Pair<EventIdentifier, T>,     strategy: SyncStrategy = SyncStrategy.Continuous): MutableSite<T, M>

Creates a new MutableSite for the provided SiteIdentifier, with a backing log. Additionally, this overload takes a TwoWayProjection and lets you specify a projection to apply to the data, to have custom MutableSite.event arguments.

inline fun <M, T, C, R> mutableSite(    identifier: SiteIdentifier,     initial: R,     projection: TwoWayProjection<R, T, C>,     vararg events: Pair<EventIdentifier, T>,     strategy: SyncStrategy = SyncStrategy.Continuous,     noinline transform: (R) -> M): MutableSite<T, M>

Creates a new MutableSite for the provided SiteIdentifier, with a backing mutable history. Additionally, this overload takes a TwoWayProjection and lets you specify a projection to apply to the data, to have custom MutableSite.event arguments.

fun <M, T, R> mutableSite(    identifier: SiteIdentifier,     history: MutableHistory<R>,     eventSerializer: KSerializer<T>,     format: BinaryFormat = DefaultBinaryFormat,     strategy: SyncStrategy = SyncStrategy.Continuous,     transform: (R) -> M): MutableSite<T, M>

Creates a new MutableSite for the provided SiteIdentifier, with a backing mutable history.

Link copied to clipboard
inline fun <M, T> site(history: MutableHistory<M>, strategy: SyncStrategy = SyncStrategy.Continuous): Site<M>
inline fun <T> site(vararg events: Pair<EventIdentifier, T>, strategy: SyncStrategy = SyncStrategy.Continuous): Site<Unit>

Creates a new Site with a backing history.

fun <M, R> site(    history: MutableHistory<R>,     strategy: SyncStrategy = SyncStrategy.Continuous,     transform: (R) -> M): Site<M>

Creates a new Site for the provided SiteIdentifier, with a backing log.

inline fun <M, T> site(    initial: M,     projection: OneWayProjection<M, T>,     vararg events: Pair<EventIdentifier, T>,     strategy: SyncStrategy = SyncStrategy.Continuous): Site<M>

Creates a new Site for the provided SiteIdentifier, with a backing log. Additionally, this overload takes a OneWayProjection and lets you specify a projection to apply to the data.

inline fun <M, T, C> site(    initial: M,     projection: TwoWayProjection<M, T, C>,     vararg events: Pair<EventIdentifier, T>,     strategy: SyncStrategy = SyncStrategy.Continuous): Site<M>

Creates a new Site for the provided SiteIdentifier, with a backing log. Additionally, this overload takes a TwoWayProjection and lets you specify a projection to apply to the data.

Link copied to clipboard
suspend fun <I, O> sync(vararg exchanges: Exchange<I, O>)

Syncs the provided Exchange until they are all done communicating. The sync operator creates a chain of Exchange, and for each pair of the chain, some flows that are then used for communication until all the data is eventually synced.

suspend fun <I, O> sync(first: (Flow<I>) -> Flow<O>, second: (Flow<O>) -> Flow<I>)

Syncs the provided bidirectional flows until they are done communicating. The sync operator creates bidirectional communication between the two Flow generator functions.

Link copied to clipboard
suspend fun <I, O> syncAll(vararg exchanges: Exchange<I, O>)

Syncs the provided Exchange until they are all done communicating. The syncAll operator creates some pairs of Exchange, forming a fully connected graph.

Properties

Link copied to clipboard
val DefaultBinaryFormat: BinaryFormat

The BinaryFormat that's used by default for serialization of events and changes when events are inserted in the event and change logs.