Struct AppState

Source
pub struct AppState<T> {
Show 14 fields pub user_state: T, pub internal_messaging_client: Option<InternalMessagingClient>, pub pending_internal_responses: Option<Arc<Mutex<HashMap<Uuid, Sender<Result<EncodedMessage, Error>>>>>>, pub config: Option<AppConfig>, pub tcp_channel: Option<Arc<TcpChannel>>, pub ipc_channel: Option<Arc<IpcChannel>>, pub tcp_capabilities: ChannelCapabilities, pub ipc_capabilities: ChannelCapabilities, pub module_message_handlers: Option<Arc<Mutex<HashMap<String, ModuleMessageHandler>>>>, pub channel_router: Option<Arc<ChannelRouter>>, pub failover_manager: Option<Arc<FailoverManager>>, pub performance_monitoring: Option<Arc<PerformanceMonitoringSystem>>, pub priority_queue: Option<Arc<PriorityMessageQueue>>, pub request_multiplexer: Option<Arc<RequestMultiplexer>>, /* private fields */
}
Expand description

Shared application state for a PyWatt module with independent channel support and advanced features.

Contains SDK-provided fields (module_id, orchestrator_api, secret_client) plus user-defined state of type T, independent communication channels, and advanced features for performance, reliability, and monitoring.

Fields§

§user_state: T

User-provided application state

§internal_messaging_client: Option<InternalMessagingClient>§pending_internal_responses: Option<Arc<Mutex<HashMap<Uuid, Sender<Result<EncodedMessage, Error>>>>>>§config: Option<AppConfig>

Application configuration

§tcp_channel: Option<Arc<TcpChannel>>

TCP channel for communication with the orchestrator

§ipc_channel: Option<Arc<IpcChannel>>

IPC channel for communication with the orchestrator (Unix Domain Sockets)

§tcp_capabilities: ChannelCapabilities

Capabilities supported by the TCP channel

§ipc_capabilities: ChannelCapabilities

Capabilities supported by the IPC channel

§module_message_handlers: Option<Arc<Mutex<HashMap<String, ModuleMessageHandler>>>>

Handlers for module-to-module messages, keyed by source module ID

§channel_router: Option<Arc<ChannelRouter>>

Smart channel routing engine

§failover_manager: Option<Arc<FailoverManager>>

Failover management system

§performance_monitoring: Option<Arc<PerformanceMonitoringSystem>>

Performance monitoring system

§priority_queue: Option<Arc<PriorityMessageQueue>>

Priority message queue

§request_multiplexer: Option<Arc<RequestMultiplexer>>

Request multiplexer for concurrent operations

Implementations§

Source§

impl<T> AppState<T>

Source

pub fn new( module_id: String, orchestrator_api: String, secret_client: Arc<SecretClient>, user_state: T, ) -> Self

Create a new AppState with the given SDK context and user state.

Source

pub fn with_advanced_features( module_id: String, orchestrator_api: String, secret_client: Arc<SecretClient>, user_state: T, config: AppConfig, ) -> Self

Create a new AppState with advanced features enabled.

Source

pub fn module_id(&self) -> &str

Returns the module’s ID.

Examples found in repository?
examples/macro_example.rs (line 61)
58async fn status_handler(Extension(state): Extension<AppState<MyModuleState>>) -> Json<Value> {
59    Json(serde_json::json!({
60        "status": "ok",
61        "module_id": state.module_id(),
62        "database_connected": !state.user_state.database_url.is_empty()
63    }))
64}
Source

pub fn orchestrator_api(&self) -> &str

Returns the orchestrator API URL.

Source

pub fn secret_client(&self) -> &Arc<SecretClient>

Returns the configured SecretClient instance.

Source

pub fn custom(&self) -> &T

Returns a reference to the custom user state.

Source

pub fn internal_messaging_client(&self) -> Option<&InternalMessagingClient>

Retrieves a reference to the InternalMessagingClient if available.

Source

pub fn pending_internal_responses_map( &self, ) -> Option<Arc<Mutex<HashMap<Uuid, Sender<Result<EncodedMessage, Error>>>>>>

