OmnyStoreNode constructor
OmnyStoreNode({
- required Uri hubUri,
- required String nodeId,
- required OmnyStore store,
- Set<
String> organizations = const {}, - String? publicBaseUrl,
- Map<
String, String> labels = const {}, - int priority = 0,
- int? capacityBytes,
- Logger logger = const NoopLogger(),
- String? authToken,
- Duration heartbeatInterval = const Duration(seconds: 10),
- Duration sessionTimeout = const Duration(minutes: 10),
- ReconnectPolicy? reconnect,
- NodeRuntime? runtime,
- StoreRpcServer? rpc,
Creates a node.
authToken is sent as a bearer token on the WebSocket upgrade, so a hub
with an authenticator admits only nodes it knows.
Implementation
OmnyStoreNode({
required Uri hubUri,
required this.nodeId,
required this.store,
Set<String> organizations = const {},
this.publicBaseUrl,
Map<String, String> labels = const {},
this.priority = 0,
this.capacityBytes,
this.logger = const NoopLogger(),
String? authToken,
Duration heartbeatInterval = const Duration(seconds: 10),
Duration sessionTimeout = const Duration(minutes: 10),
ReconnectPolicy? reconnect,
NodeRuntime? runtime,
StoreRpcServer? rpc,
}) : organizations = Set.unmodifiable(organizations),
labels = Map.unmodifiable(labels) {
this.rpc =
rpc ??
StoreRpcServer(
store: store,
sessionTimeout: sessionTimeout,
describeProvider: describe,
);
this.runtime =
runtime ??
NodeRuntime(
NodeConfig(
hubUri: hubUri,
nodeId: NodeId(nodeId),
// Advertised so a hub whose OmnyHub instance also hosts other kinds
// of node can tell storage providers apart from the rest.
capabilities: {StoreProtocol.capability},
labels: this.labels,
agentVersion: omnyStoreVersion,
heartbeatInterval: heartbeatInterval,
reconnect: reconnect,
headers: {
if (authToken != null) 'authorization': 'Bearer $authToken',
},
// The hub calls these actions; the RPC server answers them against
// this node's own store.
onRequest: (action, payload) => this.rpc.handle(action, payload),
registerPayload: () async => {
StoreProtocol.versionKey: StoreProtocol.version,
StoreProtocol.descriptorKey: (await describe()).toJson(),
},
onRegistered: _onRegistered,
// Capacity and usage ride along on the heartbeat, so placement
// decisions use fresh numbers without the hub polling every node.
heartbeatPayload: () async => {
StoreProtocol.descriptorKey: (await describe()).toJson(),
},
),
logger: logger,
);
}