Module Client

Module Client 

Source
Expand description

§Vine Client

Provides a simplified, thread-safe client for communicating with a Cocoon sidecar process via gRPC. It manages a shared pool of connections with robust error handling, automatic reconnection, health checks, and timeout management.

§Features

  • Connection Pool: Thread-safe HashMap of client connections by identifier
  • Health Checks: Validates connection status before RPC calls
  • Automatic Reconnection: Retries failed connections with exponential backoff
  • Request Timeout: Configurable timeout per RPC call
  • Retry Logic: Configurable retry attempts for transient failures
  • Message Validation: Size limits and format checking for all messages
  • Graceful Degradation: Handles Cocoon unavailability gracefully

§Usage Example

use Vine::Client::{ConnectToSideCar, SendRequest};
use serde_json::json;

// Connect to Cocoon
ConnectToSideCar("cocoon-main".to_string(), "127.0.0.1:50052".to_string()).await?;

// Send request
let result = SendRequest(
	"cocoon-main",
	"GetExtensions".to_string(),
	json!({}),
	5000, // 5 second timeout
)
.await?;

§Error Handling

All operations return Result<T, VineError> with comprehensive error types:

  • ClientNotConnected: Sidecar not in connection pool
  • RequestTimeout: RPC call exceeded timeout
  • RPCError: gRPC transport or status error
  • SerializationError: JSON parsing/serialization failure

Modules§

Config 🔒
Configuration constants for Vine client behavior

Structs§

CONNECTION_METADATA 🔒
Thread-safe metadata for connection health tracking
ConnectionMetadata 🔒
Connection metadata tracking health and last activity
SIDECAR_CLIENTS 🔒
Thread-safe pool of Cocoon client connections indexed by identifier

Functions§

CheckSideCarHealth
Checks the health status of a connected sidecar.
ConnectToSideCar
Establishes a gRPC connection to a sidecar process with retry logic.
DisconnectFromSideCar
Disconnects from a sidecar process and removes it from the connection pool.
RecordSideCarFailure 🔒
Records a failure for a sidecar connection.
SendNotification
Sends a notification to a sidecar without waiting for a response.
SendRequest
Sends a request to a sidecar and waits for a response.
UpdateSideCarActivity 🔒
Updates the last activity timestamp for a sidecar.
ValidateMessageSize 🔒
Validates message size against maximum allowed.
try_connect_single 🔒
Single connection attempt without retry logic

Type Aliases§

CocoonClient 🔒
Type alias for the Cocoon gRPC client with Channel transport