Skip to main content

Connector

Struct Connector 

Source
pub struct Connector {
    pub config: ConnectorConfig,
    /* private fields */
}
Expand description

A connector that can fetch entities from a remote Haystack server.

Fields§

§config: ConnectorConfig

Implementations§

Source§

impl Connector

Source

pub fn new(config: ConnectorConfig) -> Self

Create a new connector with an empty cache.

Source

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).

Source

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.

Source

pub fn owns(&self, id: &str) -> bool

Returns true if this connector owns an entity with the given ID.

Source

pub fn cached_entities(&self) -> Vec<HDict>

Returns a clone of all cached entities.

Source

pub fn entity_count(&self) -> usize

Returns the number of cached entities.

Source

pub fn add_remote_watch(&self, prefixed_id: &str)

Add a federated entity ID to the remote watch set.

Source

pub fn remove_remote_watch(&self, prefixed_id: &str)

Remove a federated entity ID from the remote watch set.

Source

pub fn remote_watch_count(&self) -> usize

Returns the number of entity IDs being watched remotely.

Source

pub fn transport_mode(&self) -> TransportMode

Returns the current transport mode.

Source

pub fn is_connected(&self) -> bool

Returns whether the connector is currently connected (last sync succeeded).

Source

pub fn last_sync_time(&self) -> Option<DateTime<Utc>>

Returns the timestamp of the last successful sync, if any.

Source

pub async fn proxy_his_read( &self, prefixed_id: &str, range: &str, ) -> Result<HGrid, String>

Proxy a hisRead request to the remote server.

Source

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.

Source

pub async fn proxy_his_write( &self, prefixed_id: &str, items: Vec<HDict>, ) -> Result<HGrid, String>

Proxy a hisWrite request to the remote server.

Source

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.

Source

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.

Source

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.

Auto Trait Implementations§

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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