@aj-shadow/z-abs-corelayer-server 0.0.0-aj-beta.221
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/.gitattributes +26 -0
- package/LICENSE.txt +96 -0
- package/README.md +5 -0
- package/npm-shrinkwrap.json +13 -0
- package/package.json +10 -0
- package/project/server/_build/Server-CoreLayer-server.bld +12 -0
- package/project/server/_build/z-abs-corelayer-server.prj +12 -0
- package/project/server/communication/core-protocol/decoder.js +404 -0
- package/project/server/communication/core-protocol/encoder.js +503 -0
- package/project/server/communication/messages/messages-s-to-c/message-persistent-init-response.js +14 -0
- package/project/server/communication/messages/messages-s-to-c/message-persistent-publish.js +16 -0
- package/project/server/communication/messages/messages-s-to-c/message-ws-init.js +14 -0
- package/project/server/communication/messages/messages-s-to-s/service-init-request.js +17 -0
- package/project/server/communication/messages/messages-s-to-s/service-init-response.js +18 -0
- package/project/server/communication/messages/messages-s-to-s/service-offer-off.js +15 -0
- package/project/server/communication/messages/messages-s-to-s/service-offer-on.js +15 -0
- package/project/server/communication/messages/messages-s-to-s/worker-init-request.js +15 -0
- package/project/server/data-response.js +588 -0
- package/project/server/high-resolution-timestamp.js +36 -0
- package/project/server/log/log-config.js +107 -0
- package/project/server/log/log-types.js +14 -0
- package/project/server/log/logger-console.js +36 -0
- package/project/server/log/logger.js +114 -0
- package/project/server/node/channel-input.js +65 -0
- package/project/server/node/channel-output.js +39 -0
- package/project/server/node/clients.js +80 -0
- package/project/server/node/connection-address.js +24 -0
- package/project/server/node/connection-data-ip.js +82 -0
- package/project/server/node/connection-data.js +25 -0
- package/project/server/node/const.js +44 -0
- package/project/server/node/external-services.js +209 -0
- package/project/server/node/http-cache.js +109 -0
- package/project/server/node/http-proxy.js +97 -0
- package/project/server/node/http-request-handler.js +219 -0
- package/project/server/node/http-server.js +36 -0
- package/project/server/node/http2-server.js +67 -0
- package/project/server/node/https-server.js +63 -0
- package/project/server/node/ip-client.js +98 -0
- package/project/server/node/ip-server.js +63 -0
- package/project/server/node/ip-subscription.js +46 -0
- package/project/server/node/message-channel.js +98 -0
- package/project/server/node/node-admin.js +513 -0
- package/project/server/node/node-data.js +25 -0
- package/project/server/node/node-settings.js +352 -0
- package/project/server/node/node-worker.js +76 -0
- package/project/server/node/node.js +156 -0
- package/project/server/node/servers.js +168 -0
- package/project/server/node/ws-client.js +12 -0
- package/project/server/node/ws-server.js +20 -0
- package/project/server/node/ws-web-server.js +52 -0
- package/project/server/node/wss-server.js +20 -0
- package/project/server/node/wss-web-server.js +82 -0
- package/project/server/path/actor-path-build.js +29 -0
- package/project/server/path/actor-path-content.js +51 -0
- package/project/server/path/actor-path-creator.js +90 -0
- package/project/server/path/actor-path-data.js +487 -0
- package/project/server/path/actor-path-dist.js +132 -0
- package/project/server/path/actor-path-generated.js +202 -0
- package/project/server/path/actor-path-project.js +181 -0
- package/project/server/path/actor-path.js +57 -0
- package/project/server/path/paths/actor-content-paths.js +34 -0
- package/project/server/path/paths/actor-data-paths.js +302 -0
- package/project/server/path/paths/actor-generated-paths.js +99 -0
- package/project/server/path/paths/actor-paths.js +22 -0
- package/project/server/plugin-base-multi.js +484 -0
- package/project/server/plugin-base.js +233 -0
- package/project/server/plugin-component.js +92 -0
- package/project/server/plugin-data/client/plugin_data_ClientGet.js +18 -0
- package/project/server/plugin-data/dialog-file/plugin_data_DialogFileGet.js +197 -0
- package/project/server/plugin-data/platform/plugin_data_PlatformPing.js +19 -0
- package/project/server/plugin-factor-protocol.js +35 -0
- package/project/server/plugin-factory.js +127 -0
- package/project/server/plugin-lock.js +164 -0
- package/project/server/response-queue.js +46 -0
- package/project/server/responses.js +20 -0
- package/project/server/service/plugin-service.js +264 -0
- package/project/server/service/service-export.js +47 -0
- package/project/server/service/service-manager.js +270 -0
- package/project/server/service/service-requests.js +49 -0
- package/project/server/session-cache.js +39 -0
- package/project/server/session.js +23 -0
- package/project/server/worker/worker-channel.js +175 -0
- package/project/server/worker/worker-core.js +58 -0
- package/project/server/worker/worker-main.js +165 -0
- package/project/server/worker/worker-pool.js +94 -0
- package/project/server/worker/worker-thread.js +128 -0
- package/project/z-abs-corelayer-server.tree +99 -0
|
@@ -0,0 +1,588 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
const ResponseQueue = require('./response-queue');
|
|
5
|
+
const PluginFactory = require('./plugin-factory');
|
|
6
|
+
const Session = require('./session');
|
|
7
|
+
const SessionCache = require('./session-cache');
|
|
8
|
+
const ActorPathDist = require('./path/actor-path-dist');
|
|
9
|
+
const Logger = require('./log/logger');
|
|
10
|
+
const Decoder = require('./communication/core-protocol/decoder');
|
|
11
|
+
const Encoder = require('./communication/core-protocol/encoder');
|
|
12
|
+
const MessagePersistentInitResponse = require('./communication/messages/messages-s-to-c/message-persistent-init-response');
|
|
13
|
+
const MessagePersistentPublish = require('./communication/messages/messages-s-to-c/message-persistent-publish');
|
|
14
|
+
const ConnectionData = require('./node/connection-data');
|
|
15
|
+
const ConnectionDataIp = require('./node/connection-data-ip');
|
|
16
|
+
const IpSubscription = require('z-abs-corelayer-server/server/node/ip-subscription');
|
|
17
|
+
const ServiceInitRequest = require('./communication/messages/messages-s-to-s/service-init-request');
|
|
18
|
+
const ServiceInitResponse = require('./communication/messages/messages-s-to-s/service-init-response');
|
|
19
|
+
const ServiceOfferOn = require('./communication/messages/messages-s-to-s/service-offer-on');
|
|
20
|
+
const ServiceOfferOff = require('./communication/messages/messages-s-to-s/service-offer-off');
|
|
21
|
+
const Const = require('./node/const');
|
|
22
|
+
const ServiceExport = require('./service/service-export');
|
|
23
|
+
const ServiceManager = require('./service/service-manager');const Envelope = require('z-abs-corelayer-cs/clientServer/communication/core-protocol/envelope');
|
|
24
|
+
const CoreProtocolConst = require('z-abs-corelayer-cs/clientServer/communication/core-protocol/core-protocol-const');
|
|
25
|
+
const ChildProcess = require('child_process');
|
|
26
|
+
const Path = require('path');
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
class DataResponse {
|
|
30
|
+
static connectionId = 0;
|
|
31
|
+
static basePath = './dist/Layers/z-abs-corelayer-server';
|
|
32
|
+
static PROCESS_STATUS_NOT_RUNNING = 0;
|
|
33
|
+
static PROCESS_STATUS_RUNNING = 1;
|
|
34
|
+
static PROCESS_STATUS_CLOSING = 2;
|
|
35
|
+
static _ = {serverDatas: null};
|
|
36
|
+
|
|
37
|
+
constructor(nodeName, nodeId, nodeType, node, externalServices) {
|
|
38
|
+
this.nodeName = nodeName;
|
|
39
|
+
this.nodeId = nodeId;
|
|
40
|
+
this.nodeType = nodeType;
|
|
41
|
+
this.node = node;
|
|
42
|
+
this.externalServices = externalServices;
|
|
43
|
+
this.ipSubscription = new IpSubscription();
|
|
44
|
+
this.sessionCache = new SessionCache();
|
|
45
|
+
this.pluginDataParams = [this];
|
|
46
|
+
this.pluginDataFactory = new PluginFactory('data', this.pluginDataParams);
|
|
47
|
+
this.serviceManager = new ServiceManager(this);
|
|
48
|
+
this.persistenServiceSubscriptions = new Map();
|
|
49
|
+
this.webServerConnectionDatas = new Map();
|
|
50
|
+
this.persistentWsMessageQueue = new Map();
|
|
51
|
+
this.workers = new Map();
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
init(pluginDatas, pluginServices, pluginComponents, serverDatas, workers, done) {
|
|
55
|
+
this.workers = workers;
|
|
56
|
+
DataResponse._.serverDatas = serverDatas;
|
|
57
|
+
this.pluginDataFactory.setPaths(pluginDatas);
|
|
58
|
+
let pendings = 2;
|
|
59
|
+
this.pluginDataFactory.load((size) => {
|
|
60
|
+
ddb.writelnTime(ddb.yellowBright('Loaded: '), ddb.yellow(size), ' ', ddb.greenBright('data plugins from:'.padEnd(23 - size.toString().length)), pluginDatas.join(', '));
|
|
61
|
+
if(0 === --pendings) {
|
|
62
|
+
done();
|
|
63
|
+
}
|
|
64
|
+
}, ActorPathDist.getActorDistServerPluginDataPath());
|
|
65
|
+
this.serviceManager.init(pluginComponents, pluginServices, () => {
|
|
66
|
+
if(0 === --pendings) {
|
|
67
|
+
done();
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getNode() {
|
|
73
|
+
return this.node;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
startServices(cb) {
|
|
77
|
+
this.serviceManager.startServices(cb);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
stopServices(hasException, cb) {
|
|
81
|
+
this.serviceManager.stopServices(hasException, cb);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
getService(name) {
|
|
85
|
+
return this.serviceManager.getService(name);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
onConnectionConnected(connectionType, cbMessage) {
|
|
89
|
+
if(Const.CONNECTION_TYPE_SERVER_IP === connectionType || Const.CONNECTION_TYPE_CLIENT_IP === connectionType) {
|
|
90
|
+
return new ConnectionDataIp(`NODE-${DataResponse.connectionId}-CLIENT-IN`, `NODE-${DataResponse.connectionId}-CLIENT-OUT`, cbMessage);
|
|
91
|
+
}
|
|
92
|
+
else if(Const.CONNECTION_TYPE_SERVER_WEB === connectionType) {
|
|
93
|
+
const connectionData = new ConnectionData(`NODE-${DataResponse.connectionId}-CLIENT-IN`, `NODE-${DataResponse.connectionId}-CLIENT-OUT`, cbMessage);
|
|
94
|
+
this.webServerConnectionDatas.set(connectionData.id, {
|
|
95
|
+
connectionData,
|
|
96
|
+
persistenServiceSubscriptions: []
|
|
97
|
+
});
|
|
98
|
+
return connectionData;
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
ddb.error('Unknown connectionType:', connectionType);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
onConnectionClose(connectionType, connectionData) {
|
|
106
|
+
if(Const.CONNECTION_TYPE_SERVER_WEB === connectionType) {
|
|
107
|
+
const webServerConnectionData = this.webServerConnectionDatas.get(connectionData.id);
|
|
108
|
+
const persistenServiceSubscriptions = webServerConnectionData.persistenServiceSubscriptions;
|
|
109
|
+
persistenServiceSubscriptions.forEach((persistenServiceSubscription) => {
|
|
110
|
+
this.persistenServiceSubscriptions.delete(persistenServiceSubscription);
|
|
111
|
+
});
|
|
112
|
+
this.webServerConnectionDatas.delete(connectionData.id);
|
|
113
|
+
}
|
|
114
|
+
if(Const.CONNECTION_TYPE_SERVER_IP === connectionType || Const.CONNECTION_TYPE_CLIENT_IP === connectionType) {
|
|
115
|
+
this.externalServices.deleteNode(connectionData, connectionData.nodeType);
|
|
116
|
+
const offerData = this.externalServices.getOfferData(connectionData.nodeName, connectionData.nodeSymbol);
|
|
117
|
+
this.sendOfferOff(offerData, connectionData);
|
|
118
|
+
this.ipSubscription.event(Const.EVENT_TYPE_CONNECTION, connectionData.name, Const.IP_EVENT_DISCONNECTED, connectionData.connectionAddress);
|
|
119
|
+
}
|
|
120
|
+
process.nextTick((connectionDataSessionCache) => {
|
|
121
|
+
connectionDataSessionCache.forEach((connectionDataSession) => {
|
|
122
|
+
let pendings = connectionDataSession.dataPluginsInternal.length;
|
|
123
|
+
connectionDataSession.dataPluginsInternal.forEach((dataPlugin) => {
|
|
124
|
+
dataPlugin.handleClose((err) => {
|
|
125
|
+
process.nextTick((pendings, connectionDataSession) => {
|
|
126
|
+
if(0 === --pendings) {
|
|
127
|
+
this.clearSession(connectionDataSession.sessionId, (code) => {
|
|
128
|
+
LOG_ENGINE(Logger.ENGINE.MSG, `CLOSE sessionId: ${connectionDataSession.sessionId} code = ${code}`);
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}, pendings, connectionDataSession);
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
}, connectionData.sessionCache);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
onMessage(data, connectionData) {
|
|
139
|
+
connectionData.channelInput.onNewMessage(data, true, (coreMessage) => {
|
|
140
|
+
if(!coreMessage) {
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
else if(!coreMessage.msg) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
if(CoreProtocolConst.APP <= coreMessage.msgId) {
|
|
147
|
+
const session = this.sessionCache.getSession(coreMessage.msg.sessionId);
|
|
148
|
+
if(session) {
|
|
149
|
+
session.dataPluginsInternal.forEach((dataPlugin) => {
|
|
150
|
+
dataPlugin.handleMessageFromClient(coreMessage.msg);
|
|
151
|
+
});
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
else if(CoreProtocolConst.REQUEST === coreMessage.msgId) {
|
|
155
|
+
let routes = null;
|
|
156
|
+
if(coreMessage.isServiceAction) {
|
|
157
|
+
coreMessage.envelope.createRouteEnvelope();
|
|
158
|
+
routes = coreMessage.envelope.routes;
|
|
159
|
+
}
|
|
160
|
+
this.handleRequests(coreMessage.msg, null, routes, (response, dataBuffers, debug, token) => {
|
|
161
|
+
if(coreMessage.isServiceAction) {
|
|
162
|
+
response.isServiceAction = true;
|
|
163
|
+
}
|
|
164
|
+
connectionData.channelOutput.send(response, dataBuffers, debug, coreMessage.envelope);
|
|
165
|
+
}, (msg, dataBuffers, debug, sessionId) => {
|
|
166
|
+
const session = this.sessionCache.getSession(sessionId);
|
|
167
|
+
if(session) {
|
|
168
|
+
let proxy = false;
|
|
169
|
+
session.dataPluginsInternal.forEach((dataPlugin) => {
|
|
170
|
+
if(dataPlugin.handleMessageToClient(msg, dataBuffers, (msgHandled, dataBuffersHandled) => {
|
|
171
|
+
connectionData.channelOutput.send(msgHandled, dataBuffersHandled, debug, coreMessage.envelope);
|
|
172
|
+
})) {
|
|
173
|
+
proxy = true;
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
if(!proxy) {
|
|
177
|
+
connectionData.channelOutput.send(msg, dataBuffers, debug, coreMessage.envelope);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}, connectionData);
|
|
181
|
+
}
|
|
182
|
+
else if(CoreProtocolConst.RESPONSE === coreMessage.msgId) {
|
|
183
|
+
if(!coreMessage.isServiceAction) {
|
|
184
|
+
ddb.error('DROPPED ServiceAction response, got a response that is not an ServiceAction: ', coreMessage);
|
|
185
|
+
}
|
|
186
|
+
else {
|
|
187
|
+
const envelope = coreMessage.envelope;
|
|
188
|
+
const requestData = this.serviceManager.popRequest(envelope.serviceName, envelope.shiftRoute());
|
|
189
|
+
if(requestData) {
|
|
190
|
+
requestData.pluginService.receiveResponseFromService(requestData.requestId, requestData.sessionId, coreMessage.envelope.serviceName, coreMessage.msg.responses, requestData.cb);
|
|
191
|
+
}
|
|
192
|
+
else {
|
|
193
|
+
ddb.error('DROPPED ServiceAction response, could not find request: ', coreMessage);
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
else if(CoreProtocolConst.SERVICE_INIT_REQUEST === coreMessage.msgId) {
|
|
198
|
+
connectionData.setServiceInit(coreMessage.msg.nodeName, coreMessage.msg.nodeId, coreMessage.msg.nodeType);
|
|
199
|
+
this.externalServices.addNode(connectionData);
|
|
200
|
+
const offerData = this.externalServices.getOfferData(connectionData.nodeName, connectionData.nodeSymbol);
|
|
201
|
+
if(this.sendOfferOn(offerData, connectionData, false)) {
|
|
202
|
+
const nodeData = this.externalServices.getNodeData(connectionData);
|
|
203
|
+
const serviceExport = this.serviceManager.getServiceExport(this.nodeType, connectionData.nodeType);
|
|
204
|
+
connectionData.channelOutput.send(new ServiceInitResponse(this.nodeName, this.nodeId, this.nodeType, serviceExport), null, false, null);
|
|
205
|
+
nodeData.offered = true;
|
|
206
|
+
nodeData.serviceExport = serviceExport;
|
|
207
|
+
}
|
|
208
|
+
else {
|
|
209
|
+
connectionData.channelOutput.send(new ServiceInitResponse(this.nodeName, this.nodeId, this.nodeType, ServiceExport.EMPTY), null, false, null);
|
|
210
|
+
}
|
|
211
|
+
this.ipSubscription.event(Const.EVENT_TYPE_CONNECTION, connectionData.name, Const.IP_EVENT_CONNECTED, connectionData);
|
|
212
|
+
}
|
|
213
|
+
else if(CoreProtocolConst.SERVICE_INIT_RESPONSE === coreMessage.msgId) {
|
|
214
|
+
connectionData.setServiceInit(coreMessage.msg.nodeName, coreMessage.msg.nodeId, coreMessage.msg.nodeType);
|
|
215
|
+
this.externalServices.offerOn(connectionData, coreMessage.msg.serviceExport);
|
|
216
|
+
this.externalServices.addNode(connectionData);
|
|
217
|
+
const offerData = this.externalServices.getOfferData(connectionData.nodeName, connectionData.nodeSymbol);
|
|
218
|
+
this.sendOfferOn(offerData, connectionData, true);
|
|
219
|
+
this.ipSubscription.event(Const.EVENT_TYPE_CONNECTION, connectionData.name, Const.IP_EVENT_CONNECTED, connectionData);
|
|
220
|
+
|
|
221
|
+
}
|
|
222
|
+
else if(CoreProtocolConst.SERVICE_OFFER_ON === coreMessage.msgId) {
|
|
223
|
+
this.externalServices.offerOn(connectionData, coreMessage.msg.serviceExport);
|
|
224
|
+
const offerData = this.externalServices.getOfferData(connectionData.nodeName, connectionData.nodeSymbol);
|
|
225
|
+
this.sendOfferOn(offerData, connectionData, true);
|
|
226
|
+
}
|
|
227
|
+
else if(CoreProtocolConst.SERVICE_OFFER_OFF === coreMessage.msgId) {
|
|
228
|
+
this.externalServices.offerOff(connectionData, coreMessage.msg.serviceExport);
|
|
229
|
+
const offerData = this.externalServices.getOfferData(connectionData.nodeName, connectionData.nodeSymbol);
|
|
230
|
+
this.sendOfferOff(offerData, connectionData);
|
|
231
|
+
}
|
|
232
|
+
else if(CoreProtocolConst.PERSISTENT_INIT_REQUEST === coreMessage.msgId) {
|
|
233
|
+
const name = coreMessage.msg.name;
|
|
234
|
+
const subscribeServices = coreMessage.msg.subscribeServices;
|
|
235
|
+
connectionData.persistantName = name;
|
|
236
|
+
const webServerConnectionData = this.webServerConnectionDatas.get(connectionData.id);
|
|
237
|
+
subscribeServices.forEach((subscribeService) => {
|
|
238
|
+
webServerConnectionData.persistenServiceSubscriptions.push(subscribeService);
|
|
239
|
+
this.serviceManager.subscripeOnLocalService(subscribeService);
|
|
240
|
+
if(!this.persistenServiceSubscriptions.has(subscribeService)) {
|
|
241
|
+
this.persistenServiceSubscriptions.set(subscribeService, [{
|
|
242
|
+
name: name,
|
|
243
|
+
connectionData: connectionData
|
|
244
|
+
}]);
|
|
245
|
+
}
|
|
246
|
+
else {
|
|
247
|
+
this.persistenServiceSubscriptions.get(subscribeService).push({
|
|
248
|
+
name: name,
|
|
249
|
+
connectionData: connectionData
|
|
250
|
+
});
|
|
251
|
+
}
|
|
252
|
+
});
|
|
253
|
+
webServerConnectionData.
|
|
254
|
+
connectionData.channelOutput.send(new MessagePersistentInitResponse(), null, false, null);
|
|
255
|
+
}
|
|
256
|
+
else {
|
|
257
|
+
ddb.error('DROPPED: ', coreMessage);
|
|
258
|
+
}
|
|
259
|
+
});
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
sendServiceInitRequest(connectionData) {
|
|
263
|
+
connectionData.channelOutput.send(new ServiceInitRequest(this.nodeName, this.nodeId, this.nodeType), null, false, null);
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
sendOfferOn(offerData, connectionData, shallSendToOrigin) {
|
|
267
|
+
if(offerData.offer) {
|
|
268
|
+
if(!offerData.isDependent) {
|
|
269
|
+
if(shallSendToOrigin) {
|
|
270
|
+
const nodeData = this.externalServices.getNodeData(connectionData);
|
|
271
|
+
if(!nodeData.offered) {
|
|
272
|
+
const serviceExport = this.serviceManager.getServiceExport(this.nodeType, connectionData.nodeType);
|
|
273
|
+
serviceExport.printOfferOn(offerData, connectionData.nodeName, connectionData.nodeId);
|
|
274
|
+
connectionData.channelOutput.send(new ServiceOfferOn(serviceExport), null, false, null);
|
|
275
|
+
nodeData.offered = true;
|
|
276
|
+
nodeData.serviceExport = serviceExport;
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
else {
|
|
281
|
+
this.externalServices.nodes.forEach((node) => {
|
|
282
|
+
if(shallSendToOrigin || connectionData.nodeSymbol !== node.nodeSymbol) {
|
|
283
|
+
const nodeData = this.externalServices.getNodeData(node);
|
|
284
|
+
if(!nodeData.offered && offerData.isDependent) {
|
|
285
|
+
const serviceExport = this.serviceManager.getServiceExport(this.nodeType, node.nodeType);
|
|
286
|
+
serviceExport.printOfferOn(offerData, node.nodeName, node.nodeId);
|
|
287
|
+
node.connectionData.channelOutput.send(new ServiceOfferOn(serviceExport), null, false, null);
|
|
288
|
+
nodeData.offered = true;
|
|
289
|
+
nodeData.serviceExport = serviceExport;
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
});
|
|
293
|
+
}
|
|
294
|
+
return true;
|
|
295
|
+
}
|
|
296
|
+
else {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
sendOfferOff(offerData, connectionData) {
|
|
302
|
+
if(!offerData.offer) {
|
|
303
|
+
if(!offerData.isDependent) {
|
|
304
|
+
const nodeData = this.externalServices.getNodeData(connectionData);
|
|
305
|
+
if(nodeData.offered) {
|
|
306
|
+
nodeData.serviceExport.printOfferOff(offerData, connectionData.nodeName, connectionData.nodeId);
|
|
307
|
+
connectionData.channelOutput.send(new ServiceOfferOff(nodeData.serviceExport), null, false, null);
|
|
308
|
+
nodeData.offered = false;
|
|
309
|
+
nodeData.serviceExport = null;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
else {
|
|
313
|
+
this.externalServices.nodes.forEach((node) => {
|
|
314
|
+
const nodeData = this.externalServices.getNodeData(node);
|
|
315
|
+
if(nodeData.offered && offerData.isDependent) {
|
|
316
|
+
nodeData.serviceExport.printOfferOff(offerData, node.nodeName, node.nodeId);
|
|
317
|
+
node.connectionData.channelOutput.send(new ServiceOfferOff(nodeData.serviceExport), null, false, null);
|
|
318
|
+
nodeData.offered = false;
|
|
319
|
+
nodeData.serviceExport = null;
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
sendMessageToPersistentStore(message, storeName) {
|
|
327
|
+
/*const connectionData = this.persistentWsConnections.get(storeName);
|
|
328
|
+
if(connectionData) {
|
|
329
|
+
cbMessage(message);
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
else {
|
|
333
|
+
if(this.persistentWsMessageQueue.has(storeName)) {
|
|
334
|
+
const queue = this.persistentWsMessageQueue.get(storeName);
|
|
335
|
+
queue.push(message);
|
|
336
|
+
}
|
|
337
|
+
else {
|
|
338
|
+
this.persistentWsMessageQueue.set(storeName, [message]);
|
|
339
|
+
}
|
|
340
|
+
return false;
|
|
341
|
+
}*/
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
forkWorkerProcess(name, sessionId, pluginPaths, debug, execArgv, done) {
|
|
345
|
+
const workerData = this.workers.get(name);
|
|
346
|
+
const protocols = workerData?.worker.protocols?.server ? workerData.worker.protocols.server : '[]';
|
|
347
|
+
const protocolsJson = JSON.stringify(protocols);
|
|
348
|
+
const pluginPathsJson = Array.isArray(pluginPaths) ? (JSON.stringify(pluginPaths)) : (pluginPaths ? (JSON.stringify([pluginPaths])) : '[]');
|
|
349
|
+
const workerProcess = ChildProcess.fork(`${name}.js`, [Reflect.get(global, 'dynamicConfigStringified@actorjs_global'), ActorPathDist.getActorDistServerPluginDataPath(), pluginPathsJson, protocolsJson, ...execArgv], {execArgv: [], silent: false, stdio: ['ignore', 'inherit', 'ignore', 'ipc']});
|
|
350
|
+
const session = this.sessionCache.getSession(sessionId);
|
|
351
|
+
session.workerProcess = {
|
|
352
|
+
process: workerProcess,
|
|
353
|
+
connectionData: new ConnectionData(`NODE-${DataResponse.connectionId}-WORKER-IN`, `NODE-${DataResponse.connectionId}-WORKER-OUT`, workerProcess.send.bind(workerProcess))
|
|
354
|
+
};
|
|
355
|
+
pluginPaths.forEach((pluginPath) => {
|
|
356
|
+
session.dataPluginsExternal.push(Path.parse(pluginPath).base);
|
|
357
|
+
});
|
|
358
|
+
const channelInput = session.workerProcess.connectionData.channelInput;
|
|
359
|
+
const channelOutput = session.workerProcess.connectionData.channelOutput;
|
|
360
|
+
if(workerData) {
|
|
361
|
+
workerData.pluginFactoryProtocol.register(channelInput, channelOutput);
|
|
362
|
+
}
|
|
363
|
+
workerProcess.on('message', (msg) => {
|
|
364
|
+
const data = Buffer.from(msg.data);
|
|
365
|
+
channelInput.onNewMessage(data, true, (coreMessage) => {
|
|
366
|
+
if(!coreMessage) {
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
else if(!coreMessage.msg) {
|
|
370
|
+
ddb.error('NODE-WORKER-IN dropped message, msgid: ', coreMessage.msgId);
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
if(CoreProtocolConst.APP <= coreMessage.msgId) {
|
|
374
|
+
const recordRoute = coreMessage.envelope.recordRoutes.pop();
|
|
375
|
+
const cbs = session.requests.get(recordRoute);
|
|
376
|
+
let proxy = false;
|
|
377
|
+
session.dataPluginsInternal.forEach((dataPlugin) => {
|
|
378
|
+
proxy |= dataPlugin.handleMessageFromWorker(coreMessage.msg, coreMessage.dataBuffers, debug, cbs.cbMessage);
|
|
379
|
+
});
|
|
380
|
+
if(!proxy) {
|
|
381
|
+
cbs.cbMessage(coreMessage.msg, coreMessage.dataBuffers, debug);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
else if(CoreProtocolConst.RESPONSE === coreMessage.msgId) {
|
|
385
|
+
const cbs = session.requests.get(coreMessage.msg.id);
|
|
386
|
+
cbs.cb(coreMessage.msg);
|
|
387
|
+
cbs.cb = null;
|
|
388
|
+
}
|
|
389
|
+
else if(CoreProtocolConst.WORKER_INIT_REQUEST === coreMessage.msgId) {
|
|
390
|
+
session.processStatus = DataResponse.PROCESS_STATUS_RUNNING;
|
|
391
|
+
done(workerProcess.pid, coreMessage.msg.sessionData);
|
|
392
|
+
}
|
|
393
|
+
});
|
|
394
|
+
});
|
|
395
|
+
workerProcess.on('exit', (code) => {
|
|
396
|
+
session.process = undefined;
|
|
397
|
+
session.processStatus = DataResponse.PROCESS_STATUS_NOT_RUNNING;
|
|
398
|
+
});
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
killWorkerProcess(sessionId, done) {
|
|
402
|
+
const session = this.sessionCache.getSession(sessionId);
|
|
403
|
+
if(session && DataResponse.PROCESS_STATUS_RUNNING === session.processStatus) {
|
|
404
|
+
session.workerProcess.process.on('exit', (code) => {
|
|
405
|
+
session.process = undefined;
|
|
406
|
+
session.processStatus = DataResponse.PROCESS_STATUS_NOT_RUNNING;
|
|
407
|
+
done(code);
|
|
408
|
+
});
|
|
409
|
+
session.processStatus = DataResponse.PROCESS_STATUS_CLOSING;
|
|
410
|
+
session.workerProcess.process.kill();
|
|
411
|
+
}
|
|
412
|
+
else {
|
|
413
|
+
done(-1);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
clearSession(sessionId, done) {
|
|
418
|
+
const session = this.sessionCache.getSession(sessionId);
|
|
419
|
+
if(session) {
|
|
420
|
+
this.killWorkerProcess(sessionId, (code) => {
|
|
421
|
+
session.connectionDataSessionCache.delete(sessionId);
|
|
422
|
+
this.sessionCache.deleteSession(sessionId);
|
|
423
|
+
done && done(code);
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
|
|
428
|
+
sendRequestToWorkerProcess(session, id, request, cb, cbMessage, cbProxyMessage) {
|
|
429
|
+
session.requests.set(id, {
|
|
430
|
+
cb: cb,
|
|
431
|
+
cbMessage: cbMessage,
|
|
432
|
+
cbProxyMessage: cbProxyMessage
|
|
433
|
+
});
|
|
434
|
+
session.workerProcess.connectionData.channelOutput.send(request, null, true, new Envelope(null, id));
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
sendMessageToWorkerProcess(session, msg) {
|
|
438
|
+
session.workerProcess.connectionData.channelOutput.send(msg, null, true, null);
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
_createDataPlugin(name, done) {
|
|
442
|
+
let dataPlugin = this.pluginDataFactory.create(name);
|
|
443
|
+
if(dataPlugin) {
|
|
444
|
+
process.nextTick(done, dataPlugin);
|
|
445
|
+
}
|
|
446
|
+
else {
|
|
447
|
+
this.pluginDataFactory.load(() => {
|
|
448
|
+
dataPlugin = this.pluginDataFactory.create(name);
|
|
449
|
+
done(dataPlugin);
|
|
450
|
+
}, ActorPathDist.getActorDistServerPluginDataPath());
|
|
451
|
+
}
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
_handleRequestLocal(request, dataPlugin, queue, cbMessage) {
|
|
455
|
+
try {
|
|
456
|
+
dataPlugin.handleRequest(request, (response) => {
|
|
457
|
+
if(dataPlugin.tokenOut) {
|
|
458
|
+
queue.setToken(dataPlugin.tokenOut);
|
|
459
|
+
}
|
|
460
|
+
queue.done(response);
|
|
461
|
+
}, cbMessage);
|
|
462
|
+
}
|
|
463
|
+
catch(err) {
|
|
464
|
+
LOG_ERROR(Logger.ERROR.CATCH, `Data Plugin exception: '${request.name}'. Message: ${err}`, err);
|
|
465
|
+
queue.done({name: request.name, index: request.index, result: { code: 'error', msg: 'Data Plugin exception: ' + request.name }});
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
publish(dataPluginName, subscriptionName, cb, ...params) {
|
|
470
|
+
this._createDataPlugin(dataPluginName, (dataPlugin) => {
|
|
471
|
+
try {
|
|
472
|
+
dataPlugin.handleRequest({
|
|
473
|
+
index: 0,
|
|
474
|
+
sessionId: null,
|
|
475
|
+
params: params
|
|
476
|
+
}, (response) => {
|
|
477
|
+
const subscriptions = this.persistenServiceSubscriptions.get(subscriptionName);
|
|
478
|
+
if(subscriptions) {
|
|
479
|
+
subscriptions.forEach((subscription) => {
|
|
480
|
+
subscription.connectionData.channelOutput.send(new MessagePersistentPublish(subscription.name, response), null, false, null);
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
}, null);
|
|
484
|
+
}
|
|
485
|
+
catch(err) {
|
|
486
|
+
cb(err);
|
|
487
|
+
}
|
|
488
|
+
});
|
|
489
|
+
}
|
|
490
|
+
|
|
491
|
+
handleRequests(rawRequest, token, routes, cbRequest, cbMessage, connectionData) {
|
|
492
|
+
const queue = new ResponseQueue((responses, cb, token) => {
|
|
493
|
+
cb(responses, token);
|
|
494
|
+
}, (result, token) => {
|
|
495
|
+
cbRequest(result, null, false, token);
|
|
496
|
+
}, rawRequest.id);
|
|
497
|
+
rawRequest.requests.forEach((request) => {
|
|
498
|
+
queue.add();
|
|
499
|
+
this._createDataPlugin(request.name, (dataPlugin) => {
|
|
500
|
+
if(!dataPlugin) {
|
|
501
|
+
LOG_ERROR(Logger.ERROR.ERR, `Unknown Data Plugin: ${request.name}.`, undefined);
|
|
502
|
+
queue.done({name: request.name, index: request.index, result: { code: 'error', msg: 'Unknown Data Plugin: ' + request.name }});
|
|
503
|
+
return;
|
|
504
|
+
}
|
|
505
|
+
else {
|
|
506
|
+
dataPlugin.setTokenIn(token);
|
|
507
|
+
if(!request.sessionId) {
|
|
508
|
+
if(0 !== dataPlugin.authorization.length) {
|
|
509
|
+
let authorization = null;
|
|
510
|
+
const configService = this.getService('config');
|
|
511
|
+
if(configService) {
|
|
512
|
+
const configAuthorization = configService.getConfig('authorization', 'server');
|
|
513
|
+
ddb.writelnTime('Config.Authorization', configAuthorization);
|
|
514
|
+
if(configAuthorization) {
|
|
515
|
+
const userService = this.getService('user');
|
|
516
|
+
if(userService) {
|
|
517
|
+
authorization = userService.getAuthorization(token);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
}
|
|
521
|
+
if(!authorization || -1 === dataPlugin.authorization.indexOf(authorization)) {
|
|
522
|
+
queue.done({name: request.name, index: request.index, result: { code: 'error', msg: 'Not Authorized: ' + request.name }});
|
|
523
|
+
return;
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
this._handleRequestLocal(request, dataPlugin, queue, (msg, dataBuffers, debug) => {
|
|
527
|
+
cbMessage(msg, dataBuffers, debug, request.sessionId);
|
|
528
|
+
});
|
|
529
|
+
}
|
|
530
|
+
else {
|
|
531
|
+
let session = this.sessionCache.getSession(request.sessionId);
|
|
532
|
+
if(!session)
|
|
533
|
+
{
|
|
534
|
+
session = this.sessionCache.createSession(request.sessionId, connectionData);
|
|
535
|
+
if(routes) {
|
|
536
|
+
session.routes = routes;
|
|
537
|
+
}
|
|
538
|
+
if(connectionData.sessionCache) {
|
|
539
|
+
connectionData.sessionCache.set(request.sessionId, session);
|
|
540
|
+
}
|
|
541
|
+
}
|
|
542
|
+
const externalFound = session.dataPluginsExternal.find((dataPlugin) => {
|
|
543
|
+
return dataPlugin.dataName;
|
|
544
|
+
});
|
|
545
|
+
if(externalFound) {
|
|
546
|
+
this.sendRequestToWorkerProcess(session, dataPlugin.instanceId, request, (response) => {
|
|
547
|
+
queue.done(response);
|
|
548
|
+
}, (msg, dataBuffers, debug) => {
|
|
549
|
+
cbMessage(msg, dataBuffers, debug, request.sessionId);
|
|
550
|
+
});
|
|
551
|
+
}
|
|
552
|
+
else {
|
|
553
|
+
session.dataPluginsInternal.push(dataPlugin);
|
|
554
|
+
this._handleRequestLocal(request, dataPlugin, queue, (msg, dataBuffers, debug) => {
|
|
555
|
+
cbMessage(msg, dataBuffers, debug, request.sessionId);
|
|
556
|
+
});
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
});
|
|
562
|
+
}
|
|
563
|
+
|
|
564
|
+
_handleRest(method, url, contentType, body, token, cbResult) {
|
|
565
|
+
const restApiService = this.getService('rest-api');
|
|
566
|
+
if(restApiService) {
|
|
567
|
+
restApiService.request(method, url, contentType, body, token, cbResult);
|
|
568
|
+
}
|
|
569
|
+
else {
|
|
570
|
+
process.nextTick(cbResult, 501, 'Not Implemented', null, null);
|
|
571
|
+
}
|
|
572
|
+
}
|
|
573
|
+
|
|
574
|
+
_logParameters(parameters) {
|
|
575
|
+
let logParameters = parameters.map((parameter) => {
|
|
576
|
+
if(typeof parameter === 'string') {
|
|
577
|
+
return `'${parameter.replace(/\r/g, '\\r').replace(/\n/g, '\\n')}'`;
|
|
578
|
+
}
|
|
579
|
+
else {
|
|
580
|
+
return `${parameter}`;
|
|
581
|
+
}
|
|
582
|
+
});
|
|
583
|
+
return logParameters.join(', ');
|
|
584
|
+
}
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
|
|
588
|
+
module.exports = DataResponse;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
require('z-abs-corelayer-cs/clientServer/debug-dashboard/log');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class HighResolutionTimestamp {
|
|
8
|
+
static date = new Date();
|
|
9
|
+
static hrtime = process.hrtime.bigint();
|
|
10
|
+
static dateStamp = HighResolutionTimestamp.date.getTime(); // LEGACY
|
|
11
|
+
static milliSeconds = HighResolutionTimestamp.date.getMilliseconds();
|
|
12
|
+
static dateStampNew = BigInt(HighResolutionTimestamp.dateStamp - HighResolutionTimestamp.milliSeconds) * 1000000n;
|
|
13
|
+
static hrtimeNew = HighResolutionTimestamp.hrtime - BigInt(HighResolutionTimestamp.milliSeconds) * 1000000n;
|
|
14
|
+
|
|
15
|
+
static getHighResolutionDate(timestamp) {
|
|
16
|
+
if(!timestamp) {
|
|
17
|
+
timestamp = process.hrtime.bigint();
|
|
18
|
+
}
|
|
19
|
+
return HighResolutionTimestamp.dateStampNew + (timestamp - HighResolutionTimestamp.hrtimeNew);
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
static getMilliseconds(hrtime) {
|
|
23
|
+
return Number(hrtime / 1000000n);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
static workerInit(dateStamp, timeStamp) {
|
|
27
|
+
HighResolutionTimestamp.dateStamp = dateStamp;
|
|
28
|
+
HighResolutionTimestamp.hrtime = timeStamp;
|
|
29
|
+
ddb.setTimeCreator(HighResolutionTimestamp.getHighResolutionDate);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
ddb.setTimeCreator(HighResolutionTimestamp.getHighResolutionDate);
|
|
35
|
+
|
|
36
|
+
module.exports = HighResolutionTimestamp;
|