Table of Contents

Interface IWebSocketConnectionStore

Namespace
Virtufin.WebSocketManager.Services
Assembly
Virtufin.WebSocketManager.dll

Interface for WebSocket connection storage.

public interface IWebSocketConnectionStore

Methods

ClearAllConnectionsAsync(CancellationToken)

Removes all WebSocket connections.

Task ClearAllConnectionsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task

CreateConnectionAsync(string, string, bool, CancellationToken)

Creates a new WebSocket connection entry under the given, already-minted id -- the caller (WebSocketManagerGrpcService.Connect) mints the id and activates the owning WebSocketConnectionActor for it before this ever runs, so the id always comes from outside now rather than being generated in here.

ValueTask<WebSocketConnection> CreateConnectionAsync(string id, string url, bool autoReconnect, CancellationToken cancellationToken = default)

Parameters

id string
url string
autoReconnect bool
cancellationToken CancellationToken

Returns

ValueTask<WebSocketConnection>

GetAllConnectionsAsync(CancellationToken)

Gets all WebSocket connections.

Task<IEnumerable<WebSocketConnection>> GetAllConnectionsAsync(CancellationToken cancellationToken = default)

Parameters

cancellationToken CancellationToken

Returns

Task<IEnumerable<WebSocketConnection>>

GetConnectionAsync(string, CancellationToken)

Gets a WebSocket connection by its ID.

Task<WebSocketConnection?> GetConnectionAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string
cancellationToken CancellationToken

Returns

Task<WebSocketConnection>

GetConnectionById(string)

Synchronous lookup of a local connection by ID (in-memory only). Returns null for connections owned by other instances.

WebSocketConnection? GetConnectionById(string id)

Parameters

id string

Returns

WebSocketConnection

GetLocalConnections()

Snapshot of connections owned by this instance (in-memory only). Used by ConnectionHeartbeatService to refresh state-store TTLs without depending on send/publish traffic.

IReadOnlyCollection<WebSocketConnection> GetLocalConnections()

Returns

IReadOnlyCollection<WebSocketConnection>

RemoveConnectionAsync(string, CancellationToken)

Removes a WebSocket connection by its ID.

Task RemoveConnectionAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string
cancellationToken CancellationToken

Returns

Task

TouchAsync(string, CancellationToken)

Refreshes the state-store TTL on the connection record without changing its payload. Called after a successful Send to keep an idle but live socket from being garbage-collected.

Task TouchAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string
cancellationToken CancellationToken

Returns

Task

TryLoadPersistedAsync(string, CancellationToken)

If id isn't already local, checks the persisted directory and, if found, materializes it into this instance's local view. Used only by WebSocketConnectionActor.OnActivateAsync to self-heal after Dapr activates this connection's actor on an instance that never opened its socket -- a genuine failover/rebalance of an already-connected id, not a fresh CreateConnectionAsync(string, string, bool, CancellationToken) (which registers the connection locally itself, so this is always a no-op during a normal Connect). Returns null if already local, or if there's truly no persisted record either.

Task<WebSocketConnection?> TryLoadPersistedAsync(string id, CancellationToken cancellationToken = default)

Parameters

id string
cancellationToken CancellationToken

Returns

Task<WebSocketConnection>

UpdateConnectionAsync(WebSocketConnection, CancellationToken)

Updates an existing WebSocket connection.

Task UpdateConnectionAsync(WebSocketConnection connection, CancellationToken cancellationToken = default)

Parameters

connection WebSocketConnection
cancellationToken CancellationToken

Returns

Task