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>
impl<T> AppState<T>
Sourcepub fn new(
module_id: String,
orchestrator_api: String,
secret_client: Arc<SecretClient>,
user_state: T,
) -> Self
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.
Sourcepub fn with_advanced_features(
module_id: String,
orchestrator_api: String,
secret_client: Arc<SecretClient>,
user_state: T,
config: AppConfig,
) -> Self
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.
Sourcepub fn orchestrator_api(&self) -> &str
pub fn orchestrator_api(&self) -> &str
Returns the orchestrator API URL.
Sourcepub fn secret_client(&self) -> &Arc<SecretClient>
pub fn secret_client(&self) -> &Arc<SecretClient>
Returns the configured SecretClient
instance.
Sourcepub fn internal_messaging_client(&self) -> Option<&InternalMessagingClient>
pub fn internal_messaging_client(&self) -> Option<&InternalMessagingClient>
Retrieves a reference to the InternalMessagingClient
if available.
Sourcepub fn pending_internal_responses_map(
&self,
) -> Option<Arc<Mutex<HashMap<Uuid, Sender<Result<EncodedMessage, Error>>>>>>
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.
Sourcepub async fn send_message(
&self,
target: &str,
message: EncodedMessage,
preferences: Option<ChannelPreferences>,
) -> Result<(), Error>
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.
Sourcepub async fn send_message_via_channel(
&self,
channel_type: ChannelType,
message: EncodedMessage,
) -> Result<(), Error>
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.
Sourcepub async fn send_request(
&self,
target: &str,
request: EncodedMessage,
preferences: Option<ChannelPreferences>,
) -> Result<EncodedMessage, Error>
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
Sourcepub fn available_channels(&self) -> Vec<ChannelType>
pub fn available_channels(&self) -> Vec<ChannelType>
Get the available channel types.
Returns a vector of channel types that are currently available and connected.
Sourcepub fn channel_capabilities(
&self,
channel_type: ChannelType,
) -> Option<&ChannelCapabilities>
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.
Sourcepub fn has_channel(&self, channel_type: ChannelType) -> bool
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.
Sourcepub async fn channel_health(&self) -> HashMap<ChannelType, bool>
pub async fn channel_health(&self) -> HashMap<ChannelType, bool>
Get channel health status.
Returns a map of channel types to their current connection status.
Sourcepub fn recommend_channel(
&self,
target: &str,
preferences: Option<ChannelPreferences>,
) -> Option<ChannelType>
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.
Sourcepub async fn get_performance_metrics(
&self,
) -> Result<HashMap<ChannelType, ChannelMetrics>, Error>
pub async fn get_performance_metrics( &self, ) -> Result<HashMap<ChannelType, ChannelMetrics>, Error>
Get performance metrics for all channels
Sourcepub async fn get_sla_status(
&self,
) -> Result<HashMap<ChannelType, SlaStatus>, Error>
pub async fn get_sla_status( &self, ) -> Result<HashMap<ChannelType, SlaStatus>, Error>
Get SLA compliance status for all channels
Sourcepub async fn get_performance_comparison(
&self,
) -> Result<PerformanceComparisonReport, Error>
pub async fn get_performance_comparison( &self, ) -> Result<PerformanceComparisonReport, Error>
Get performance comparison report
Sourcepub fn update_routing_matrix(&self, matrix: RoutingMatrix) -> Result<(), Error>
pub fn update_routing_matrix(&self, matrix: RoutingMatrix) -> Result<(), Error>
Update routing matrix for smart routing
Sourcepub fn get_routing_matrix(&self) -> Result<RoutingMatrix, Error>
pub fn get_routing_matrix(&self) -> Result<RoutingMatrix, Error>
Get current routing matrix
Sourcepub async fn get_request_stats(&self) -> Result<(usize, Vec<Uuid>), Error>
pub async fn get_request_stats(&self) -> Result<(usize, Vec<Uuid>), Error>
Get statistics about pending requests
Sourcepub fn set_advanced_features_enabled(&mut self, enabled: bool)
pub fn set_advanced_features_enabled(&mut self, enabled: bool)
Enable or disable advanced features at runtime