@zlink-systems/framework 0.29.1 → 0.30.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +150 -68
- package/dist/.tsbuildinfo +1 -1
- package/dist/contracts/Actors/ZLinkActorClient.d.ts +2 -1
- package/dist/contracts/Channels/Calls.d.ts +2 -1
- package/dist/contracts/Common/ZLinkMessageMetadata.js +11 -5
- package/dist/contracts/Configuration/Builders.d.ts +1 -2
- package/dist/contracts/Configuration/Configs.d.ts +0 -5
- package/dist/contracts/Configuration/RegistrationBuilders.js +6 -4
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +1 -6
- package/dist/contracts/Configuration/RegistrationValidators.js +4 -4
- package/dist/contracts/Configuration/index.d.ts +1 -1
- package/dist/contracts/Handlers/Attributes.d.ts +5 -13
- package/dist/contracts/Handlers/Attributes.js +7 -11
- package/dist/contracts/Handlers/JsonContract.d.ts +2 -46
- package/dist/contracts/Handlers/JsonContract.js +4 -153
- package/dist/contracts/Spots/Contracts.d.ts +2 -1
- package/dist/internal.d.ts +1 -0
- package/dist/internal.js +3 -1
- package/dist/nest-integration.d.ts +1 -1
- package/dist/nest-integration.js +2 -1
- package/dist/runtime/actors/actor-client.d.ts +1 -1
- package/dist/runtime/actors/actor-client.js +14 -12
- package/dist/runtime/actors/actor-handoff.d.ts +3 -2
- package/dist/runtime/actors/actor-handoff.js +15 -7
- package/dist/runtime/actors/actor-join-relocation.d.ts +1 -0
- package/dist/runtime/actors/actor-local-native-join.js +9 -12
- package/dist/runtime/actors/actor-remote-wire.js +15 -0
- package/dist/runtime/actors/actor-routed-join-transport.d.ts +6 -2
- package/dist/runtime/actors/actor-routed-json-request.d.ts +2 -0
- package/dist/runtime/actors/index.d.ts +2 -1
- package/dist/runtime/actors/index.js +18 -6
- package/dist/runtime/actors/spot-actor-dispatch.js +2 -2
- package/dist/runtime/admission.d.ts +1 -1
- package/dist/runtime/admission.js +15 -5
- package/dist/runtime/application-jobs/application-ingress-record-owner.d.ts +9 -9
- package/dist/runtime/application-jobs/application-ingress-record-owner.js +45 -23
- package/dist/runtime/application-jobs/application-job-queue-scope.d.ts +5 -2
- package/dist/runtime/application-jobs/application-job-queue-scope.js +41 -21
- package/dist/runtime/application-jobs/contracts.d.ts +15 -2
- package/dist/runtime/backend/contracts/index.d.ts +27 -27
- package/dist/runtime/backend/mesh-completion-table.d.ts +15 -5
- package/dist/runtime/backend/mesh-completion-table.js +160 -50
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +3 -0
- package/dist/runtime/backend/mesh-dispatch-pump.js +53 -36
- package/dist/runtime/backend/node/node-backend-adapter-factory.js +6 -1
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +3 -3
- package/dist/runtime/backend/node/node-backend-adapter-support.js +33 -31
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.d.ts +1 -1
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +5 -2
- package/dist/runtime/backend/node/node-mesh-backend-adapter.d.ts +1 -9
- package/dist/runtime/backend/node/node-mesh-backend-adapter.js +1 -1
- package/dist/runtime/backend/node/node-raw-binding-port.js +50 -25
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +22 -16
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +133 -149
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +15 -10
- package/dist/runtime/backend/raw-binding-port.d.ts +10 -3
- package/dist/runtime/backend/runtime-message.d.ts +1 -0
- package/dist/runtime/backend/runtime-message.js +5 -0
- package/dist/runtime/backend/runtime-values.d.ts +1 -0
- package/dist/runtime/backend/runtime-values.js +2 -1
- package/dist/runtime/channels/channel-clients.d.ts +1 -0
- package/dist/runtime/channels/channel-clients.js +58 -21
- package/dist/runtime/channels/channel-dispatch-pipeline.d.ts +3 -2
- package/dist/runtime/channels/channel-dispatch-pipeline.js +20 -11
- package/dist/runtime/channels/channel-dispatch-services.d.ts +1 -0
- package/dist/runtime/channels/channel-dispatch-services.js +45 -0
- package/dist/runtime/channels/channel-dispatchers.d.ts +1 -1
- package/dist/runtime/channels/channel-dispatchers.js +27 -26
- package/dist/runtime/channels/channel-envelope-inspection.d.ts +1 -2
- package/dist/runtime/channels/channel-envelope-inspection.js +1 -16
- package/dist/runtime/channels/channel-envelope.d.ts +1 -0
- package/dist/runtime/channels/channel-envelope.js +83 -8
- package/dist/runtime/channels/channel-outbound-operations.d.ts +2 -2
- package/dist/runtime/channels/channel-outbound-operations.js +8 -8
- package/dist/runtime/channels/channel-receive-loops.js +3 -3
- package/dist/runtime/channels/channel-runtime-lifecycle.js +2 -1
- package/dist/runtime/channels/channel-runtime-manager.d.ts +6 -6
- package/dist/runtime/channels/channel-runtime-manager.js +12 -12
- package/dist/runtime/channels/channel-socket-registry.d.ts +10 -3
- package/dist/runtime/channels/channel-socket-registry.js +59 -82
- package/dist/runtime/channels/channel-transports.d.ts +18 -15
- package/dist/runtime/channels/channel-transports.js +48 -31
- package/dist/runtime/channels/local-spot-route-transport.d.ts +1 -1
- package/dist/runtime/channels/local-spot-route-transport.js +2 -1
- package/dist/runtime/channels/router-socket-spot-route-transport.d.ts +2 -2
- package/dist/runtime/channels/router-socket-spot-route-transport.js +4 -4
- package/dist/runtime/channels/source-spot-router.d.ts +2 -2
- package/dist/runtime/channels/source-spot-router.js +4 -4
- package/dist/runtime/channels/spot-node-route-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-node-route-transport.js +4 -4
- package/dist/runtime/channels/spot-route-bridge-transport.d.ts +2 -2
- package/dist/runtime/channels/spot-route-bridge-transport.js +4 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.d.ts +5 -4
- package/dist/runtime/channels/spot-route-dispatch-strategy.js +18 -18
- package/dist/runtime/diagnostics/message-flow.d.ts +1 -0
- package/dist/runtime/diagnostics/message-flow.js +3 -3
- package/dist/runtime/execution/serial-execution-queue.d.ts +1 -0
- package/dist/runtime/execution/serial-execution-queue.js +1 -0
- package/dist/runtime/foundation/actor-join-recovery-codec.js +2 -2
- package/dist/runtime/foundation/durable-service-request.d.ts +14 -0
- package/dist/runtime/foundation/durable-service-request.js +98 -0
- package/dist/runtime/foundation/operation-identity.d.ts +1 -0
- package/dist/runtime/foundation/operation-identity.js +5 -1
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +37 -6
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +473 -220
- package/dist/runtime/foundation/service-liveness-registry.d.ts +20 -8
- package/dist/runtime/foundation/service-liveness-registry.js +57 -44
- package/dist/runtime/foundation/service-mailbox.d.ts +3 -0
- package/dist/runtime/foundation/service-mailbox.js +2 -1
- package/dist/runtime/foundation/service-relocation-object-owner.d.ts +1 -0
- package/dist/runtime/foundation/service-relocation-object-owner.js +1 -0
- package/dist/runtime/foundation/service-relocation-runtime.d.ts +2 -0
- package/dist/runtime/foundation/service-relocation-runtime.js +13 -1
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -0
- package/dist/runtime/foundation/service-stateful-runtime.d.ts +10 -9
- package/dist/runtime/foundation/service-stateful-runtime.js +78 -126
- package/dist/runtime/foundation/service-stateful-wire-codec.d.ts +5 -7
- package/dist/runtime/foundation/service-stateful-wire-codec.js +43 -61
- package/dist/runtime/foundation/service-topology-registry.d.ts +16 -4
- package/dist/runtime/foundation/service-topology-registry.js +69 -30
- package/dist/runtime/foundation/service-wire-m6a-codec.d.ts +3 -3
- package/dist/runtime/foundation/service-wire-m6a-codec.js +36 -38
- package/dist/runtime/handlers/handler-instance-scope.d.ts +8 -0
- package/dist/runtime/handlers/handler-instance-scope.js +54 -11
- package/dist/runtime/host/actor-packet-relay.js +7 -7
- package/dist/runtime/host/actor-runtime-options-factory.js +2 -2
- package/dist/runtime/host/application-job-queue.d.ts +28 -9
- package/dist/runtime/host/application-job-queue.js +214 -50
- package/dist/runtime/host/entry-actor-runtime.d.ts +1 -0
- package/dist/runtime/host/entry-actor-runtime.js +4 -1
- package/dist/runtime/host/index.d.ts +7 -1
- package/dist/runtime/host/index.js +154 -126
- package/dist/runtime/host/instance-activation-authority.d.ts +2 -1
- package/dist/runtime/host/instance-activation-authority.js +89 -25
- package/dist/runtime/host/remote-bound-session-relay.js +2 -18
- package/dist/runtime/host/route-mesh-runtime.js +1 -1
- package/dist/runtime/host/service-relocation-control.d.ts +1 -0
- package/dist/runtime/host/service-relocation-control.js +10 -4
- package/dist/runtime/host/service-relocation-host-runtime.d.ts +6 -8
- package/dist/runtime/host/service-relocation-host-runtime.js +215 -243
- package/dist/runtime/host/spot-address-transport.d.ts +1 -0
- package/dist/runtime/host/spot-address-transport.js +28 -14
- package/dist/runtime/host/spot-runtime-options-factory.js +3 -2
- package/dist/runtime/host/user-spot-creation-coordinator.d.ts +1 -0
- package/dist/runtime/host/user-spot-creation-coordinator.js +1 -0
- package/dist/runtime/locations/actor-location-claims.d.ts +2 -2
- package/dist/runtime/locations/actor-location-claims.js +34 -19
- package/dist/runtime/locations/domain-store-contract.d.ts +2 -2
- package/dist/runtime/locations/in-memory-authority-store.d.ts +4 -2
- package/dist/runtime/locations/in-memory-authority-store.js +80 -8
- package/dist/runtime/locations/in-memory-location-store.d.ts +2 -2
- package/dist/runtime/locations/in-memory-location-store.js +19 -3
- package/dist/runtime/locations/internal-location-contracts.d.ts +3 -0
- package/dist/runtime/locations/lifecycle.d.ts +1 -2
- package/dist/runtime/locations/lifecycle.js +2 -5
- package/dist/runtime/locations/location-store-repository.d.ts +3 -2
- package/dist/runtime/locations/location-store-repository.js +165 -22
- package/dist/runtime/locations/resolvers.d.ts +2 -1
- package/dist/runtime/locations/resolvers.js +10 -1
- package/dist/runtime/locations/runtime.d.ts +1 -1
- package/dist/runtime/locations/runtime.js +24 -23
- package/dist/runtime/messaging/framework-json-v1.d.ts +4 -6
- package/dist/runtime/messaging/framework-json-v1.js +38 -294
- package/dist/runtime/messaging/packet-name.d.ts +1 -1
- package/dist/runtime/messaging/packet-name.js +8 -24
- package/dist/runtime/messaging/request-result.d.ts +2 -0
- package/dist/runtime/messaging/request-result.js +54 -0
- package/dist/runtime/messaging/submission-result.d.ts +2 -1
- package/dist/runtime/messaging/submission-result.js +7 -4
- package/dist/runtime/protocol/service_wire_codec.generated.d.ts +15 -0
- package/dist/runtime/protocol/service_wire_codec.generated.js +144 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.d.ts +9 -0
- package/dist/runtime/protocol/service_wire_pilot_codec.generated.js +14 -1
- package/dist/runtime/spots/formal-remote-actor-admission-registry.d.ts +9 -2
- package/dist/runtime/spots/formal-remote-actor-admission-registry.js +33 -19
- package/dist/runtime/spots/index.d.ts +7 -3
- package/dist/runtime/spots/index.js +23 -16
- package/dist/runtime/spots/spot-activation.d.ts +3 -1
- package/dist/runtime/spots/spot-activation.js +21 -12
- package/dist/runtime/spots/spot-actor-admission-coordinator.d.ts +2 -1
- package/dist/runtime/spots/spot-actor-admission-coordinator.js +11 -10
- package/dist/runtime/spots/spot-actor-packet-dispatch.d.ts +4 -1
- package/dist/runtime/spots/spot-actor-packet-dispatch.js +7 -5
- package/dist/runtime/spots/spot-actor-packet-drain.js +2 -0
- package/dist/runtime/spots/spot-actor-packet-relay-dispatch.js +1 -0
- package/dist/runtime/spots/spot-entry-activation.js +9 -3
- package/dist/runtime/spots/spot-handler-registry.d.ts +3 -1
- package/dist/runtime/spots/spot-handler-registry.js +18 -8
- package/dist/runtime/spots/spot-node-autoconnect.js +4 -3
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +2 -1
- package/dist/runtime/spots/spot-node-runtime-manager.js +4 -11
- package/dist/runtime/spots/spot-outbound.d.ts +3 -0
- package/dist/runtime/spots/spot-outbound.js +24 -15
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.d.ts +1 -0
- package/dist/runtime/spots/spot-routed-spot-packet-dispatch.js +1 -1
- package/dist/runtime/spots/spot-routing-internal.d.ts +6 -0
- package/dist/runtime/spots/spot-runtime-ports.d.ts +3 -1
- package/dist/runtime/spots/spot-subscription-dispatch.js +0 -3
- package/dist/runtime/spots/spot-timer.js +1 -0
- package/dist/runtime/streams/stream-session-runtime.d.ts +1 -1
- package/dist/runtime/streams/stream-session-runtime.js +14 -28
- package/package.json +3 -3
- package/src/contracts/Actors/ZLinkActorClient.ts +2 -1
- package/src/contracts/Channels/Calls.ts +2 -1
- package/src/contracts/Common/ZLinkMessageMetadata.ts +13 -8
- package/src/contracts/Configuration/Builders.ts +1 -2
- package/src/contracts/Configuration/Configs.ts +0 -6
- package/src/contracts/Configuration/RegistrationBuilders.ts +8 -12
- package/src/contracts/Configuration/RegistrationTypes.ts +1 -6
- package/src/contracts/Configuration/RegistrationValidators.ts +9 -10
- package/src/contracts/Configuration/index.ts +1 -6
- package/src/contracts/Handlers/Attributes.ts +14 -21
- package/src/contracts/Handlers/JsonContract.ts +8 -216
- package/src/contracts/Spots/Contracts.ts +2 -1
- package/src/internal.ts +1 -0
- package/src/nest-integration.ts +1 -0
- package/src/runtime/actors/actor-client.ts +40 -16
- package/src/runtime/actors/actor-handoff.ts +22 -8
- package/src/runtime/actors/actor-join-relocation.ts +1 -0
- package/src/runtime/actors/actor-local-native-join.ts +17 -26
- package/src/runtime/actors/actor-remote-wire.ts +17 -0
- package/src/runtime/actors/actor-routed-join-transport.ts +14 -4
- package/src/runtime/actors/actor-routed-json-request.ts +10 -2
- package/src/runtime/actors/index.ts +19 -5
- package/src/runtime/actors/spot-actor-dispatch.ts +4 -2
- package/src/runtime/admission.ts +18 -5
- package/src/runtime/application-jobs/application-ingress-record-owner.ts +53 -27
- package/src/runtime/application-jobs/application-job-queue-scope.ts +56 -22
- package/src/runtime/application-jobs/contracts.ts +28 -2
- package/src/runtime/backend/contracts/index.ts +63 -32
- package/src/runtime/backend/mesh-completion-table.ts +175 -59
- package/src/runtime/backend/mesh-dispatch-pump.ts +59 -32
- package/src/runtime/backend/node/node-backend-adapter-factory.ts +12 -5
- package/src/runtime/backend/node/node-backend-adapter-support.ts +42 -31
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +12 -2
- package/src/runtime/backend/node/node-mesh-backend-adapter.ts +3 -10
- package/src/runtime/backend/node/node-raw-binding-port.ts +73 -37
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +209 -176
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +32 -13
- package/src/runtime/backend/raw-binding-port.ts +18 -3
- package/src/runtime/backend/runtime-message.ts +6 -0
- package/src/runtime/backend/runtime-values.ts +1 -0
- package/src/runtime/channels/channel-clients.ts +90 -41
- package/src/runtime/channels/channel-dispatch-pipeline.ts +69 -34
- package/src/runtime/channels/channel-dispatch-services.ts +69 -1
- package/src/runtime/channels/channel-dispatchers.ts +29 -27
- package/src/runtime/channels/channel-envelope-inspection.ts +2 -16
- package/src/runtime/channels/channel-envelope.ts +133 -8
- package/src/runtime/channels/channel-outbound-operations.ts +22 -8
- package/src/runtime/channels/channel-receive-loops.ts +3 -3
- package/src/runtime/channels/channel-runtime-lifecycle.ts +7 -1
- package/src/runtime/channels/channel-runtime-manager.ts +29 -12
- package/src/runtime/channels/channel-socket-registry.ts +84 -130
- package/src/runtime/channels/channel-transports.ts +128 -60
- package/src/runtime/channels/local-spot-route-transport.ts +3 -1
- package/src/runtime/channels/router-socket-spot-route-transport.ts +13 -4
- package/src/runtime/channels/source-spot-router.ts +8 -4
- package/src/runtime/channels/spot-node-route-transport.ts +8 -4
- package/src/runtime/channels/spot-route-bridge-transport.ts +6 -4
- package/src/runtime/channels/spot-route-dispatch-strategy.ts +47 -18
- package/src/runtime/diagnostics/message-flow.ts +1 -1
- package/src/runtime/execution/serial-execution-queue.ts +2 -0
- package/src/runtime/foundation/actor-join-recovery-codec.ts +2 -2
- package/src/runtime/foundation/durable-service-request.ts +137 -0
- package/src/runtime/foundation/operation-identity.ts +5 -1
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +642 -253
- package/src/runtime/foundation/service-liveness-registry.ts +68 -59
- package/src/runtime/foundation/service-mailbox.ts +7 -1
- package/src/runtime/foundation/service-relocation-object-owner.ts +2 -0
- package/src/runtime/foundation/service-relocation-runtime.ts +18 -1
- package/src/runtime/foundation/service-runtime-contracts.ts +7 -1
- package/src/runtime/foundation/service-stateful-runtime.ts +128 -160
- package/src/runtime/foundation/service-stateful-wire-codec.ts +55 -84
- package/src/runtime/foundation/service-topology-registry.ts +103 -42
- package/src/runtime/foundation/service-wire-m6a-codec.ts +57 -38
- package/src/runtime/handlers/handler-instance-scope.ts +67 -16
- package/src/runtime/host/actor-packet-relay.ts +7 -0
- package/src/runtime/host/actor-runtime-options-factory.ts +14 -2
- package/src/runtime/host/application-job-queue.ts +249 -48
- package/src/runtime/host/entry-actor-runtime.ts +5 -0
- package/src/runtime/host/index.ts +224 -160
- package/src/runtime/host/instance-activation-authority.ts +132 -27
- package/src/runtime/host/remote-bound-session-relay.ts +2 -23
- package/src/runtime/host/route-mesh-runtime.ts +1 -1
- package/src/runtime/host/service-relocation-control.ts +11 -5
- package/src/runtime/host/service-relocation-host-runtime.ts +317 -291
- package/src/runtime/host/spot-address-transport.ts +49 -24
- package/src/runtime/host/spot-runtime-options-factory.ts +4 -0
- package/src/runtime/host/user-spot-creation-coordinator.ts +8 -0
- package/src/runtime/locations/actor-location-claims.ts +52 -30
- package/src/runtime/locations/domain-store-contract.ts +6 -2
- package/src/runtime/locations/in-memory-authority-store.ts +113 -9
- package/src/runtime/locations/in-memory-location-store.ts +25 -3
- package/src/runtime/locations/internal-location-contracts.ts +4 -0
- package/src/runtime/locations/lifecycle.ts +8 -26
- package/src/runtime/locations/location-store-repository.ts +220 -15
- package/src/runtime/locations/resolvers.ts +25 -2
- package/src/runtime/locations/runtime.ts +28 -24
- package/src/runtime/messaging/framework-json-v1.ts +5 -325
- package/src/runtime/messaging/packet-name.ts +5 -25
- package/src/runtime/messaging/request-result.ts +58 -0
- package/src/runtime/messaging/submission-result.ts +7 -3
- package/src/runtime/protocol/service_wire_codec.generated.ts +131 -1
- package/src/runtime/protocol/service_wire_pilot_codec.generated.ts +4 -4
- package/src/runtime/spots/formal-remote-actor-admission-registry.ts +45 -23
- package/src/runtime/spots/index.ts +30 -2
- package/src/runtime/spots/spot-activation.ts +33 -10
- package/src/runtime/spots/spot-actor-admission-coordinator.ts +13 -0
- package/src/runtime/spots/spot-actor-packet-dispatch.ts +10 -0
- package/src/runtime/spots/spot-actor-packet-drain.ts +2 -0
- package/src/runtime/spots/spot-actor-packet-relay-dispatch.ts +1 -0
- package/src/runtime/spots/spot-entry-activation.ts +12 -2
- package/src/runtime/spots/spot-handler-registry.ts +41 -8
- package/src/runtime/spots/spot-node-autoconnect.ts +6 -2
- package/src/runtime/spots/spot-node-runtime-manager.ts +7 -12
- package/src/runtime/spots/spot-outbound.ts +36 -16
- package/src/runtime/spots/spot-routed-spot-packet-dispatch.ts +2 -1
- package/src/runtime/spots/spot-routing-internal.ts +14 -0
- package/src/runtime/spots/spot-runtime-ports.ts +3 -0
- package/src/runtime/spots/spot-subscription-dispatch.ts +0 -3
- package/src/runtime/spots/spot-timer.ts +5 -1
- package/src/runtime/streams/stream-session-runtime.ts +13 -30
|
@@ -58,6 +58,7 @@ export interface ZLinkMeshDispatchFailureContext {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
export class ZLinkMeshDispatchPump {
|
|
61
|
+
private readonly dispatchOwnedRecord = this.dispatchRecord.bind(this);
|
|
61
62
|
private pendingDomains: number = ReadyDomain.None;
|
|
62
63
|
private infrastructureScheduled = false;
|
|
63
64
|
private disposed = false;
|
|
@@ -180,6 +181,36 @@ export class ZLinkMeshDispatchPump {
|
|
|
180
181
|
return new Promise((resolve) => this.idleApplicationWorkers.add(resolve));
|
|
181
182
|
}
|
|
182
183
|
|
|
184
|
+
private dispatchRecord(owner: ReadyRecord, record: ReceiveRecord): void | Promise<void> {
|
|
185
|
+
let result: void | Promise<void>;
|
|
186
|
+
try {
|
|
187
|
+
result = this.options.dispatch(owner, record);
|
|
188
|
+
} catch (error) {
|
|
189
|
+
this.reportDispatchError(error, meshDispatchFailureContext(record));
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
return result === undefined
|
|
193
|
+
? this.finishRecord(record)
|
|
194
|
+
: Promise.resolve(result).then(
|
|
195
|
+
() => this.finishRecord(record),
|
|
196
|
+
(error) => this.reportDispatchError(error, meshDispatchFailureContext(record))
|
|
197
|
+
);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
private finishRecord(record: ReceiveRecord): void | Promise<void> {
|
|
201
|
+
let result: void | Promise<void>;
|
|
202
|
+
try {
|
|
203
|
+
result = record.onTerminalCompletion?.();
|
|
204
|
+
} catch (error) {
|
|
205
|
+
this.reportDispatchError(error, meshDispatchFailureContext(record));
|
|
206
|
+
return;
|
|
207
|
+
}
|
|
208
|
+
if (result !== undefined)
|
|
209
|
+
return Promise.resolve(result).catch((error) =>
|
|
210
|
+
this.reportDispatchError(error, meshDispatchFailureContext(record))
|
|
211
|
+
);
|
|
212
|
+
}
|
|
213
|
+
|
|
183
214
|
private reportDispatchError(error: unknown, context?: ZLinkMeshDispatchFailureContext): void {
|
|
184
215
|
this.options.reportError?.(error, context);
|
|
185
216
|
}
|
|
@@ -253,7 +284,7 @@ export class ZLinkMeshDispatchPump {
|
|
|
253
284
|
): Promise<boolean> {
|
|
254
285
|
let claimsDrained = 0;
|
|
255
286
|
try {
|
|
256
|
-
|
|
287
|
+
while (!this.disposed) {
|
|
257
288
|
if (claimBudget !== undefined && claimsDrained >= claimBudget) {
|
|
258
289
|
// Lifecycle work has priority, but a bounded turn lets application
|
|
259
290
|
// work make progress when lifecycle records keep arriving.
|
|
@@ -282,19 +313,18 @@ export class ZLinkMeshDispatchPump {
|
|
|
282
313
|
);
|
|
283
314
|
const capacity =
|
|
284
315
|
owner.ordinaryIngressPreAdmitted === true ? MESH_DISPATCH_RECEIVE_CAPACITY : 1;
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
// This owner keeps its claim while it drains, so its records stay in FIFO order.
|
|
316
|
+
let claimPermit =
|
|
317
|
+
owner.terminalCompletion === true ||
|
|
318
|
+
owner.ordinaryIngressPreAdmitted === true ||
|
|
319
|
+
domain === ReadyDomain.Infrastructure
|
|
320
|
+
? undefined
|
|
321
|
+
: await this.acquirePermit();
|
|
322
|
+
try {
|
|
323
|
+
if (this.capacityStop.signal.aborted) return;
|
|
324
|
+
ownerReceiveBatch.reset(capacity);
|
|
325
|
+
const received = claim.recvBatch(ownerReceiveBatch, ZLINK_BACKEND_RECV_DONT_WAIT);
|
|
326
|
+
if (received.ok) {
|
|
327
|
+
// The bounded batch stays in claim order until its records finish.
|
|
298
328
|
try {
|
|
299
329
|
for (const record of received.records) {
|
|
300
330
|
if (this.disposed) break;
|
|
@@ -305,16 +335,9 @@ export class ZLinkMeshDispatchPump {
|
|
|
305
335
|
);
|
|
306
336
|
}
|
|
307
337
|
this.recordsSinceYield += 1;
|
|
308
|
-
const dispatch = async () => {
|
|
309
|
-
try {
|
|
310
|
-
await this.options.dispatch(owner, record);
|
|
311
|
-
await record.onTerminalCompletion?.();
|
|
312
|
-
} catch (error) {
|
|
313
|
-
this.reportDispatchError(error, meshDispatchFailureContext(record));
|
|
314
|
-
}
|
|
315
|
-
};
|
|
316
338
|
if (permit === undefined) {
|
|
317
|
-
|
|
339
|
+
const dispatched = this.dispatchRecord(owner, record);
|
|
340
|
+
if (dispatched !== undefined) await dispatched;
|
|
318
341
|
} else {
|
|
319
342
|
if (
|
|
320
343
|
domain === ReadyDomain.Application &&
|
|
@@ -325,10 +348,14 @@ export class ZLinkMeshDispatchPump {
|
|
|
325
348
|
// and detached handler handoff. Only unused permits remain
|
|
326
349
|
// owned by the receive attempt's finally block.
|
|
327
350
|
if (permit === claimPermit) claimPermit = undefined;
|
|
328
|
-
|
|
351
|
+
const dispatched = runWithApplicationJobPermit(
|
|
352
|
+
permit,
|
|
353
|
+
this.dispatchOwnedRecord,
|
|
354
|
+
owner,
|
|
355
|
+
record
|
|
356
|
+
);
|
|
357
|
+
if (dispatched !== undefined) await dispatched;
|
|
329
358
|
}
|
|
330
|
-
const yieldTurn = this.yieldIfNeeded();
|
|
331
|
-
if (yieldTurn !== undefined) await yieldTurn;
|
|
332
359
|
}
|
|
333
360
|
} finally {
|
|
334
361
|
// Batch ownership includes records whose dispatch never began,
|
|
@@ -338,14 +365,16 @@ export class ZLinkMeshDispatchPump {
|
|
|
338
365
|
record.releaseRetainedIngress?.();
|
|
339
366
|
}
|
|
340
367
|
}
|
|
341
|
-
} finally {
|
|
342
|
-
claimPermit?.releaseAfterInternalProcessing();
|
|
343
368
|
}
|
|
369
|
+
} finally {
|
|
370
|
+
claimPermit?.releaseAfterInternalProcessing();
|
|
344
371
|
}
|
|
345
372
|
} finally {
|
|
346
373
|
claim.release();
|
|
347
374
|
if (receiveBatch === undefined) ownerReceiveBatch?.close();
|
|
348
375
|
}
|
|
376
|
+
const yieldTurn = this.yieldIfNeeded();
|
|
377
|
+
if (yieldTurn !== undefined) await yieldTurn;
|
|
349
378
|
};
|
|
350
379
|
// An application worker drains the one owner it claimed. Infrastructure owners
|
|
351
380
|
// drain independently, so a suspended owner does not hold the other claims.
|
|
@@ -366,10 +395,8 @@ export class ZLinkMeshDispatchPump {
|
|
|
366
395
|
this.recordsSinceYield += 1;
|
|
367
396
|
const yieldTurn = this.yieldIfNeeded();
|
|
368
397
|
if (yieldTurn !== undefined) await yieldTurn;
|
|
369
|
-
if (!drained.hasResidue) {
|
|
370
|
-
return false;
|
|
371
|
-
}
|
|
372
398
|
}
|
|
399
|
+
return false;
|
|
373
400
|
} finally {
|
|
374
401
|
readyBatch.reset();
|
|
375
402
|
}
|
|
@@ -394,7 +421,7 @@ export class ZLinkMeshDispatchPump {
|
|
|
394
421
|
|
|
395
422
|
private async acquirePermit(): Promise<ApplicationJobPermitPort | undefined> {
|
|
396
423
|
try {
|
|
397
|
-
return await this.options.applicationJobQueue.acquire(this.capacityStop.signal);
|
|
424
|
+
return await this.options.applicationJobQueue.acquire(this.capacityStop.signal, 'remote');
|
|
398
425
|
} catch (error) {
|
|
399
426
|
if (this.disposed || this.capacityStop.signal.aborted) return undefined;
|
|
400
427
|
throw error;
|
|
@@ -1,4 +1,9 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
Context,
|
|
3
|
+
CoreHwmBudgetSnapshot,
|
|
4
|
+
ReceiveFlowState,
|
|
5
|
+
TopicMessage
|
|
6
|
+
} from '@zlink-systems/zlink';
|
|
2
7
|
import type { ZLinkCoreHwmOptions } from '../../../contracts/Configuration';
|
|
3
8
|
import type {
|
|
4
9
|
ZLinkBackendAdapterFactory,
|
|
@@ -60,10 +65,12 @@ class ZLinkNodeChannelBackendAdapter implements ZLinkChannelBackendAdapter {
|
|
|
60
65
|
}
|
|
61
66
|
|
|
62
67
|
createRouterSocket(context: ZLinkBackendContext): ZLinkBackendRouterSocket {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
68
|
+
const socket = zlink.createRouterSocket(asNodeContext(context));
|
|
69
|
+
const adapter = wrapSocket(socket, true);
|
|
70
|
+
adapter.setReceiveFlowState = (state: ReceiveFlowState): void => {
|
|
71
|
+
socket.setReceiveFlowState(state);
|
|
72
|
+
};
|
|
73
|
+
return adapter as unknown as ZLinkBackendRouterSocket;
|
|
67
74
|
}
|
|
68
75
|
|
|
69
76
|
createPublisherSocket(context: ZLinkBackendContext): ZLinkBackendPublisherSocket {
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { loadBinding } from '../node-backend-adapter';
|
|
8
8
|
import { SubmitResult, ZLinkBackendResultError } from '../runtime-values';
|
|
9
9
|
const nativeErrnoValues = osConstants.errno;
|
|
10
|
+
const completedSend: Promise<void> = Promise.resolve();
|
|
10
11
|
|
|
11
12
|
export type ZLinkBindingModule = typeof import('@zlink-systems/zlink');
|
|
12
13
|
export const zlink = loadBinding() as ZLinkBindingModule;
|
|
@@ -119,10 +120,22 @@ export function submitBindingReply(operation: ZLinkBindingReplyOperation, payloa
|
|
|
119
120
|
}
|
|
120
121
|
}
|
|
121
122
|
|
|
122
|
-
export
|
|
123
|
+
export function submitBindingAsyncSend(
|
|
123
124
|
operation: ZLinkBindingAsyncSendOperation,
|
|
124
125
|
payload: unknown
|
|
125
126
|
): Promise<void> {
|
|
127
|
+
try {
|
|
128
|
+
const submission = submitBindingSend(operation, payload);
|
|
129
|
+
return submission.result === SubmitResult.Backpressured ? submission.admitted : completedSend;
|
|
130
|
+
} catch (error) {
|
|
131
|
+
return Promise.reject(error);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
export function submitBindingSend(
|
|
136
|
+
operation: ZLinkBindingAsyncSendOperation,
|
|
137
|
+
payload: unknown
|
|
138
|
+
): import('../raw-binding-port').ZLinkRawSendSubmission {
|
|
126
139
|
let submission: import('@zlink-systems/zlink').SendSubmission;
|
|
127
140
|
try {
|
|
128
141
|
let current: ZLinkBindingAsyncSendSubmitOperation | undefined;
|
|
@@ -137,12 +150,15 @@ export async function submitBindingAsyncSend(
|
|
|
137
150
|
throw translateBindingResultError(error, 'submit');
|
|
138
151
|
}
|
|
139
152
|
if (submission.result === SubmitResult.Backpressured) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
153
|
+
return {
|
|
154
|
+
result: submission.result,
|
|
155
|
+
admitted: submission.admitted.catch((error) => {
|
|
156
|
+
throw translateBindingResultError(error, 'completion');
|
|
157
|
+
})
|
|
158
|
+
};
|
|
145
159
|
}
|
|
160
|
+
// Binding SendSubmission is the closed OK | BACKPRESSURED snapshot.
|
|
161
|
+
return submission as import('../raw-binding-port').ZLinkRawSendSubmission;
|
|
146
162
|
}
|
|
147
163
|
|
|
148
164
|
export function submitBindingSyncSend(
|
|
@@ -166,7 +182,9 @@ export function submitBindingSyncSend(
|
|
|
166
182
|
export async function submitBindingRequest(
|
|
167
183
|
operation: ZLinkBindingRequestOperation,
|
|
168
184
|
payload: unknown,
|
|
169
|
-
timeoutMs: number | undefined
|
|
185
|
+
timeoutMs: number | undefined,
|
|
186
|
+
recordReceived?: () => void,
|
|
187
|
+
onAdmitted?: () => void
|
|
170
188
|
): Promise<readonly unknown[]> {
|
|
171
189
|
const deadlineMs = timeoutMs === undefined ? undefined : performance.now() + timeoutMs;
|
|
172
190
|
try {
|
|
@@ -184,7 +202,7 @@ export async function submitBindingRequest(
|
|
|
184
202
|
if (timeoutMs !== undefined) {
|
|
185
203
|
current = current.timeout(timeoutMs);
|
|
186
204
|
}
|
|
187
|
-
return await bindingRequestReply(current.submit(), deadlineMs);
|
|
205
|
+
return await bindingRequestReply(current.submit(), deadlineMs, recordReceived, onAdmitted);
|
|
188
206
|
} catch (error) {
|
|
189
207
|
throw translateBindingResultError(error);
|
|
190
208
|
}
|
|
@@ -192,23 +210,35 @@ export async function submitBindingRequest(
|
|
|
192
210
|
|
|
193
211
|
export async function bindingRequestReply(
|
|
194
212
|
submission: import('@zlink-systems/zlink').RequestSubmission,
|
|
195
|
-
deadlineMs: number | undefined
|
|
213
|
+
deadlineMs: number | undefined,
|
|
214
|
+
recordReceived?: () => void,
|
|
215
|
+
onAdmitted?: () => void
|
|
196
216
|
): Promise<import('@zlink-systems/zlink').Message[]> {
|
|
197
217
|
const reply = submission.reply;
|
|
198
218
|
if (submission.result === SubmitResult.Backpressured) {
|
|
199
219
|
try {
|
|
200
220
|
const [, replies] = await waitRequestReply(
|
|
201
|
-
Promise.all([submission.admitted, reply]),
|
|
221
|
+
Promise.all([submission.admitted.then(() => onAdmitted?.()), reply]),
|
|
202
222
|
'Request',
|
|
203
223
|
deadlineMs
|
|
204
224
|
);
|
|
225
|
+
recordReceived?.();
|
|
205
226
|
return replies;
|
|
206
227
|
} catch (error) {
|
|
207
|
-
void reply.then(
|
|
228
|
+
void reply.then(
|
|
229
|
+
(parts) => {
|
|
230
|
+
recordReceived?.();
|
|
231
|
+
closeBindingReply(parts);
|
|
232
|
+
},
|
|
233
|
+
() => undefined
|
|
234
|
+
);
|
|
208
235
|
throw error;
|
|
209
236
|
}
|
|
210
237
|
}
|
|
211
|
-
|
|
238
|
+
onAdmitted?.();
|
|
239
|
+
const replies = await reply;
|
|
240
|
+
recordReceived?.();
|
|
241
|
+
return replies;
|
|
212
242
|
}
|
|
213
243
|
|
|
214
244
|
export function closeBindingReply(
|
|
@@ -248,25 +278,6 @@ export function isContextTerminatedError(error: unknown): boolean {
|
|
|
248
278
|
return error instanceof Error && /context was terminated/i.test(error.message);
|
|
249
279
|
}
|
|
250
280
|
|
|
251
|
-
export function disableSocketLinger(target: unknown): void {
|
|
252
|
-
if (
|
|
253
|
-
target !== null &&
|
|
254
|
-
typeof target === 'object' &&
|
|
255
|
-
'options' in target &&
|
|
256
|
-
typeof target.options === 'object' &&
|
|
257
|
-
target.options !== null &&
|
|
258
|
-
'linger' in target.options
|
|
259
|
-
) {
|
|
260
|
-
try {
|
|
261
|
-
(target.options as { linger: number }).linger = 0;
|
|
262
|
-
} catch (error) {
|
|
263
|
-
if (!isContextTerminatedError(error)) {
|
|
264
|
-
throw error;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
|
|
270
281
|
export function toNativeRoutingId(routingId: unknown): unknown {
|
|
271
282
|
if (typeof routingId === 'string') return zlink.RoutingId.from(routingId);
|
|
272
283
|
const toHex = (routingId as { readonly toHex?: unknown } | null)?.toHex;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { bindingRequestReply } from './node-backend-adapter-support';
|
|
1
2
|
import type { DealerSocket, Message, PubSocket } from '@zlink-systems/zlink';
|
|
2
3
|
import { ZLinkConfigurationException } from '../../configuration';
|
|
3
4
|
import { ZLinkSubmitStatus, type ZLinkSubmitResult } from '../../messaging/submission-result';
|
|
@@ -56,7 +57,8 @@ export class ZLinkDealerChannelClientTransport implements ZLinkChannelClientTran
|
|
|
56
57
|
request: Message,
|
|
57
58
|
timeoutMs: number | undefined,
|
|
58
59
|
signal?: AbortSignal,
|
|
59
|
-
metadata: ReadonlyMap<string, string> = EMPTY_METADATA
|
|
60
|
+
metadata: ReadonlyMap<string, string> = EMPTY_METADATA,
|
|
61
|
+
onAdmitted?: () => void
|
|
60
62
|
): Promise<TReply> {
|
|
61
63
|
throwIfAborted(signal);
|
|
62
64
|
const operation = runWithOutboundFlow(true, () =>
|
|
@@ -78,7 +80,15 @@ export class ZLinkDealerChannelClientTransport implements ZLinkChannelClientTran
|
|
|
78
80
|
);
|
|
79
81
|
if (timeoutMs !== undefined) operation.timeout(timeoutMs);
|
|
80
82
|
const reply = await submitRequestOperation(
|
|
81
|
-
{
|
|
83
|
+
{
|
|
84
|
+
submit: () =>
|
|
85
|
+
bindingRequestReply(
|
|
86
|
+
operation.submit(),
|
|
87
|
+
timeoutMs === undefined ? undefined : performance.now() + timeoutMs,
|
|
88
|
+
undefined,
|
|
89
|
+
onAdmitted
|
|
90
|
+
)
|
|
91
|
+
},
|
|
82
92
|
'channel request'
|
|
83
93
|
);
|
|
84
94
|
try {
|
|
@@ -10,15 +10,7 @@ import type { Context } from '@zlink-systems/zlink';
|
|
|
10
10
|
export class ZLinkNodeMeshBackendAdapter implements ZLinkMeshBackendAdapter {
|
|
11
11
|
createMeshNode(
|
|
12
12
|
context: ZLinkBackendContext,
|
|
13
|
-
options:
|
|
14
|
-
readonly meshName: string;
|
|
15
|
-
readonly routingId?: string;
|
|
16
|
-
readonly receiveTimeoutMs?: number;
|
|
17
|
-
readonly trustProfile?: string;
|
|
18
|
-
readonly applicationJobQueue: import('../../application-jobs/contracts').ApplicationJobQueuePort;
|
|
19
|
-
readonly applicationJobReceiveFlowFailureSink?: (error: unknown) => void;
|
|
20
|
-
readonly peerAdmissionSealed?: () => boolean;
|
|
21
|
-
}
|
|
13
|
+
options: Parameters<ZLinkMeshBackendAdapter['createMeshNode']>[1]
|
|
22
14
|
): ZLinkBackendMeshNode {
|
|
23
15
|
if (options.trustProfile !== undefined) {
|
|
24
16
|
throw new Error(
|
|
@@ -37,7 +29,8 @@ export class ZLinkNodeMeshBackendAdapter implements ZLinkMeshBackendAdapter {
|
|
|
37
29
|
new ZLinkNodeRawBindingPort(bindingContext, options.receiveTimeoutMs),
|
|
38
30
|
options.applicationJobQueue,
|
|
39
31
|
options.applicationJobReceiveFlowFailureSink,
|
|
40
|
-
options.peerAdmissionSealed
|
|
32
|
+
options.peerAdmissionSealed,
|
|
33
|
+
options.infrastructureTaskRunner
|
|
41
34
|
);
|
|
42
35
|
}
|
|
43
36
|
}
|
|
@@ -22,10 +22,12 @@ import {
|
|
|
22
22
|
import {
|
|
23
23
|
translateBindingResultError,
|
|
24
24
|
bindingRequestReply,
|
|
25
|
-
submitBindingAsyncSend
|
|
25
|
+
submitBindingAsyncSend,
|
|
26
|
+
submitBindingSend
|
|
26
27
|
} from './node-backend-adapter-support';
|
|
27
28
|
import { isEndpointCloseIgnorableError } from './node-socket-backend-adapter';
|
|
28
29
|
import { ZLinkNodeEventLoopPoller } from './node-event-loop-poller';
|
|
30
|
+
import { ZLinkBufferMessage } from '../runtime-message';
|
|
29
31
|
import type {
|
|
30
32
|
ZLinkRawBindingPort,
|
|
31
33
|
ZLinkRawDealerPort,
|
|
@@ -171,13 +173,6 @@ abstract class NodeRawSocketPort<TSocket extends Socket> implements ZLinkRawSock
|
|
|
171
173
|
this.endpoints.delete(`connect\0${endpoint}`);
|
|
172
174
|
}
|
|
173
175
|
|
|
174
|
-
setReceiveFlowState(state: 'running' | 'paused'): void {
|
|
175
|
-
this.requireOpen();
|
|
176
|
-
this.socket.setReceiveFlowState(
|
|
177
|
-
state === 'paused' ? ReceiveFlowState.PAUSED : ReceiveFlowState.RUNNING
|
|
178
|
-
);
|
|
179
|
-
}
|
|
180
|
-
|
|
181
176
|
monitor(): ZLinkRawMonitorPort {
|
|
182
177
|
this.requireOpen();
|
|
183
178
|
const nativeMonitor = this.socket.monitorOpen();
|
|
@@ -232,13 +227,57 @@ abstract class NodeRawSocketPort<TSocket extends Socket> implements ZLinkRawSock
|
|
|
232
227
|
|
|
233
228
|
class NodeRawRouterPort extends NodeRawSocketPort<RouterSocket> implements ZLinkRawRouterPort {
|
|
234
229
|
private nextIncomingRequestSequence = 1n;
|
|
230
|
+
private readonly routingIds = new Map<string, BindingRoutingId>();
|
|
231
|
+
private readonly nextRequestSequence = () => {
|
|
232
|
+
const current = this.nextIncomingRequestSequence;
|
|
233
|
+
this.nextIncomingRequestSequence =
|
|
234
|
+
current === BigInt(Number.MAX_SAFE_INTEGER) ? 1n : current + 1n;
|
|
235
|
+
return current;
|
|
236
|
+
};
|
|
237
|
+
private readonly replyParts = (
|
|
238
|
+
targetRid: string | Uint8Array,
|
|
239
|
+
replyToken: unknown,
|
|
240
|
+
parts: readonly Uint8Array[]
|
|
241
|
+
) => {
|
|
242
|
+
appendReplyParts(
|
|
243
|
+
this.socket.reply(
|
|
244
|
+
this.preparedRoutingId(targetRid),
|
|
245
|
+
replyToken as Parameters<RouterSocket['reply']>[1]
|
|
246
|
+
),
|
|
247
|
+
parts
|
|
248
|
+
).submit();
|
|
249
|
+
};
|
|
250
|
+
|
|
251
|
+
private preparedRoutingId(routingId: string | Uint8Array): BindingRoutingId {
|
|
252
|
+
if (typeof routingId !== 'string') return bindingRoutingId(routingId);
|
|
253
|
+
let prepared = this.routingIds.get(routingId);
|
|
254
|
+
if (prepared === undefined)
|
|
255
|
+
this.routingIds.set(routingId, (prepared = bindingRoutingId(routingId)));
|
|
256
|
+
return prepared;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
override close(): void {
|
|
260
|
+
try {
|
|
261
|
+
super.close();
|
|
262
|
+
} finally {
|
|
263
|
+
this.routingIds.clear();
|
|
264
|
+
}
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
setReceiveFlowState(state: 'running' | 'paused'): void {
|
|
268
|
+
this.requireOpen();
|
|
269
|
+
this.socket.setReceiveFlowState(
|
|
270
|
+
state === 'paused' ? ReceiveFlowState.PAUSED : ReceiveFlowState.RUNNING
|
|
271
|
+
);
|
|
272
|
+
}
|
|
273
|
+
|
|
235
274
|
disconnectRid(routingId: string): void {
|
|
236
275
|
this.requireOpen();
|
|
237
276
|
(
|
|
238
277
|
this.socket as RouterSocket & {
|
|
239
278
|
disconnectRid(value: BindingRoutingId): void;
|
|
240
279
|
}
|
|
241
|
-
).disconnectRid(
|
|
280
|
+
).disconnectRid(this.preparedRoutingId(routingId));
|
|
242
281
|
}
|
|
243
282
|
|
|
244
283
|
constructor(socket: RouterSocket, receiveTimeoutMs?: number) {
|
|
@@ -258,39 +297,47 @@ class NodeRawRouterPort extends NodeRawSocketPort<RouterSocket> implements ZLink
|
|
|
258
297
|
|
|
259
298
|
setRoutingId(routingId: string): void {
|
|
260
299
|
this.requireOpen();
|
|
261
|
-
this.socket.setRoutingId(
|
|
300
|
+
this.socket.setRoutingId(this.preparedRoutingId(routingId));
|
|
262
301
|
}
|
|
263
302
|
|
|
264
303
|
connectToRoutingId(routingId: string, endpoint: string): void {
|
|
265
304
|
this.requireOpen();
|
|
266
|
-
this.socket.options.setConnectRoutingId(
|
|
305
|
+
this.socket.options.setConnectRoutingId(this.preparedRoutingId(routingId));
|
|
267
306
|
this.connect(endpoint);
|
|
268
307
|
}
|
|
269
308
|
|
|
270
309
|
send(targetRid: string, parts: readonly Uint8Array[]): Promise<void> {
|
|
271
310
|
this.requireOpen();
|
|
272
311
|
requireParts(parts);
|
|
273
|
-
return submitBindingAsyncSend(this.socket.send(
|
|
312
|
+
return submitBindingAsyncSend(this.socket.send(this.preparedRoutingId(targetRid)), parts);
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
submitSend(targetRid: string, parts: readonly Uint8Array[]) {
|
|
316
|
+
this.requireOpen();
|
|
317
|
+
requireParts(parts);
|
|
318
|
+
return submitBindingSend(this.socket.send(this.preparedRoutingId(targetRid)), parts);
|
|
274
319
|
}
|
|
275
320
|
|
|
276
321
|
async request(
|
|
277
322
|
targetRid: string,
|
|
278
323
|
parts: readonly Uint8Array[],
|
|
279
|
-
timeoutMs: number
|
|
324
|
+
timeoutMs: number,
|
|
325
|
+
recordReceived?: () => void,
|
|
326
|
+
onAdmitted?: () => void
|
|
280
327
|
): Promise<readonly Buffer[]> {
|
|
281
328
|
this.requireOpen();
|
|
282
329
|
const deadlineMs = performance.now() + timeoutMs;
|
|
283
330
|
let submission: ReturnType<RequestSubmitOperation['submit']>;
|
|
284
331
|
try {
|
|
285
|
-
submission = appendRequestParts(this.socket.request(
|
|
332
|
+
submission = appendRequestParts(this.socket.request(this.preparedRoutingId(targetRid)), parts)
|
|
286
333
|
.timeout(timeoutMs)
|
|
287
334
|
.submit();
|
|
288
335
|
} catch (error) {
|
|
289
336
|
throw translateBindingResultError(error, 'submit');
|
|
290
337
|
}
|
|
291
338
|
try {
|
|
292
|
-
const replies = await bindingRequestReply(submission, deadlineMs);
|
|
293
|
-
return
|
|
339
|
+
const replies = await bindingRequestReply(submission, deadlineMs, recordReceived, onAdmitted);
|
|
340
|
+
return retainAndClose(replies);
|
|
294
341
|
} catch (error) {
|
|
295
342
|
throw translateBindingResultError(error, 'completion');
|
|
296
343
|
}
|
|
@@ -306,22 +353,7 @@ class NodeRawRouterPort extends NodeRawSocketPort<RouterSocket> implements ZLink
|
|
|
306
353
|
|
|
307
354
|
receive(dontWait = false): ZLinkRawReceivedRecord | undefined {
|
|
308
355
|
this.requireOpen();
|
|
309
|
-
return receiveRecord(
|
|
310
|
-
this.socket,
|
|
311
|
-
dontWait,
|
|
312
|
-
() => {
|
|
313
|
-
const current = this.nextIncomingRequestSequence;
|
|
314
|
-
this.nextIncomingRequestSequence =
|
|
315
|
-
current === BigInt(Number.MAX_SAFE_INTEGER) ? 1n : current + 1n;
|
|
316
|
-
return current;
|
|
317
|
-
},
|
|
318
|
-
(targetRid, replyToken, parts) => {
|
|
319
|
-
appendReplyParts(
|
|
320
|
-
this.socket.reply(bindingRoutingId(targetRid), replyToken),
|
|
321
|
-
parts
|
|
322
|
-
).submit();
|
|
323
|
-
}
|
|
324
|
-
);
|
|
356
|
+
return receiveRecord(this.socket, dontWait, this.nextRequestSequence, this.replyParts);
|
|
325
357
|
}
|
|
326
358
|
}
|
|
327
359
|
|
|
@@ -341,7 +373,11 @@ class NodeRawDealerPort extends NodeRawSocketPort<DealerSocket> implements ZLink
|
|
|
341
373
|
return submitBindingAsyncSend(this.socket.send(), parts);
|
|
342
374
|
}
|
|
343
375
|
|
|
344
|
-
async request(
|
|
376
|
+
async request(
|
|
377
|
+
parts: readonly Uint8Array[],
|
|
378
|
+
timeoutMs: number,
|
|
379
|
+
onAdmitted?: () => void
|
|
380
|
+
): Promise<readonly Buffer[]> {
|
|
345
381
|
this.requireOpen();
|
|
346
382
|
const deadlineMs = performance.now() + timeoutMs;
|
|
347
383
|
let submission: ReturnType<RequestSubmitOperation['submit']>;
|
|
@@ -351,8 +387,8 @@ class NodeRawDealerPort extends NodeRawSocketPort<DealerSocket> implements ZLink
|
|
|
351
387
|
throw translateBindingResultError(error, 'submit');
|
|
352
388
|
}
|
|
353
389
|
try {
|
|
354
|
-
const replies = await bindingRequestReply(submission, deadlineMs);
|
|
355
|
-
return
|
|
390
|
+
const replies = await bindingRequestReply(submission, deadlineMs, undefined, onAdmitted);
|
|
391
|
+
return retainAndClose(replies);
|
|
356
392
|
} catch (error) {
|
|
357
393
|
throw translateBindingResultError(error, 'completion');
|
|
358
394
|
}
|
|
@@ -484,9 +520,9 @@ function receiveRecord(
|
|
|
484
520
|
}
|
|
485
521
|
}
|
|
486
522
|
|
|
487
|
-
function
|
|
523
|
+
function retainAndClose(messages: readonly Message[]): readonly Buffer[] {
|
|
488
524
|
try {
|
|
489
|
-
return messages.map((message) =>
|
|
525
|
+
return messages.map((message) => ZLinkBufferMessage.retainPayload(message));
|
|
490
526
|
} finally {
|
|
491
527
|
for (const message of messages) message.close();
|
|
492
528
|
}
|