Module reactive_messaging::prelude
source · Expand description
Re-exports of types – out of the internal directory and module structure – useful for users of this crate
Macros§
- For internal use: defines
ProcessorUniType&SenderChannelbased on the given [Channels] parameter (for use when spawning processors with MessagingService::spawn_unresponsive_processor() & MessagingService::spawn_responsive_processor().) - Macro to close, atomically-ish, all Multis passed in as parameters
- Instantiates & allocates resources for a stateful CompositeSocketClient (suitable for the “Composite Protocol Stacking” pattern), ready to have processors added by spawn_unresponsive_client_processor!() or spawn_responsive_client_processor!().
- Instantiates & allocates resources for a stateful CompositeSocketServer (suitable for the “Composite Protocol Stacking” pattern), ready to have processors added by spawn_unresponsive_server_processor!() or spawn_responsive_server_processor!() and to be later started by CompositeSocketServer::start_multi_protocol() – using the default “Atomic” channels (see [new_composite_fullsync_server!()] & [new_composite_crossbeam_server!()] for alternatives).
Params: - Instantiates & allocates resources for a stateless CompositeSocketClient (suitable for single protocol communications), ready to be later started by
start_unresponsive_client_processor!()orstart_responsive_client_processor!(). - Instantiates & allocates resources for a stateless CompositeSocketServer (suitable for single protocol communications), ready to be later started by
start_unresponsive_server_processor!()orstart_responsive_server_processor!(). - Spawns a processor for a client (previously instantiated by
new_composite_socket_client!()) that may communicate with the server using multiple protocols / multiple calls to this macro with different parameters (or to its “responsive” variant) – finally calling CompositeSocketClient::start_multi_protocol() when the “Composite Protocol Stacking” is complete. - Starts a client (previously instantiated by new_socket_client!()) that will communicate with the server using a single protocol – as defined by the given
dialog_processor_builder_fn, a builder of “responsive”Streams as specified in [GenericCompositeSocketClient::spawn_responsive_processor()].
If you want to follow the “Composite Protocol Stacking” pattern, see the [spawn_responsive_composite_client_processor!()] macro instead. - Starts a server (previously instantiated by new_socket_server!()) that will communicate with clients using a single protocol – as defined by the given
dialog_processor_builder_fn, a builder of “responsive”Streams as specified in CompositeSocketServer::spawn_responsive_processor().
If you want to follow the “Composite Protocol Stacking” pattern, see the [spawn_responsive_composite_server_processor!()] macro instead. - Starts a client (previously instantiated by
new_socket_client!()) that will communicate with the server using a single protocol – as defined by the givendialog_processor_builder_fn, a builder of “unresponsive”Streams as specified in CompositeSocketClient::spawn_unresponsive_processor(). - Starts a server (previously instantiated by new_socket_server!()) that will communicate with clients using a single protocol – as defined by the given
dialog_processor_builder_fn, a builder of “unresponsive”Streams as specified in CompositeSocketServer::spawn_unresponsive_processor().
If you want to follow the “Composite Protocol Stacking” pattern, see the [spawn_unresponsive_composite_server_processor!()] macro instead. - Macro to close, atomically-ish, all Unis passed as parameters
Structs§
- Abstracts out the TCP/IP intricacies for establishing (and retrying) connections, while still enabling the “Protocol Stack Composition” pattern by accepting existing connections to be provided (instead of opening new ones).
- Real definition & implementation for our Socket Client, full of generic parameters.
Probably you want to instantiate this structure through the sugared macros new_socket_client!() or new_composite_socket_client!() instead. Generic Parameters: - Real definition & implementation for our Socket Server, full of generic parameters.
Probably you want to instantiate this structure through the sugared macros new_socket_server!() or new_composite_socket_server!() instead. Generic Parameters: - The abstraction for handling server connections – here, the connections are provided through a
Streaminstead of through the TCP/IP API directly. This enables the “Protocol Stack Composition” pattern, as already existing connections may be also added to theStream(in addition to fresh incoming ones).
When the end-of-stream is reached (possibly due to a “server shutdown” request), theStreamwill returnNone. - Implements something that could be called the “Zero-Cost Const Configuration Pattern”, that produces a
usizewhose goal is to be the only const parameter of a generic struct (avoiding the alternative of bloating it with several const params).
When using the const “query functions” defined here inifs, the compiler will have the opportunity to cancel out any unreachable code (zero-cost abstraction).
Some commonly used combinations may be pre-defined in some enum variants, but you may always build unmapped possibilities through [Self::custom()].
Usage examples: Multiis an event handler capable of having several “listeners” – all of which receives all events.
With this struct, it is possible to:- Special
Streamimplementation to avoid using dynamic dispatching, so to allow the compiler to fully optimize the whole event consumption chain.
The following paths are covered: - Wrapper type for data providing an atomic reference counter for dropping control, similar to
Arc, but allowing a custom allocator to be used – OgreAllocator. providing reference counting similar to Arc - Wrapper type for data that requires a custom Drop to be called (through an OgreAllocator). Similar to C++’s
unique_ptr - Represents a reactive channel connected to a remote peer, through which we’re able to send out “local messages” of type
RetryableSenderImpl::LocalMessages.
the Self::send() method honors whatever retrying config is specified in [RetryableSenderImpl::CONST_CONFIG]. IMPLEMENTATION NOTE: GAT traits (to reduce the number of generic parameters) couldn’t be used here – even after applying this compiler bug workaround https://github.com/rust-lang/rust/issues/102211#issuecomment-1513931928 – the “error: implementation ofstd::marker::Sendis not general enough” bug kept on popping up in user provided closures that called other async functions. - Indicates the receiver end of a channel was dropped, therefore the element of type
Tcouldn’t be sent and is being returned back along with the error indication.
Important: This is an unrecoverable situation, so trying again is futile. - Abstracts out, from servers, the connection handling so to enable the “Protocol Stack Composition” pattern:
Binds to a network listening interface and port and starts a network event loop for accepting connections, supplying them to an internal ConnectionChannel (while also allowing manually fed connections). - A wrapper for a TcpStream – attaching a custom “state” and unique id to it.
This abstraction plays a role in enabling the “Composite Protocol Stacking” design pattern.
IMPLEMENTATION NOTE: The crate::prelude::Peer object still holds a copy of the state – synced elsewhere with us here – in the future, this should be reworked. - Socket options for the local peer to be set when the connection is established
- Contains the producer-side Uni handle used to interact with the
unievent – for closing the stream, requiring stats, …
Enums§
- Event issued by Composite Protocol Clients & Servers when connections are made or dropped
- Honors the Zero-Cost Instrumentation Pattern for the [stream_executors]:
Designed to be used as a const generic parameter for Structs, causes the conditional instrumentation code in client structs to be selectively compiled – see the implemented const methods for documentation of each available instrument. - Event issued by Composite Protocol Clients & Servers to their Reactive Processors.
The user code may use those events to maintain a list of connected parties, be notified of stop/close/quit requests, init/de-init sessions, etc. Note that thePeerobjects received in those events may be used, at any time, to send messages to the remote party – like “Shutting down. Goodbye”. IMPLEMENTATION NOTE: GAT traits (to reduce the number of generic parameters) couldn’t be used here – even after applying this compiler bug workaround https://github.com/rust-lang/rust/issues/102211#issuecomment-1513931928 – the “error: implementation ofstd::marker::Sendis not general enough” bug kept on popping up in user provided closures that called other async functions. - Specifies how to behave when communication failures happen
Traits§
- Defines common abstractions on how [Uni]s receives produced events and delivers them to
Streams.
Implementors should also implement one of ChannelProducer or [UniZeroCopyChannel]. NOTE: all async functions are out of the hot path, so theasync_traitwon’t impose performance penalties - Source of events for MutinyStream.
- Defines abstractions specific to [Uni] channels
- Defines how to send events (to a [Uni] or [Multi]).
- Defines abstractions specific to [Uni] channels
- A fully fledged
Multichannel, that has both the producer and consumer parts Also, laverages generic programming by allowing simpler generic parameters: - Defines a fully fledged
Unichannel, that has both the producer and consumer parts Also, laverages generic programming by allowing simpler generic parameters: - This trait exists to allow simplifying generic declarations of concrete Multi types. See also [GenericUni].
Usage: - This trait exists to allow simplifying generic declarations of concrete Uni types. See also [GenericMulti].
Usage: - Base trait for server and client services functionalities
- Dictates how data slots should be acquired and returned for future reuse.
Two APIs are available: - Trait that should be implemented by enums that model the “remote messages” to be consumed by a “Responsive Processor” – “remote messages” may either be messages produced by the remote server or by the remote client (when we are implementing the opposite peer).
This trait, therefore, specifies how todeserialize()enum variants received by the remote peer (like RON, for textual protocols) - Trait that should be implemented by enums that model the “local messages” to be sent to the remote peer – “local messages” may either be messages generated by the server or by the client, depending on if you’re building a server or client.
This trait, therefore, specifies how to: - Adherents will, typically, also implement [ReactiveMessagingUnresponsiveSerializer].
By upgrading your type with this trait, it is possible to build a “Responsive Processor”, where the returnedStreamcontains the messages to be sent as an answer to the remote peer.
This trait, therefore, specifies (to the internal sender) how to handle special response cases, like “no answer” and “disconnection” messages.
Functions§
- RON deserializer
- RON serializer
Type Aliases§
- Concrete type of the
Streams this crate produces.
Type for theStreamwe create when reading from the remote peer.
This type is intended to be used only for the first level ofdialog_processor_builder()s you pass to the [SocketClient] or [SocketServer], as Rust Generics isn’t able to infer a genericStreamtype in this situation (in which theStreamis created inside the generic function itself).
If your logic uses functions that receiveStreams, you’ll want flexibility to do whatever you want with theStream(which would no longer be aMutinyStream), so declare such functions as: - Default
Multifor those who wants to useArcas the wrapping type for payloads - Default
Multifor those who want the more performant OgreArc as the wrapping type for their payloads - Default
UniBuilderfor “moving” data around – good for small payloads (< 1k) whose types don’t require a customDropfunction - Default ‘UniBuilder’ for “zero-copying” data that will either be shared around or has a reasonably “big” payload (> 1k)