Skip to main content

Connector

Struct Connector 

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

Fields§

§config: ConnectorConfig

Implementations§

Source§

impl Connector

Source

pub fn new(config: ConnectorConfig) -> Self

Create a new connector with an empty cache.

The connector starts disconnected; a persistent connection is established lazily on the first sync call.

Source

pub async fn sync(&self) -> Result<usize, String>

Connect to the remote server, fetch entities, and update cache.

Tries incremental delta sync first (via the changes op) if we have a known remote version. Falls back to full sync on first connect, when the remote doesn’t support changes, or when the version gap is too large.

Returns the number of cached entities after sync, or an error string.

Source

pub fn update_cache(&self, entities: Vec<HDict>)

Replace the cached entities and rebuild the owned-ID index and bitmap tag index.

Extracts all id Ref values from the given entities into a HashSet, builds a bitmap tag index for fast filtered reads, then atomically replaces the cache, ownership set, and index.

Source

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

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

Source

pub fn get_cached_entity(&self, id: &str) -> Option<Arc<HDict>>

Look up a single cached entity by ID using the O(1) id_map index.

Source

pub fn batch_get_cached(&self, ids: &[&str]) -> (Vec<Arc<HDict>>, Vec<String>)

Look up multiple cached entities by ID in a single pass. Returns found entities and missing IDs.

Source

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

Returns Arc-wrapped references to all cached entities (cheap pointer copies).

Source

pub fn entity_count(&self) -> usize

Returns the number of cached entities.

Source

pub fn filter_cached( &self, filter_expr: &str, limit: usize, ) -> Result<Vec<HDict>, String>

Filter cached entities using the bitmap tag index for acceleration.

Returns matching entities up to limit (0 = unlimited). Uses the same two-phase approach as EntityGraph: bitmap candidates → full filter eval.

Source

pub fn filter_cached_with_ast( &self, ast: &FilterNode, limit: usize, ) -> Vec<Arc<HDict>>

Filter cached entities using a pre-parsed filter AST.

Avoids redundant parsing when the same filter is applied across multiple connectors (e.g. federated reads). Returns Arc-wrapped references for cheap cloning in federation pipelines.

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 fn cache_version(&self) -> u64

Returns the current cache version counter.

Source

pub fn state(&self) -> ConnectorState

Returns an observable snapshot of this connector’s state.

Source

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

Proxy a hisRead request to the remote server.

Strips the ID prefix, calls hisRead on the remote, and returns the response grid. Clears the client on connection error.

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.

Strips the ID prefix, calls pointWrite on the remote with the given level and value. Clears the client on connection error.

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.

Strips the ID prefix, calls hisWrite on the remote with the given time-series rows. Clears the client on connection error.

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.

Strips the ID prefix, calls invokeAction on the remote with the given action name and arguments dict. Clears the client on connection error.

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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