Retrieves a clone of the PendingInternalResponses map if available.

Source

pub async fn send_message( &self, target: &str, message: EncodedMessage, preferences: Option<ChannelPreferences>, ) -> Result<(), Error>

Send a message using the best available channel based on preferences with advanced routing.

This method automatically selects the appropriate channel based on the target, channel preferences, message characteristics, and uses the smart routing engine for optimal performance and reliability.

Source

pub async fn send_message_via_channel( &self, channel_type: ChannelType, message: EncodedMessage, ) -> Result<(), Error>

Send a message using a specific channel type.

This method allows explicit channel selection when the caller knows which channel they want to use, bypassing the automatic selection logic.

Source

pub async fn send_request( &self, target: &str, request: EncodedMessage, preferences: Option<ChannelPreferences>, ) -> Result<EncodedMessage, Error>

Send a request and wait for response using request multiplexing

Source

pub fn available_channels(&self) -> Vec<ChannelType>

Get the available channel types.

Returns a vector of channel types that are currently available and connected.

Source

pub fn channel_capabilities( &self, channel_type: ChannelType, ) -> Option<&ChannelCapabilities>

Get the capabilities of a specific channel.

Returns the capabilities supported by the specified channel type, or None if the channel is not available.

Source

pub fn has_channel(&self, channel_type: ChannelType) -> bool

Check if a specific channel type is available.

Returns true if the specified channel type is configured and available.

Source

pub async fn channel_health(&self) -> HashMap<ChannelType, bool>

Get channel health status.

Returns a map of channel types to their current connection status.

Source

pub fn recommend_channel( &self, target: &str, preferences: Option<ChannelPreferences>, ) -> Option<ChannelType>

Get recommended channel for a target.

Returns the recommended channel type for communicating with a specific target, based on channel preferences and availability.

Source

pub async fn get_performance_metrics( &self, ) -> Result<HashMap<ChannelType, ChannelMetrics>, Error>

Get performance metrics for all channels

Source

pub async fn get_sla_status( &self, ) -> Result<HashMap<ChannelType, SlaStatus>, Error>

Get SLA compliance status for all channels

Source

pub async fn get_performance_comparison( &self, ) -> Result<PerformanceComparisonReport, Error>

Get performance comparison report

Source

pub fn update_routing_matrix(&self, matrix: RoutingMatrix) -> Result<(), Error>

Update routing matrix for smart routing

Source

pub fn get_routing_matrix(&self) -> Result<RoutingMatrix, Error>

Get current routing matrix

Source

pub async fn get_request_stats(&self) -> Result<(usize, Vec<Uuid>), Error>

Get statistics about pending requests

Source

pub fn set_advanced_features_enabled(&mut self, enabled: bool)

Enable or disable advanced features at runtime

Trait Implementations§

Source§

impl<T: Send + Sync + 'static> AppStateExt<T> for AppState<T>

Source§

async fn register_module_message_handler<F, Fut>( &self, source_module_id: String, handler: F, ) -> Result<(), Error>
where F: Fn(String, Uuid, EncodedMessage) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<(), Error>> + Send + 'static,

Register a handler for module-to-module messages from a specific source module
Source§

async fn remove_module_message_handler( &self, source_module_id: &str, ) -> Result<(), Error>

Remove a registered handler for a specific source module
Source§

impl<T: Clone> Clone for AppState<T>

Source§

fn clone(&self) -> AppState<T>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for AppState<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<T> Freeze for AppState<T>
where T: Freeze,

§

impl<T> !RefUnwindSafe for AppState<T>

§

impl<T> Send for AppState<T>
where T: Send,

§

impl<T> Sync for AppState<T>
where T: Sync,

§

impl<T> Unpin for AppState<T>
where T: Unpin,

§

impl<T> !UnwindSafe for AppState<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> FromRef<T> for T
where T: Clone,

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

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

fn in_current_span(self) -> Instrumented<Self>

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

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

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

fn with_current_subscriber(self) -> WithDispatch<Self>

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

impl<T> ErasedDestructor for T
where T: 'static,

Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

Source§

impl<T> MaybeSendSync for T