ee-core 2.9.2 → 2.10.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/LICENSE +21 -21
- package/README.md +65 -65
- package/addon/index.js +34 -34
- package/addon/window/index.js +98 -98
- package/bin/tools.js +8 -8
- package/config/cache.js +41 -38
- package/config/config.default.js +331 -330
- package/config/index.js +75 -73
- package/const/channel.js +17 -17
- package/const/index.js +8 -8
- package/controller/baseContextClass.js +34 -34
- package/controller/index.js +34 -34
- package/core/index.js +10 -10
- package/core/lib/ee.js +216 -216
- package/core/lib/loader/context_loader.js +106 -106
- package/core/lib/loader/ee_loader.js +435 -435
- package/core/lib/loader/file_loader.js +326 -326
- package/core/lib/loader/mixin/addon.js +32 -32
- package/core/lib/loader/mixin/config.js +130 -130
- package/core/lib/loader/mixin/controller.js +125 -125
- package/core/lib/loader/mixin/service.js +28 -28
- package/core/lib/utils/base_context_class.js +34 -34
- package/core/lib/utils/function.js +30 -30
- package/core/lib/utils/index.js +133 -133
- package/core/lib/utils/sequencify.js +59 -59
- package/core/lib/utils/timing.js +77 -77
- package/cross/index.js +183 -183
- package/cross/spawnProcess.js +183 -183
- package/ee/appLoader.js +48 -48
- package/ee/application.js +99 -99
- package/ee/baseApp.js +103 -102
- package/ee/eeApp.js +408 -408
- package/ee/index.js +57 -57
- package/electron/app/index.js +64 -58
- package/electron/index.js +19 -19
- package/electron/window/index.js +73 -73
- package/electron/window/winState.js +186 -186
- package/exception/index.js +112 -112
- package/html/boot.html +98 -98
- package/html/cross-failure.html +28 -28
- package/html/failure.html +28 -28
- package/html/index.js +13 -13
- package/httpclient/index.js +161 -161
- package/index.js +54 -54
- package/jobs/baseJobClass.js +16 -16
- package/jobs/child/app.js +65 -65
- package/jobs/child/forkProcess.js +145 -145
- package/jobs/child/index.js +82 -82
- package/jobs/child-pool/index.js +213 -213
- package/jobs/index.js +8 -8
- package/jobs/load-balancer/algorithm/index.js +11 -11
- package/jobs/load-balancer/algorithm/minimumConnection.js +18 -18
- package/jobs/load-balancer/algorithm/polling.js +11 -11
- package/jobs/load-balancer/algorithm/random.js +9 -9
- package/jobs/load-balancer/algorithm/specify.js +14 -14
- package/jobs/load-balancer/algorithm/weights.js +21 -21
- package/jobs/load-balancer/algorithm/weightsMinimumConnection.js +29 -29
- package/jobs/load-balancer/algorithm/weightsPolling.js +22 -22
- package/jobs/load-balancer/algorithm/weightsRandom.js +16 -16
- package/jobs/load-balancer/consts.js +9 -9
- package/jobs/load-balancer/index.js +201 -201
- package/jobs/load-balancer/scheduler.js +31 -31
- package/jobs/renderer/index.js +141 -141
- package/jobs/renderer/loadView.js +40 -40
- package/jobs/unification.js +63 -63
- package/loader/index.js +172 -172
- package/log/index.js +68 -68
- package/log/logger.js +86 -80
- package/main/index.js +56 -56
- package/message/childMessage.js +54 -54
- package/message/index.js +18 -18
- package/old-utils/index.js +91 -91
- package/package.json +38 -38
- package/ps/index.js +371 -371
- package/services/baseContextClass.js +34 -34
- package/services/index.js +40 -40
- package/socket/httpServer.js +147 -147
- package/socket/index.js +81 -81
- package/socket/io.js +27 -27
- package/socket/ipcServer.js +112 -112
- package/socket/socketServer.js +69 -67
- package/storage/index.js +38 -38
- package/storage/jsondb/adapters/Base.js +23 -23
- package/storage/jsondb/adapters/FileSync.js +64 -52
- package/storage/jsondb/main.js +55 -42
- package/storage/jsondbStorage.js +195 -195
- package/storage/sqliteStorage.js +123 -123
- package/utils/co.js +237 -237
- package/utils/copyto.js +160 -160
- package/utils/depd/index.js +538 -538
- package/utils/depd/lib/browser/index.js +77 -77
- package/utils/extend.js +73 -73
- package/utils/get-port/index.d.ts +64 -64
- package/utils/get-port/index.js +148 -148
- package/utils/helper.js +220 -220
- package/utils/index.js +160 -160
- package/utils/ip.js +261 -261
- package/utils/is.js +145 -145
- package/utils/json.js +72 -72
- package/utils/pargv.js +263 -263
- package/utils/time/index.js +19 -19
- package/utils/time/ms.js +162 -162
- package/utils/wrap.js +35 -35
package/cross/index.js
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
const fs = require('fs');
|
|
2
|
-
const EventEmitter = require('events');
|
|
3
|
-
const Conf = require('../config/cache');
|
|
4
|
-
const Helper = require('../utils/helper');
|
|
5
|
-
const Ps = require('../ps');
|
|
6
|
-
const SpawnProcess = require('./spawnProcess');
|
|
7
|
-
const Channel = require('../const/channel');
|
|
8
|
-
const extend = require('../utils/extend');
|
|
9
|
-
const GetPort = require('../utils/get-port');
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Cross-language service
|
|
13
|
-
* 跨语言服务
|
|
14
|
-
*/
|
|
15
|
-
const CrossLanguageService = {
|
|
16
|
-
|
|
17
|
-
emitter: undefined,
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* pid唯一
|
|
21
|
-
* {pid:{name,entity}, pid:{name,entity}, ...}
|
|
22
|
-
*/
|
|
23
|
-
children: {},
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* name唯一
|
|
27
|
-
* {name:pid, name:pid, ...}
|
|
28
|
-
*/
|
|
29
|
-
childrenMap: {},
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* create
|
|
33
|
-
*/
|
|
34
|
-
async create() {
|
|
35
|
-
|
|
36
|
-
// boot services
|
|
37
|
-
const servicesCfg = Conf.getValue('cross');
|
|
38
|
-
//await Helper.sleep(5 * 1000);
|
|
39
|
-
|
|
40
|
-
for (let key of Object.keys(servicesCfg)) {
|
|
41
|
-
let cfg = servicesCfg[key];
|
|
42
|
-
if (cfg.enable == true) {
|
|
43
|
-
this.run(key)
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
},
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* _initEventEmitter
|
|
50
|
-
*/
|
|
51
|
-
_initEventEmitter() {
|
|
52
|
-
if (this.emitter) {
|
|
53
|
-
return
|
|
54
|
-
}
|
|
55
|
-
this.emitter = new EventEmitter();
|
|
56
|
-
this.emitter.on(Channel.events.childProcessExit, (data) => {
|
|
57
|
-
const child = this.children[data.pid];
|
|
58
|
-
delete this.childrenMap[child.name];
|
|
59
|
-
delete this.children[data.pid];
|
|
60
|
-
});
|
|
61
|
-
this.emitter.on(Channel.events.childProcessError, (data) => {
|
|
62
|
-
const child = this.children[data.pid];
|
|
63
|
-
delete this.childrenMap[child.name];
|
|
64
|
-
delete this.children[data.pid];
|
|
65
|
-
});
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* run
|
|
70
|
-
*/
|
|
71
|
-
async run(service, opt = {}) {
|
|
72
|
-
// init dir
|
|
73
|
-
this._initPath();
|
|
74
|
-
|
|
75
|
-
const allConfig = Conf.all();
|
|
76
|
-
const defaultOpt = allConfig.cross[service] || {};
|
|
77
|
-
const targetConf = extend(true, {}, defaultOpt, opt);
|
|
78
|
-
if (Object.keys(targetConf).length == 0) {
|
|
79
|
-
throw new Error(`[ee-core] [cross] The service [${service}] config does not exit`);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
// eventEmitter
|
|
83
|
-
this._initEventEmitter();
|
|
84
|
-
|
|
85
|
-
// format params
|
|
86
|
-
let tmpArgs = targetConf.args;
|
|
87
|
-
let confPort = parseInt(Helper.getValueFromArgv(tmpArgs, 'port'));
|
|
88
|
-
// 某些程序给它传入不存在的参数时会报错
|
|
89
|
-
if (isNaN(confPort) && targetConf.port > 0) {
|
|
90
|
-
confPort = targetConf.port;
|
|
91
|
-
}
|
|
92
|
-
if (confPort > 0) {
|
|
93
|
-
// 动态生成port,传入的端口必须为int
|
|
94
|
-
confPort = await GetPort({ port: confPort });
|
|
95
|
-
// 替换port
|
|
96
|
-
targetConf.args = Helper.replaceArgsValue(tmpArgs, "port", String(confPort));
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
// 创建进程
|
|
100
|
-
const subProcess = new SpawnProcess(this, { targetConf, port: confPort });
|
|
101
|
-
let uniqueName = targetConf.name;
|
|
102
|
-
if (this.childrenMap.hasOwnProperty(uniqueName)) {
|
|
103
|
-
uniqueName = uniqueName + "-" + String(subProcess.pid);
|
|
104
|
-
}
|
|
105
|
-
this.childrenMap[uniqueName] = subProcess.pid;
|
|
106
|
-
subProcess.name = uniqueName;
|
|
107
|
-
this.children[subProcess.pid] = {
|
|
108
|
-
name: uniqueName,
|
|
109
|
-
entity: subProcess
|
|
110
|
-
};
|
|
111
|
-
|
|
112
|
-
return subProcess;
|
|
113
|
-
},
|
|
114
|
-
|
|
115
|
-
killAll() {
|
|
116
|
-
Object.keys(this.children).forEach(pid => {
|
|
117
|
-
this.kill(pid)
|
|
118
|
-
});
|
|
119
|
-
},
|
|
120
|
-
|
|
121
|
-
kill(pid) {
|
|
122
|
-
const entity = this.getProc(pid);
|
|
123
|
-
if (entity) {
|
|
124
|
-
entity.kill();
|
|
125
|
-
}
|
|
126
|
-
},
|
|
127
|
-
|
|
128
|
-
killByName(name) {
|
|
129
|
-
const entity = this.getProcByName(name);
|
|
130
|
-
if (entity) {
|
|
131
|
-
entity.kill();
|
|
132
|
-
}
|
|
133
|
-
},
|
|
134
|
-
|
|
135
|
-
getUrl(name) {
|
|
136
|
-
const entity = this.getProcByName(name);
|
|
137
|
-
const url = entity.getUrl();
|
|
138
|
-
|
|
139
|
-
return url;
|
|
140
|
-
},
|
|
141
|
-
|
|
142
|
-
// 获取 proc
|
|
143
|
-
getProcByName(name) {
|
|
144
|
-
const pid = this.childrenMap[name];
|
|
145
|
-
if (!pid) {
|
|
146
|
-
throw new Error(`[ee-core] [cross] The process named [${name}] does not exit`);
|
|
147
|
-
}
|
|
148
|
-
const entity = this.getProc(pid);
|
|
149
|
-
|
|
150
|
-
return entity;
|
|
151
|
-
},
|
|
152
|
-
|
|
153
|
-
// 获取 proc
|
|
154
|
-
getProc(pid) {
|
|
155
|
-
const child = this.children[pid];
|
|
156
|
-
if (!pid) {
|
|
157
|
-
throw new Error(`[ee-core] [cross] The process pid [${pid}] does not exit`);
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
return child.entity;
|
|
161
|
-
},
|
|
162
|
-
|
|
163
|
-
/**
|
|
164
|
-
* 获取pids
|
|
165
|
-
*/
|
|
166
|
-
getPids() {
|
|
167
|
-
let pids = Object.keys(this.children);
|
|
168
|
-
return pids;
|
|
169
|
-
},
|
|
170
|
-
|
|
171
|
-
/**
|
|
172
|
-
* init path
|
|
173
|
-
*/
|
|
174
|
-
_initPath() {
|
|
175
|
-
const pathname = Ps.getUserHomeConfigDir();
|
|
176
|
-
if (!fs.existsSync(pathname)) {
|
|
177
|
-
Helper.mkdir(pathname, {mode: 0o755});
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
module.exports = CrossLanguageService;
|
|
1
|
+
const fs = require('fs');
|
|
2
|
+
const EventEmitter = require('events');
|
|
3
|
+
const Conf = require('../config/cache');
|
|
4
|
+
const Helper = require('../utils/helper');
|
|
5
|
+
const Ps = require('../ps');
|
|
6
|
+
const SpawnProcess = require('./spawnProcess');
|
|
7
|
+
const Channel = require('../const/channel');
|
|
8
|
+
const extend = require('../utils/extend');
|
|
9
|
+
const GetPort = require('../utils/get-port');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Cross-language service
|
|
13
|
+
* 跨语言服务
|
|
14
|
+
*/
|
|
15
|
+
const CrossLanguageService = {
|
|
16
|
+
|
|
17
|
+
emitter: undefined,
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* pid唯一
|
|
21
|
+
* {pid:{name,entity}, pid:{name,entity}, ...}
|
|
22
|
+
*/
|
|
23
|
+
children: {},
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* name唯一
|
|
27
|
+
* {name:pid, name:pid, ...}
|
|
28
|
+
*/
|
|
29
|
+
childrenMap: {},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* create
|
|
33
|
+
*/
|
|
34
|
+
async create() {
|
|
35
|
+
|
|
36
|
+
// boot services
|
|
37
|
+
const servicesCfg = Conf.getValue('cross');
|
|
38
|
+
//await Helper.sleep(5 * 1000);
|
|
39
|
+
|
|
40
|
+
for (let key of Object.keys(servicesCfg)) {
|
|
41
|
+
let cfg = servicesCfg[key];
|
|
42
|
+
if (cfg.enable == true) {
|
|
43
|
+
this.run(key)
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* _initEventEmitter
|
|
50
|
+
*/
|
|
51
|
+
_initEventEmitter() {
|
|
52
|
+
if (this.emitter) {
|
|
53
|
+
return
|
|
54
|
+
}
|
|
55
|
+
this.emitter = new EventEmitter();
|
|
56
|
+
this.emitter.on(Channel.events.childProcessExit, (data) => {
|
|
57
|
+
const child = this.children[data.pid];
|
|
58
|
+
delete this.childrenMap[child.name];
|
|
59
|
+
delete this.children[data.pid];
|
|
60
|
+
});
|
|
61
|
+
this.emitter.on(Channel.events.childProcessError, (data) => {
|
|
62
|
+
const child = this.children[data.pid];
|
|
63
|
+
delete this.childrenMap[child.name];
|
|
64
|
+
delete this.children[data.pid];
|
|
65
|
+
});
|
|
66
|
+
},
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* run
|
|
70
|
+
*/
|
|
71
|
+
async run(service, opt = {}) {
|
|
72
|
+
// init dir
|
|
73
|
+
this._initPath();
|
|
74
|
+
|
|
75
|
+
const allConfig = Conf.all();
|
|
76
|
+
const defaultOpt = allConfig.cross[service] || {};
|
|
77
|
+
const targetConf = extend(true, {}, defaultOpt, opt);
|
|
78
|
+
if (Object.keys(targetConf).length == 0) {
|
|
79
|
+
throw new Error(`[ee-core] [cross] The service [${service}] config does not exit`);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// eventEmitter
|
|
83
|
+
this._initEventEmitter();
|
|
84
|
+
|
|
85
|
+
// format params
|
|
86
|
+
let tmpArgs = targetConf.args;
|
|
87
|
+
let confPort = parseInt(Helper.getValueFromArgv(tmpArgs, 'port'));
|
|
88
|
+
// 某些程序给它传入不存在的参数时会报错
|
|
89
|
+
if (isNaN(confPort) && targetConf.port > 0) {
|
|
90
|
+
confPort = targetConf.port;
|
|
91
|
+
}
|
|
92
|
+
if (confPort > 0) {
|
|
93
|
+
// 动态生成port,传入的端口必须为int
|
|
94
|
+
confPort = await GetPort({ port: confPort });
|
|
95
|
+
// 替换port
|
|
96
|
+
targetConf.args = Helper.replaceArgsValue(tmpArgs, "port", String(confPort));
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
// 创建进程
|
|
100
|
+
const subProcess = new SpawnProcess(this, { targetConf, port: confPort });
|
|
101
|
+
let uniqueName = targetConf.name;
|
|
102
|
+
if (this.childrenMap.hasOwnProperty(uniqueName)) {
|
|
103
|
+
uniqueName = uniqueName + "-" + String(subProcess.pid);
|
|
104
|
+
}
|
|
105
|
+
this.childrenMap[uniqueName] = subProcess.pid;
|
|
106
|
+
subProcess.name = uniqueName;
|
|
107
|
+
this.children[subProcess.pid] = {
|
|
108
|
+
name: uniqueName,
|
|
109
|
+
entity: subProcess
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
return subProcess;
|
|
113
|
+
},
|
|
114
|
+
|
|
115
|
+
killAll() {
|
|
116
|
+
Object.keys(this.children).forEach(pid => {
|
|
117
|
+
this.kill(pid)
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
|
|
121
|
+
kill(pid) {
|
|
122
|
+
const entity = this.getProc(pid);
|
|
123
|
+
if (entity) {
|
|
124
|
+
entity.kill();
|
|
125
|
+
}
|
|
126
|
+
},
|
|
127
|
+
|
|
128
|
+
killByName(name) {
|
|
129
|
+
const entity = this.getProcByName(name);
|
|
130
|
+
if (entity) {
|
|
131
|
+
entity.kill();
|
|
132
|
+
}
|
|
133
|
+
},
|
|
134
|
+
|
|
135
|
+
getUrl(name) {
|
|
136
|
+
const entity = this.getProcByName(name);
|
|
137
|
+
const url = entity.getUrl();
|
|
138
|
+
|
|
139
|
+
return url;
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// 获取 proc
|
|
143
|
+
getProcByName(name) {
|
|
144
|
+
const pid = this.childrenMap[name];
|
|
145
|
+
if (!pid) {
|
|
146
|
+
throw new Error(`[ee-core] [cross] The process named [${name}] does not exit`);
|
|
147
|
+
}
|
|
148
|
+
const entity = this.getProc(pid);
|
|
149
|
+
|
|
150
|
+
return entity;
|
|
151
|
+
},
|
|
152
|
+
|
|
153
|
+
// 获取 proc
|
|
154
|
+
getProc(pid) {
|
|
155
|
+
const child = this.children[pid];
|
|
156
|
+
if (!pid) {
|
|
157
|
+
throw new Error(`[ee-core] [cross] The process pid [${pid}] does not exit`);
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return child.entity;
|
|
161
|
+
},
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 获取pids
|
|
165
|
+
*/
|
|
166
|
+
getPids() {
|
|
167
|
+
let pids = Object.keys(this.children);
|
|
168
|
+
return pids;
|
|
169
|
+
},
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* init path
|
|
173
|
+
*/
|
|
174
|
+
_initPath() {
|
|
175
|
+
const pathname = Ps.getUserHomeConfigDir();
|
|
176
|
+
if (!fs.existsSync(pathname)) {
|
|
177
|
+
Helper.mkdir(pathname, {mode: 0o755});
|
|
178
|
+
}
|
|
179
|
+
},
|
|
180
|
+
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
module.exports = CrossLanguageService;
|