use crate::RS2Stream;
use async_trait::async_trait;
use serde::{Deserialize, Serialize};
use std::time::Duration;
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommonConfig {
pub batch_size: usize,
pub timeout_ms: u64,
pub retry_attempts: usize,
pub compression: bool,
}
impl Default for CommonConfig {
fn default() -> Self {
Self {
batch_size: 100,
timeout_ms: 30000,
retry_attempts: 3,
compression: false,
}
}
}
#[async_trait]
pub trait StreamConnector<T>: Send + Sync
where
T: Send + 'static,
{
type Config: Send + Sync;
type Error: std::error::Error + Send + Sync + 'static;
type Metadata: Send + Sync;
async fn from_source(&self, config: Self::Config) -> Result<RS2Stream<T>, Self::Error>;
async fn to_sink(
&self,
stream: RS2Stream<T>,
config: Self::Config,
) -> Result<Self::Metadata, Self::Error>;
async fn health_check(&self) -> Result<bool, Self::Error>;
async fn metadata(&self) -> Result<Self::Metadata, Self::Error>;
fn name(&self) -> &'static str;
fn version(&self) -> &'static str;
}
#[async_trait]
pub trait BidirectionalConnector<T>: StreamConnector<T>
where
T: Send + 'static,
{
async fn bidirectional(
&self,
input_config: Self::Config,
output_config: Self::Config,
) -> Result<
(
RS2Stream<T>,
Box<dyn Fn(RS2Stream<T>) -> Result<(), Self::Error> + Send + Sync>,
),
Self::Error,
>;
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthStatus {
pub healthy: bool,
pub message: String,
pub last_check: Duration,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ConnectionStats {
pub messages_sent: u64,
pub messages_received: u64,
pub bytes_sent: u64,
pub bytes_received: u64,
pub errors: u64,
pub uptime: Duration,
}