pub struct Client { /* private fields */ }Expand description
Main Commy client for interacting with a Commy server
Implementations§
Source§impl Client
impl Client
Sourcepub async fn initialize(
server_url: impl Into<String>,
tenant_id: impl Into<String>,
credentials: AuthCredentials,
) -> Result<Self>
pub async fn initialize( server_url: impl Into<String>, tenant_id: impl Into<String>, credentials: AuthCredentials, ) -> Result<Self>
Initialize a fully-configured client in one call
This is the primary entry point. It:
- Creates a new client
- Connects to the server
- Authenticates to the tenant
- Initializes the file watcher
- Starts file monitoring
After this, the client is ready to use with get_virtual_service_file().
Sourcepub fn new(server_url: impl Into<String>) -> Self
pub fn new(server_url: impl Into<String>) -> Self
Create a new client (public - for testing/special cases)
Sourcepub fn with_id(
server_url: impl Into<String>,
client_id: impl Into<String>,
) -> Self
pub fn with_id( server_url: impl Into<String>, client_id: impl Into<String>, ) -> Self
Create a new client with custom ID
Sourcepub fn server_url(&self) -> &str
pub fn server_url(&self) -> &str
Get server URL
Sourcepub async fn connect(&self) -> Result<()>
pub async fn connect(&self) -> Result<()>
Connect to server (public - for testing/special cases)
Sourcepub async fn authenticate(
&self,
tenant_id: impl Into<String>,
credentials: AuthCredentials,
) -> Result<AuthContext>
pub async fn authenticate( &self, tenant_id: impl Into<String>, credentials: AuthCredentials, ) -> Result<AuthContext>
Authenticate to a tenant (public - for testing/special cases)
Sourcepub async fn create_service(
&self,
tenant_id: &str,
service_name: &str,
) -> Result<String>
pub async fn create_service( &self, tenant_id: &str, service_name: &str, ) -> Result<String>
Create a new service in a tenant
Returns the service ID on success. Returns error if:
- Not authenticated to the tenant
- Service already exists
- Insufficient permissions (need create_service permission)
Sourcepub async fn get_service(
&self,
tenant_id: &str,
service_name: &str,
) -> Result<Service>
pub async fn get_service( &self, tenant_id: &str, service_name: &str, ) -> Result<Service>
Get an existing service from a tenant (read-only, no side effects)
Returns error if:
- Not authenticated to the tenant
- Service does not exist (NotFound error)
- Insufficient permissions (need read_service permission)
Sourcepub async fn delete_service(
&self,
tenant_id: &str,
service_name: &str,
) -> Result<()>
pub async fn delete_service( &self, tenant_id: &str, service_name: &str, ) -> Result<()>
Delete a service from a tenant
Returns error if:
- Not authenticated to the tenant
- Service does not exist
- Insufficient permissions (need delete_service permission, typically admin)
Sourcepub async fn create_tenant(
&self,
tenant_id: &str,
tenant_name: &str,
) -> Result<String>
pub async fn create_tenant( &self, tenant_id: &str, tenant_name: &str, ) -> Result<String>
Create a new tenant (admin operation)
Requires admin credentials or special permissions to create tenants. Returns the tenant ID on success.
Returns error if:
- Not connected to server
- Tenant already exists
- Insufficient permissions (need admin role)
Sourcepub async fn delete_tenant(&self, tenant_id: &str) -> Result<()>
pub async fn delete_tenant(&self, tenant_id: &str) -> Result<()>
Delete a tenant (admin operation)
Removes all services and data associated with the tenant. Requires admin credentials or special permissions.
Returns error if:
- Not connected to server
- Tenant does not exist
- Insufficient permissions (need admin role)
- Tenant has active clients
Sourcepub async fn read_variable(
&self,
service_id: &str,
variable_name: &str,
) -> Result<Vec<u8>>
pub async fn read_variable( &self, service_id: &str, variable_name: &str, ) -> Result<Vec<u8>>
Read a variable value
Sourcepub async fn write_variable(
&self,
service_id: &str,
variable_name: &str,
data: Vec<u8>,
) -> Result<()>
pub async fn write_variable( &self, service_id: &str, variable_name: &str, data: Vec<u8>, ) -> Result<()>
Write a variable value
Sourcepub async fn subscribe(
&self,
service_id: &str,
variable_name: &str,
) -> Result<()>
pub async fn subscribe( &self, service_id: &str, variable_name: &str, ) -> Result<()>
Subscribe to variable changes
Sourcepub async fn unsubscribe(
&self,
service_id: &str,
variable_name: &str,
) -> Result<()>
pub async fn unsubscribe( &self, service_id: &str, variable_name: &str, ) -> Result<()>
Unsubscribe from variable changes
Sourcepub async fn disconnect(&self) -> Result<()>
pub async fn disconnect(&self) -> Result<()>
Disconnect from server
Sourcepub async fn is_connected(&self) -> bool
pub async fn is_connected(&self) -> bool
Check if connected
Sourcepub async fn connection_state(&self) -> ConnectionState
pub async fn connection_state(&self) -> ConnectionState
Get current connection state
Sourcepub async fn authenticated_tenants(&self) -> Vec<String>
pub async fn authenticated_tenants(&self) -> Vec<String>
Get authenticated tenants
Sourcepub async fn is_authenticated_to(&self, tenant_id: &str) -> bool
pub async fn is_authenticated_to(&self, tenant_id: &str) -> bool
Check if authenticated to tenant
Sourcepub async fn idle_seconds(&self) -> u64
pub async fn idle_seconds(&self) -> u64
Get idle time in seconds
Sourcepub async fn init_file_watcher(&self) -> Result<()>
pub async fn init_file_watcher(&self) -> Result<()>
Initialize file watcher for hybrid mode (public - for testing/special cases)
Sourcepub async fn get_virtual_service_file(
&self,
tenant_id: &str,
service_name: &str,
) -> Result<Arc<VirtualVariableFile>>
pub async fn get_virtual_service_file( &self, tenant_id: &str, service_name: &str, ) -> Result<Arc<VirtualVariableFile>>
Get or create a virtual variable file for a service
This creates a virtual representation that works seamlessly for both:
- Local clients: Memory-mapped to actual service file
- Remote clients: In-memory buffer synced via WSS
Sourcepub async fn start_file_monitoring(&self) -> Result<()>
pub async fn start_file_monitoring(&self) -> Result<()>
Start monitoring virtual files for changes (public - for testing/special cases)
This spawns a background task that watches for file changes and automatically detects which variables have changed using SIMD
Sourcepub async fn wait_for_file_change(&self) -> Result<Option<FileChangeEvent>>
pub async fn wait_for_file_change(&self) -> Result<Option<FileChangeEvent>>
Get next file change event (blocks until a file changes)
Sourcepub async fn try_get_file_change(&self) -> Result<Option<FileChangeEvent>>
pub async fn try_get_file_change(&self) -> Result<Option<FileChangeEvent>>
Try to get next file change event (non-blocking)
Sourcepub async fn stop_file_monitoring(&self) -> Result<()>
pub async fn stop_file_monitoring(&self) -> Result<()>
Stop file monitoring