@zlink-systems/framework 0.11.0 → 0.12.0
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/dist/.tsbuildinfo +1 -1
- package/dist/contracts/Configuration/EndpointNotation.d.ts +5 -4
- package/dist/contracts/Configuration/EndpointNotation.js +5 -4
- package/dist/contracts/Configuration/InternalDefaults.d.ts +0 -1
- package/dist/contracts/Configuration/InternalDefaults.js +1 -2
- package/dist/contracts/Configuration/RegistrationNormalizers.js +1 -2
- package/dist/contracts/Configuration/RegistrationTypes.d.ts +2 -5
- package/dist/contracts/Configuration/RegistrationValidators.js +0 -1
- package/dist/contracts/Errors/ZLinkFrameworkException.d.ts +6 -7
- package/dist/contracts/Errors/ZLinkFrameworkException.js +6 -7
- package/dist/runtime/actors/actor-client.js +1 -1
- package/dist/runtime/actors/actor-mailbox.js +1 -5
- package/dist/runtime/backend/contracts/index.d.ts +2 -0
- package/dist/runtime/backend/mesh-completion-table.d.ts +1 -3
- package/dist/runtime/backend/mesh-completion-table.js +11 -15
- package/dist/runtime/backend/mesh-dispatch-pump.d.ts +11 -4
- package/dist/runtime/backend/mesh-dispatch-pump.js +201 -134
- package/dist/runtime/backend/node/node-backend-adapter-factory.d.ts +3 -4
- package/dist/runtime/backend/node/node-backend-adapter-factory.js +51 -37
- package/dist/runtime/backend/node/node-backend-adapter-support.d.ts +2 -2
- package/dist/runtime/backend/node/node-backend-adapter-support.js +2 -2
- package/dist/runtime/backend/node/node-dealer-channel-client-transport.js +2 -2
- package/dist/runtime/backend/node/node-event-loop-poller.d.ts +16 -0
- package/dist/runtime/backend/node/node-event-loop-poller.js +49 -0
- package/dist/runtime/backend/node/node-raw-binding-port.js +24 -41
- package/dist/runtime/backend/node/node-raw-mesh-backend.d.ts +8 -8
- package/dist/runtime/backend/node/node-raw-mesh-backend.js +100 -107
- package/dist/runtime/backend/node/node-socket-backend-adapter.d.ts +3 -2
- package/dist/runtime/backend/node/node-socket-backend-adapter.js +18 -67
- package/dist/runtime/backend/raw-binding-port.d.ts +1 -0
- package/dist/runtime/backend/runtime-values.d.ts +5 -1
- package/dist/runtime/channels/channel-dispatchers.js +2 -2
- package/dist/runtime/channels/channel-envelope.js +324 -121
- package/dist/runtime/channels/channel-multipart.d.ts +8 -1
- package/dist/runtime/channels/channel-outbound-operations.js +0 -2
- package/dist/runtime/channels/channel-receive-loops.d.ts +1 -3
- package/dist/runtime/channels/channel-receive-loops.js +25 -65
- package/dist/runtime/channels/channel-socket-registry.js +3 -1
- package/dist/runtime/channels/channel-transports.d.ts +2 -1
- package/dist/runtime/channels/channel-transports.js +12 -10
- package/dist/runtime/execution/serial-execution-queue.d.ts +5 -18
- package/dist/runtime/execution/serial-execution-queue.js +16 -80
- package/dist/runtime/foundation/event-loop-resources.d.ts +0 -3
- package/dist/runtime/foundation/event-loop-resources.js +2 -11
- package/dist/runtime/foundation/operation-registry.d.ts +2 -8
- package/dist/runtime/foundation/operation-registry.js +3 -21
- package/dist/runtime/foundation/raw-service-mesh-runtime.d.ts +19 -7
- package/dist/runtime/foundation/raw-service-mesh-runtime.js +56 -10
- package/dist/runtime/foundation/service-mailbox.d.ts +1 -7
- package/dist/runtime/foundation/service-mailbox.js +3 -2
- package/dist/runtime/foundation/service-runtime-contracts.d.ts +2 -1
- package/dist/runtime/foundation/service-stateful-registry.d.ts +1 -1
- package/dist/runtime/foundation/service-stateful-registry.js +2 -2
- package/dist/runtime/foundation/service-stateful-runtime.js +14 -14
- package/dist/runtime/framework-errors-internal.d.ts +4 -4
- package/dist/runtime/framework-errors-internal.js +8 -10
- package/dist/runtime/host/actor-placement-coordinator.js +1 -1
- package/dist/runtime/host/index.js +1 -1
- package/dist/runtime/host/service-relocation-host-runtime.js +0 -4
- package/dist/runtime/host/spot-address-transport.js +1 -1
- package/dist/runtime/host/user-spot-creation-coordinator.js +1 -1
- package/dist/runtime/spots/spot-node-runtime-manager.d.ts +0 -12
- package/dist/runtime/spots/spot-node-runtime-manager.js +6 -166
- package/dist/runtime/spots/spot-serial-turn-executor.js +1 -4
- package/dist/runtime/spots/spot-timer.d.ts +3 -0
- package/dist/runtime/spots/spot-timer.js +87 -18
- package/dist/runtime/streams/session-serial-executor.js +1 -3
- package/dist/runtime/streams/stream-session-runtime.d.ts +2 -2
- package/dist/runtime/streams/stream-session-runtime.js +13 -19
- package/dist/runtime/workers/index.d.ts +0 -1
- package/dist/runtime/workers/index.js +1 -9
- package/package.json +3 -3
- package/src/contracts/Configuration/EndpointNotation.ts +5 -4
- package/src/contracts/Configuration/InternalDefaults.ts +0 -1
- package/src/contracts/Configuration/RegistrationNormalizers.ts +2 -4
- package/src/contracts/Configuration/RegistrationTypes.ts +2 -5
- package/src/contracts/Configuration/RegistrationValidators.ts +0 -1
- package/src/contracts/Errors/ZLinkFrameworkException.ts +6 -7
- package/src/runtime/actors/actor-client.ts +1 -1
- package/src/runtime/actors/actor-mailbox.ts +1 -12
- package/src/runtime/backend/contracts/index.ts +2 -0
- package/src/runtime/backend/mesh-completion-table.ts +12 -23
- package/src/runtime/backend/mesh-dispatch-pump.ts +206 -138
- package/src/runtime/backend/node/node-backend-adapter-factory.ts +66 -35
- package/src/runtime/backend/node/node-backend-adapter-support.ts +4 -4
- package/src/runtime/backend/node/node-dealer-channel-client-transport.ts +2 -2
- package/src/runtime/backend/node/node-event-loop-poller.ts +55 -0
- package/src/runtime/backend/node/node-raw-binding-port.ts +30 -45
- package/src/runtime/backend/node/node-raw-mesh-backend.ts +97 -110
- package/src/runtime/backend/node/node-socket-backend-adapter.ts +23 -69
- package/src/runtime/backend/raw-binding-port.ts +1 -0
- package/src/runtime/backend/runtime-values.ts +7 -1
- package/src/runtime/channels/channel-dispatchers.ts +2 -2
- package/src/runtime/channels/channel-envelope.ts +379 -109
- package/src/runtime/channels/channel-multipart.ts +9 -1
- package/src/runtime/channels/channel-outbound-operations.ts +0 -1
- package/src/runtime/channels/channel-receive-loops.ts +24 -75
- package/src/runtime/channels/channel-socket-registry.ts +4 -1
- package/src/runtime/channels/channel-transports.ts +20 -10
- package/src/runtime/execution/serial-execution-queue.ts +16 -108
- package/src/runtime/foundation/event-loop-resources.ts +2 -11
- package/src/runtime/foundation/operation-registry.ts +2 -22
- package/src/runtime/foundation/raw-service-mesh-runtime.ts +74 -19
- package/src/runtime/foundation/service-mailbox.ts +3 -13
- package/src/runtime/foundation/service-runtime-contracts.ts +2 -1
- package/src/runtime/foundation/service-stateful-registry.ts +2 -2
- package/src/runtime/foundation/service-stateful-runtime.ts +14 -14
- package/src/runtime/framework-errors-internal.ts +8 -10
- package/src/runtime/host/actor-placement-coordinator.ts +1 -1
- package/src/runtime/host/index.ts +2 -1
- package/src/runtime/host/service-relocation-host-runtime.ts +0 -4
- package/src/runtime/host/spot-address-transport.ts +1 -1
- package/src/runtime/host/user-spot-creation-coordinator.ts +1 -1
- package/src/runtime/spots/spot-node-runtime-manager.ts +13 -233
- package/src/runtime/spots/spot-serial-turn-executor.ts +1 -8
- package/src/runtime/spots/spot-timer.ts +109 -18
- package/src/runtime/streams/session-serial-executor.ts +1 -7
- package/src/runtime/streams/stream-session-runtime.ts +13 -17
- package/src/runtime/workers/index.ts +2 -17
|
@@ -1,45 +1,43 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.wrapSocket = wrapSocket;
|
|
4
|
+
exports.nodeEventLoopPollerOf = nodeEventLoopPollerOf;
|
|
4
5
|
exports.disconnectStreamPeer = disconnectStreamPeer;
|
|
5
|
-
exports.isDisconnectRouteNotFoundError = isDisconnectRouteNotFoundError;
|
|
6
6
|
exports.isEndpointCloseIgnorableError = isEndpointCloseIgnorableError;
|
|
7
7
|
const node_backend_adapter_support_1 = require("./node-backend-adapter-support");
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
const peerRoutingIds = new Set();
|
|
8
|
+
const node_event_loop_poller_1 = require("./node-event-loop-poller");
|
|
9
|
+
const eventLoopPollers = new WeakMap();
|
|
10
|
+
function wrapSocket(nativeInstance, pollCompletion) {
|
|
12
11
|
const socket = nativeInstance;
|
|
13
12
|
const hasRequest = typeof nativeInstance.request === 'function';
|
|
14
13
|
const hasRoutedPeer = hasRequest
|
|
15
14
|
&& typeof nativeInstance.reply === 'function';
|
|
16
15
|
const hasStream = typeof nativeInstance.recvPacket === 'function';
|
|
16
|
+
const eventLoopPoller = pollCompletion === undefined
|
|
17
|
+
? undefined
|
|
18
|
+
: new node_event_loop_poller_1.ZLinkNodeEventLoopPoller(nativeInstance, pollCompletion, () => { });
|
|
17
19
|
const adapter = {
|
|
18
20
|
nativeInstance,
|
|
19
21
|
async dispose() {
|
|
22
|
+
eventLoopPoller?.dispose();
|
|
20
23
|
(0, node_backend_adapter_support_1.disableSocketLinger)(nativeInstance);
|
|
21
|
-
closeSocketRoutes(nativeInstance, peerRoutingIds);
|
|
22
|
-
closeSocketEndpoints(nativeInstance, boundEndpoints, connectedEndpoints);
|
|
23
24
|
await (0, node_backend_adapter_support_1.closeWithBusyRetry)(nativeInstance);
|
|
24
25
|
},
|
|
25
26
|
close() {
|
|
27
|
+
eventLoopPoller?.dispose();
|
|
26
28
|
nativeInstance.close();
|
|
27
29
|
},
|
|
28
30
|
bind(endpoint) {
|
|
29
31
|
nativeInstance.bind(endpoint);
|
|
30
|
-
boundEndpoints.add(endpoint);
|
|
31
32
|
},
|
|
32
33
|
unbind(endpoint) {
|
|
33
34
|
nativeInstance.unbind(endpoint);
|
|
34
|
-
boundEndpoints.delete(endpoint);
|
|
35
35
|
},
|
|
36
36
|
connect(endpoint) {
|
|
37
37
|
nativeInstance.connect(endpoint);
|
|
38
|
-
connectedEndpoints.add(endpoint);
|
|
39
38
|
},
|
|
40
39
|
disconnect(endpoint) {
|
|
41
40
|
nativeInstance.disconnect(endpoint);
|
|
42
|
-
connectedEndpoints.delete(endpoint);
|
|
43
41
|
},
|
|
44
42
|
setChannelName(channelName) {
|
|
45
43
|
const setChannelName = nativeInstance.setChannelName;
|
|
@@ -103,14 +101,12 @@ function wrapSocket(nativeInstance) {
|
|
|
103
101
|
send(...args) {
|
|
104
102
|
if (hasStream) {
|
|
105
103
|
const [routingId, payload] = args;
|
|
106
|
-
peerRoutingIds.add(routingId);
|
|
107
104
|
const operation = nativeInstance.send((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId));
|
|
108
105
|
(0, node_backend_adapter_support_1.submitBindingSyncSend)(operation, payload);
|
|
109
106
|
return true;
|
|
110
107
|
}
|
|
111
108
|
if (hasRoutedPeer) {
|
|
112
109
|
const [routingId, payload] = args;
|
|
113
|
-
peerRoutingIds.add(routingId);
|
|
114
110
|
return (0, node_backend_adapter_support_1.submitBindingAsyncSend)(nativeInstance
|
|
115
111
|
.send((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId)), payload);
|
|
116
112
|
}
|
|
@@ -128,14 +124,12 @@ function wrapSocket(nativeInstance) {
|
|
|
128
124
|
submit(routingId, payload, _timeoutMs) {
|
|
129
125
|
if (!hasStream)
|
|
130
126
|
throw new TypeError('Async stream send requires a STREAM socket.');
|
|
131
|
-
peerRoutingIds.add(routingId);
|
|
132
127
|
return (0, node_backend_adapter_support_1.submitBindingAsyncSend)(nativeInstance
|
|
133
128
|
.send((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId)), payload);
|
|
134
129
|
},
|
|
135
130
|
request(...args) {
|
|
136
131
|
if (hasRoutedPeer) {
|
|
137
132
|
const [routingId, payload, timeoutMs] = args;
|
|
138
|
-
peerRoutingIds.add(routingId);
|
|
139
133
|
return (0, node_backend_adapter_support_1.submitBindingRequest)(nativeInstance
|
|
140
134
|
.request((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId)), payload, timeoutMs);
|
|
141
135
|
}
|
|
@@ -147,7 +141,6 @@ function wrapSocket(nativeInstance) {
|
|
|
147
141
|
},
|
|
148
142
|
reply(...args) {
|
|
149
143
|
const [routingId, replyToken, payload] = args;
|
|
150
|
-
peerRoutingIds.add(routingId);
|
|
151
144
|
const operation = nativeInstance.reply((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId), replyToken);
|
|
152
145
|
return args.length < 3 ? operation : (0, node_backend_adapter_support_1.submitBindingReply)(operation, payload);
|
|
153
146
|
},
|
|
@@ -210,8 +203,17 @@ function wrapSocket(nativeInstance) {
|
|
|
210
203
|
return false;
|
|
211
204
|
}
|
|
212
205
|
};
|
|
206
|
+
if (eventLoopPoller !== undefined)
|
|
207
|
+
eventLoopPollers.set(adapter, eventLoopPoller);
|
|
213
208
|
return adapter;
|
|
214
209
|
}
|
|
210
|
+
function nodeEventLoopPollerOf(socket) {
|
|
211
|
+
const poller = eventLoopPollers.get(socket);
|
|
212
|
+
if (poller === undefined) {
|
|
213
|
+
throw new TypeError('Node backend socket does not own an event-loop poller.');
|
|
214
|
+
}
|
|
215
|
+
return poller;
|
|
216
|
+
}
|
|
215
217
|
function disconnectStreamPeer(socket, routingId) {
|
|
216
218
|
try {
|
|
217
219
|
socket.disconnectRid((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId));
|
|
@@ -229,57 +231,6 @@ function requireSocketOptions(socket) {
|
|
|
229
231
|
}
|
|
230
232
|
return socket.options;
|
|
231
233
|
}
|
|
232
|
-
function closeSocketRoutes(target, peerRoutingIds) {
|
|
233
|
-
if (peerRoutingIds.size === 0 || !hasDisconnectRid(target)) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
for (const routingId of peerRoutingIds) {
|
|
237
|
-
try {
|
|
238
|
-
target.disconnectRid((0, node_backend_adapter_support_1.toNativeRoutingId)(routingId));
|
|
239
|
-
}
|
|
240
|
-
catch (error) {
|
|
241
|
-
if (!isDisconnectRouteNotFoundError(error)) {
|
|
242
|
-
throw error;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
peerRoutingIds.delete(routingId);
|
|
246
|
-
}
|
|
247
|
-
}
|
|
248
|
-
function isDisconnectRouteNotFoundError(error) {
|
|
249
|
-
return (0, node_backend_adapter_support_1.isBindingNotFound)(error) || (0, node_backend_adapter_support_1.isContextTerminatedError)(error) || (error instanceof Error && 'code' in error &&
|
|
250
|
-
(error.code === node_backend_adapter_support_1.zlink.ConnectResult.NotFound ||
|
|
251
|
-
error.code === node_backend_adapter_support_1.zlink.ConnectResult.Busy ||
|
|
252
|
-
(error.code === node_backend_adapter_support_1.zlink.ConnectResult.InternalError &&
|
|
253
|
-
/current state/i.test(error.message))));
|
|
254
|
-
}
|
|
255
|
-
function hasDisconnectRid(target) {
|
|
256
|
-
return target !== null && typeof target === 'object' && 'disconnectRid' in target &&
|
|
257
|
-
typeof target.disconnectRid === 'function';
|
|
258
|
-
}
|
|
259
|
-
function closeSocketEndpoints(target, boundEndpoints, connectedEndpoints) {
|
|
260
|
-
for (const endpoint of connectedEndpoints) {
|
|
261
|
-
try {
|
|
262
|
-
target.disconnect(endpoint);
|
|
263
|
-
}
|
|
264
|
-
catch (error) {
|
|
265
|
-
if (!isEndpointCloseIgnorableError(error)) {
|
|
266
|
-
throw error;
|
|
267
|
-
}
|
|
268
|
-
}
|
|
269
|
-
connectedEndpoints.delete(endpoint);
|
|
270
|
-
}
|
|
271
|
-
for (const endpoint of boundEndpoints) {
|
|
272
|
-
try {
|
|
273
|
-
target.unbind(endpoint);
|
|
274
|
-
}
|
|
275
|
-
catch (error) {
|
|
276
|
-
if (!isEndpointCloseIgnorableError(error)) {
|
|
277
|
-
throw error;
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
boundEndpoints.delete(endpoint);
|
|
281
|
-
}
|
|
282
|
-
}
|
|
283
234
|
function isEndpointCloseIgnorableError(error) {
|
|
284
235
|
return (0, node_backend_adapter_support_1.isContextTerminatedError)(error) || (error instanceof Error && 'code' in error &&
|
|
285
236
|
(error.code === 604 || error.code === node_backend_adapter_support_1.zlink.ConnectResult.NotFound));
|
|
@@ -19,6 +19,7 @@ export interface ZLinkRawMonitorRecord {
|
|
|
19
19
|
readonly flags?: number;
|
|
20
20
|
}
|
|
21
21
|
export interface ZLinkRawSocketPort {
|
|
22
|
+
setReadableHandler(handler: () => void): void;
|
|
22
23
|
bind(endpoint: string): void;
|
|
23
24
|
unbind(endpoint: string): void;
|
|
24
25
|
connect(endpoint: string): void;
|
|
@@ -47,9 +47,13 @@ export declare function isZLinkBackendResultError(error: unknown): error is ZLin
|
|
|
47
47
|
export declare function isBackendNotConnectedError(error: unknown): boolean;
|
|
48
48
|
export declare function isBackendRequestTimeoutError(error: unknown): boolean;
|
|
49
49
|
export type ZLinkBackendMessageLike = Message | Buffer | Uint8Array | string;
|
|
50
|
+
/** Binding의 SendSubmission과 구조적으로 호환된다. binding 타입을 import 하지 않는다. */
|
|
51
|
+
export interface ZLinkBackendSendSubmission {
|
|
52
|
+
readonly admitted: Promise<void>;
|
|
53
|
+
}
|
|
50
54
|
export interface ZLinkBackendSendSubmitBuilder {
|
|
51
55
|
message(message: ZLinkBackendMessageLike): ZLinkBackendSendSubmitBuilder;
|
|
52
|
-
submit():
|
|
56
|
+
submit(): ZLinkBackendSendSubmission;
|
|
53
57
|
}
|
|
54
58
|
export interface ZLinkBackendSendBuilder {
|
|
55
59
|
message(message: ZLinkBackendMessageLike): ZLinkBackendSendSubmitBuilder;
|
|
@@ -33,7 +33,7 @@ class ZLinkChannelRequestDispatcher {
|
|
|
33
33
|
if (received.send === undefined) {
|
|
34
34
|
throw new configuration_1.ZLinkConfigurationException('Routed SPOT packet is missing a local SPOT delivery context.');
|
|
35
35
|
}
|
|
36
|
-
await (0, channel_multipart_1.appendParts)(received.send(), received.parts).submit();
|
|
36
|
+
await (0, channel_multipart_1.appendParts)(received.send(), received.parts).submit().admitted;
|
|
37
37
|
return true;
|
|
38
38
|
}
|
|
39
39
|
if (received.parts.length === 0 || received.parts[0].data().length === 0) {
|
|
@@ -354,7 +354,7 @@ class ZLinkRoutePacketDispatcher {
|
|
|
354
354
|
if (received.send === undefined) {
|
|
355
355
|
throw new configuration_1.ZLinkConfigurationException('Routed SPOT packet is missing a local SPOT delivery context.');
|
|
356
356
|
}
|
|
357
|
-
return (0, channel_multipart_1.appendParts)(received.send(), received.parts).submit();
|
|
357
|
+
return (0, channel_multipart_1.appendParts)(received.send(), received.parts).submit().admitted;
|
|
358
358
|
}
|
|
359
359
|
return false;
|
|
360
360
|
}
|