pub struct Connector {
pub config: ConnectorConfig,
/* private fields */
}Expand description
A connector that can fetch entities from a remote Haystack server.
Fields§
§config: ConnectorConfigImplementations§
Source§impl Connector
impl Connector
Sourcepub fn new(config: ConnectorConfig) -> Self
pub fn new(config: ConnectorConfig) -> Self
Create a new connector with an empty cache.
Sourcepub async fn sync(&self) -> Result<usize, String>
pub async fn sync(&self) -> Result<usize, String>
Connect to the remote server, fetch all entities, apply id prefixing, and store them in the cache. Returns the count of entities synced.
Uses the persistent client if available, otherwise establishes a new connection (WS-first, falling back to HTTP).
Sourcepub fn update_cache(&self, entities: Vec<HDict>)
pub fn update_cache(&self, entities: Vec<HDict>)
Replace the cached entities and rebuild the owned-ID index.
Extracts all id Ref values from the given entities into a HashSet,
then atomically replaces both the entity cache and the ownership set.
Sourcepub fn owns(&self, id: &str) -> bool
pub fn owns(&self, id: &str) -> bool
Returns true if this connector owns an entity with the given ID.
Sourcepub fn cached_entities(&self) -> Vec<HDict>
pub fn cached_entities(&self) -> Vec<HDict>
Returns a clone of all cached entities.
Sourcepub fn entity_count(&self) -> usize
pub fn entity_count(&self) -> usize
Returns the number of cached entities.
Sourcepub fn add_remote_watch(&self, prefixed_id: &str)
pub fn add_remote_watch(&self, prefixed_id: &str)
Add a federated entity ID to the remote watch set.
Sourcepub fn remove_remote_watch(&self, prefixed_id: &str)
pub fn remove_remote_watch(&self, prefixed_id: &str)
Remove a federated entity ID from the remote watch set.
Sourcepub fn remote_watch_count(&self) -> usize
pub fn remote_watch_count(&self) -> usize
Returns the number of entity IDs being watched remotely.
Sourcepub fn transport_mode(&self) -> TransportMode
pub fn transport_mode(&self) -> TransportMode
Returns the current transport mode.
Sourcepub fn is_connected(&self) -> bool
pub fn is_connected(&self) -> bool
Returns whether the connector is currently connected (last sync succeeded).
Sourcepub fn last_sync_time(&self) -> Option<DateTime<Utc>>
pub fn last_sync_time(&self) -> Option<DateTime<Utc>>
Returns the timestamp of the last successful sync, if any.
Sourcepub async fn proxy_his_read(
&self,
prefixed_id: &str,
range: &str,
) -> Result<HGrid, String>
pub async fn proxy_his_read( &self, prefixed_id: &str, range: &str, ) -> Result<HGrid, String>
Proxy a hisRead request to the remote server.
Sourcepub async fn proxy_point_write(
&self,
prefixed_id: &str,
level: u8,
val: &Kind,
) -> Result<HGrid, String>
pub async fn proxy_point_write( &self, prefixed_id: &str, level: u8, val: &Kind, ) -> Result<HGrid, String>
Proxy a pointWrite request to the remote server.
Sourcepub async fn proxy_his_write(
&self,
prefixed_id: &str,
items: Vec<HDict>,
) -> Result<HGrid, String>
pub async fn proxy_his_write( &self, prefixed_id: &str, items: Vec<HDict>, ) -> Result<HGrid, String>
Proxy a hisWrite request to the remote server.
Sourcepub async fn proxy_import(&self, entity: &HDict) -> Result<HGrid, String>
pub async fn proxy_import(&self, entity: &HDict) -> Result<HGrid, String>
Proxy an import request for a single entity to the remote server.
Strips the id prefix from the entity, wraps it in a single-row grid,
and calls the remote import op.
Sourcepub async fn proxy_invoke_action(
&self,
prefixed_id: &str,
action: &str,
args: HDict,
) -> Result<HGrid, String>
pub async fn proxy_invoke_action( &self, prefixed_id: &str, action: &str, args: HDict, ) -> Result<HGrid, String>
Proxy an invokeAction request to the remote server.
Sourcepub fn spawn_sync_task(connector: Arc<Connector>) -> JoinHandle<()>
pub fn spawn_sync_task(connector: Arc<Connector>) -> JoinHandle<()>
Spawn a background sync task for this connector.
The task loops forever, syncing entities at the configured interval. On error, the persistent client is cleared to force reconnection on the next iteration.