use crate::cluster::slotmap::SlotMap;
use crate::cmd::Cmd;
use crate::connection::info::{PubSubChannelOrPattern, PubSubSubscriptionKind};
use crate::value::{Result, Value};
use async_trait::async_trait;
use std::collections::{HashMap, HashSet};
#[async_trait]
pub trait PubSubSynchronizer: Send + Sync {
fn add_desired_subscriptions(
&self,
channels: HashSet<PubSubChannelOrPattern>,
subscription_type: PubSubSubscriptionKind,
);
fn remove_desired_subscriptions(
&self,
channels: Option<HashSet<PubSubChannelOrPattern>>,
subscription_type: PubSubSubscriptionKind,
);
fn add_current_subscriptions(
&self,
channels: HashSet<PubSubChannelOrPattern>,
subscription_type: PubSubSubscriptionKind,
address: String,
);
fn remove_current_subscriptions(
&self,
channels: HashSet<PubSubChannelOrPattern>,
subscription_type: PubSubSubscriptionKind,
address: String,
);
fn get_subscription_state(
&self,
) -> (
HashMap<PubSubSubscriptionKind, HashSet<PubSubChannelOrPattern>>,
HashMap<PubSubSubscriptionKind, HashSet<PubSubChannelOrPattern>>,
);
fn trigger_reconciliation(&self);
fn is_synchronized(&self) -> bool {
let (desired, actual) = self.get_subscription_state();
desired == actual
}
fn remove_current_subscriptions_for_addresses(&self, _addresses: &HashSet<String>) {
}
fn handle_topology_refresh(&self, _new_slot_map: &SlotMap) {
}
async fn intercept_pubsub_command(&self, _cmd: &Cmd) -> Option<Result<Value>> {
None
}
async fn wait_for_sync(
&self,
_timeout_ms: u64,
_expected_channels: Option<HashSet<Vec<u8>>>,
_expected_patterns: Option<HashSet<Vec<u8>>>,
_expected_sharded: Option<HashSet<Vec<u8>>>,
) -> Result<()> {
Ok(()) }
fn as_any(&self) -> &dyn std::any::Any;
}