ConnectionManager class
Manages MCP server connections: create, reuse, disconnect, reconnect, and notify listeners on state changes (MOD-CONN-001, FR-CONN-001~010).
- Inheritance
-
- Object
- ChangeNotifier
- ConnectionManager
Constructors
- ConnectionManager({Logger? logger, TransportFactory? transportFactory, ClientConnector? connector, Duration? waitCheckInterval, Duration? waitMaxDuration})
Properties
-
connections
→ Map<
String, ConnectionInfo> -
no setter
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- onClientAttached ↔ void Function(String serverId, Client client)?
-
Called after a server's
Clientis replaced by a NEW one — the first connect and every reconnect alike.getter/setter pair - runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tokenReGrant ↔ ServerReGrant?
-
Optional durable-reconnect hook (see ServerReGrant). Mutable so the host
can wire it after the marketplace session exists (the core / manager is
built at composition time, before the marketplace capabilities). Null =
no re-grant; connect/reconnect stay byte-for-byte as before.
getter/setter pair
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
connect(
ServerConfig server) → Future< ConnectionResult> - FR-CONN-001~003, 010
-
disconnect(
String serverId) → Future< void> -
FR-CONN-004 — close
serverIdnow, whoever holds it. For taking a device away (card removed, lending withdrawn — 23 §6); letting go is release. -
disconnectAll(
) → Future< void> - FR-CONN-005
-
dispose(
) → void -
Discards any resources used by the object.
inherited
-
getConnection(
String serverId) → ConnectionInfo? -
hasConnection(
String serverId) → bool -
isHeld(
String serverId) → bool -
Whether anyone holds
serverId. A short-lived use (a metadata read, an open that gave up) closes the connection only when nobody does. -
keepAliveSweep(
{Duration timeout = const Duration(seconds: 4), Duration dropAfterSilence = _silenceToDrop}) → Future< void> -
Active keepalive + liveness for transient stream transports (ble:// /
tcp:// / serial:// carried on a streamableHttp config). Sends a cheap
pinground-trip on every such CONNECTED link (any reply counts, see the probe below): -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
reconnect(
String serverId) → Future< ConnectionResult> - FR-CONN-006
-
release(
String serverId, String holder) → Future< void> -
holderis done withserverId. The connection closes only when the last holder lets go. -
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
retain(
String serverId, String holder) → void -
holderuses the connection ofserverId. Idempotent per holder. -
suspend(
String serverId) → Future< void> -
Close
serverIdfor a while — the host is paused — keeping who holds it. Resuming dials again for the same holders. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited