@ohos-ports/pm2 0.0.0-stage → 7.1.2-beta.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/CHANGELOG.md +2607 -0
- package/CONTRIBUTING.md +124 -0
- package/GNU-AGPL-3.0.txt +665 -0
- package/LICENSE +1 -0
- package/README.md +255 -2
- package/SECURITY.md +41 -0
- package/bin/pm2 +3 -0
- package/bin/pm2-dev +3 -0
- package/bin/pm2-docker +3 -0
- package/bin/pm2-runtime +3 -0
- package/bin/pm2.ps1 +3 -0
- package/constants.js +113 -0
- package/index.js +12 -0
- package/lib/API/Configuration.js +212 -0
- package/lib/API/Containerizer.js +335 -0
- package/lib/API/Dashboard.js +726 -0
- package/lib/API/Deploy.js +117 -0
- package/lib/API/Extra.js +798 -0
- package/lib/API/ExtraMgmt/Docker.js +30 -0
- package/lib/API/Log.js +388 -0
- package/lib/API/LogManagement.js +351 -0
- package/lib/API/Modules/LOCAL.js +122 -0
- package/lib/API/Modules/Modularizer.js +148 -0
- package/lib/API/Modules/NPM.js +443 -0
- package/lib/API/Modules/TAR.js +368 -0
- package/lib/API/Modules/flagExt.js +46 -0
- package/lib/API/Modules/index.js +120 -0
- package/lib/API/Monit.js +247 -0
- package/lib/API/Serve.js +497 -0
- package/lib/API/Startup.js +630 -0
- package/lib/API/UX/helpers.js +213 -0
- package/lib/API/UX/index.js +9 -0
- package/lib/API/UX/pm2-describe.js +197 -0
- package/lib/API/UX/pm2-ls-minimal.js +31 -0
- package/lib/API/UX/pm2-ls.js +581 -0
- package/lib/API/Version.js +383 -0
- package/lib/API/interpreter.json +12 -0
- package/lib/API/pm2-plus/PM2IO.js +381 -0
- package/lib/API/pm2-plus/auth-strategies/CliAuth.js +306 -0
- package/lib/API/pm2-plus/auth-strategies/WebAuth.js +195 -0
- package/lib/API/pm2-plus/helpers.js +97 -0
- package/lib/API/pm2-plus/link.js +126 -0
- package/lib/API/pm2-plus/pres/motd +16 -0
- package/lib/API/pm2-plus/pres/motd.update +26 -0
- package/lib/API/pm2-plus/pres/welcome +28 -0
- package/lib/API/pm2-plus/process-selector.js +52 -0
- package/lib/API/schema.json +375 -0
- package/lib/API.js +1980 -0
- package/lib/Client.js +793 -0
- package/lib/Common.js +949 -0
- package/lib/Configuration.js +309 -0
- package/lib/Daemon.js +468 -0
- package/lib/Event.js +37 -0
- package/lib/God/ActionMethods.js +955 -0
- package/lib/God/ClusterMode.js +192 -0
- package/lib/God/ForkMode.js +205 -0
- package/lib/God/Methods.js +292 -0
- package/lib/God/Reload.js +300 -0
- package/lib/God/StdioLogger.js +239 -0
- package/lib/God.js +653 -0
- package/lib/HttpInterface.js +75 -0
- package/lib/OtelManager.js +74 -0
- package/lib/ProcessContainer.js +321 -0
- package/lib/ProcessContainerBun.js +355 -0
- package/lib/ProcessContainerFork.js +42 -0
- package/lib/ProcessContainerForkBun.js +31 -0
- package/lib/ProcessUtils.js +74 -0
- package/lib/TreeKill.js +111 -0
- package/lib/Utility.js +304 -0
- package/lib/VersionCheck.js +46 -0
- package/lib/Watcher.js +117 -0
- package/lib/Worker.js +200 -0
- package/lib/binaries/CLI.js +1092 -0
- package/lib/binaries/DevCLI.js +183 -0
- package/lib/binaries/Runtime.js +101 -0
- package/lib/binaries/Runtime4Docker.js +192 -0
- package/lib/completion.js +229 -0
- package/lib/completion.sh +40 -0
- package/lib/motd +36 -0
- package/lib/templates/Dockerfiles/Dockerfile-nodejs.tpl +8 -0
- package/lib/templates/ecosystem-es.tpl +24 -0
- package/lib/templates/ecosystem-simple-es.tpl +8 -0
- package/lib/templates/ecosystem-simple.tpl +6 -0
- package/lib/templates/ecosystem.tpl +22 -0
- package/lib/templates/init-scripts/launchd.tpl +35 -0
- package/lib/templates/init-scripts/openrc.tpl +52 -0
- package/lib/templates/init-scripts/pm2-init-amazon.sh +86 -0
- package/lib/templates/init-scripts/rcd-openbsd.tpl +41 -0
- package/lib/templates/init-scripts/rcd.tpl +44 -0
- package/lib/templates/init-scripts/smf.tpl +43 -0
- package/lib/templates/init-scripts/systemd-online.tpl +22 -0
- package/lib/templates/init-scripts/systemd.tpl +22 -0
- package/lib/templates/init-scripts/upstart.tpl +103 -0
- package/lib/templates/logrotate.d/pm2 +10 -0
- package/lib/templates/sample-apps/http-server/README.md +14 -0
- package/lib/templates/sample-apps/http-server/api.js +9 -0
- package/lib/templates/sample-apps/http-server/ecosystem.config.js +14 -0
- package/lib/templates/sample-apps/http-server/package.json +11 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/README.md +45 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/custom-metrics.js +66 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/pm2-plus-metrics-actions/package.json +11 -0
- package/lib/templates/sample-apps/python-app/README.md +4 -0
- package/lib/templates/sample-apps/python-app/echo.py +7 -0
- package/lib/templates/sample-apps/python-app/ecosystem.config.js +12 -0
- package/lib/templates/sample-apps/python-app/package.json +11 -0
- package/lib/tools/Config.js +251 -0
- package/lib/tools/SysMetrics.js +375 -0
- package/lib/tools/copydirSync.js +101 -0
- package/lib/tools/deleteFolderRecursive.js +19 -0
- package/lib/tools/find-package-json.js +74 -0
- package/lib/tools/fmt.js +72 -0
- package/lib/tools/interpreter.js +88 -0
- package/lib/tools/isbinaryfile.js +94 -0
- package/lib/tools/json5.js +752 -0
- package/lib/tools/multimeter/bar.js +111 -0
- package/lib/tools/multimeter/charm/encode.js +18 -0
- package/lib/tools/multimeter/charm/index.js +305 -0
- package/lib/tools/multimeter/index.js +76 -0
- package/lib/tools/open.js +56 -0
- package/lib/tools/passwd.js +58 -0
- package/lib/tools/pm2-config-keys.js +165 -0
- package/lib/tools/prompt.js +76 -0
- package/lib/tools/serviceStop.js +149 -0
- package/lib/tools/sexec.js +55 -0
- package/lib/tools/treeify.js +113 -0
- package/lib/tools/typestrip.js +55 -0
- package/lib/tools/which.js +120 -0
- package/lib/tools/xdg-open +861 -0
- package/modules/blessed/LICENSE +20 -0
- package/modules/blessed/README.md +34 -0
- package/modules/blessed/index.js +1 -0
- package/modules/blessed/lib/alias.js +526 -0
- package/modules/blessed/lib/blessed.js +32 -0
- package/modules/blessed/lib/colors.js +530 -0
- package/modules/blessed/lib/events.js +189 -0
- package/modules/blessed/lib/gpmclient.js +221 -0
- package/modules/blessed/lib/helpers.js +165 -0
- package/modules/blessed/lib/keys.js +339 -0
- package/modules/blessed/lib/program.js +4297 -0
- package/modules/blessed/lib/tput.js +3022 -0
- package/modules/blessed/lib/unicode.js +885 -0
- package/modules/blessed/lib/widget.js +32 -0
- package/modules/blessed/lib/widgets/box.js +34 -0
- package/modules/blessed/lib/widgets/element.js +2570 -0
- package/modules/blessed/lib/widgets/list.js +599 -0
- package/modules/blessed/lib/widgets/log.js +83 -0
- package/modules/blessed/lib/widgets/node.js +282 -0
- package/modules/blessed/lib/widgets/screen.js +2298 -0
- package/modules/blessed/lib/widgets/scrollablebox.js +389 -0
- package/modules/blessed/lib/widgets/scrollabletext.js +35 -0
- package/modules/blessed/lib/widgets/text.js +35 -0
- package/modules/blessed/usr/linux +0 -0
- package/modules/blessed/usr/windows-ansi +0 -0
- package/modules/blessed/usr/xterm +0 -0
- package/modules/blessed/usr/xterm-256color +0 -0
- package/modules/blessed/usr/xterm.termcap +243 -0
- package/modules/chokidar/LICENSE +21 -0
- package/modules/chokidar/VENDORED.md +76 -0
- package/modules/chokidar/index.js +979 -0
- package/modules/chokidar/lib/brace-expand.js +180 -0
- package/modules/chokidar/lib/constants.js +66 -0
- package/modules/chokidar/lib/fsevents-handler.js +526 -0
- package/modules/chokidar/lib/nodefs-handler.js +654 -0
- package/modules/fclone.js +49 -0
- package/modules/pm2-axon/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/History.md +5 -0
- package/modules/pm2-axon/lib/configurable/Makefile +7 -0
- package/modules/pm2-axon/lib/configurable/Readme.md +57 -0
- package/modules/pm2-axon/lib/configurable/index.js +2 -0
- package/modules/pm2-axon/lib/configurable/lib/configurable.js +47 -0
- package/modules/pm2-axon/lib/configurable/package.json +68 -0
- package/modules/pm2-axon/lib/index.js +44 -0
- package/modules/pm2-axon/lib/plugins/queue.js +71 -0
- package/modules/pm2-axon/lib/plugins/round-robin.js +55 -0
- package/modules/pm2-axon/lib/sockets/pub-emitter.js +26 -0
- package/modules/pm2-axon/lib/sockets/pub.js +77 -0
- package/modules/pm2-axon/lib/sockets/pull.js +37 -0
- package/modules/pm2-axon/lib/sockets/push.js +32 -0
- package/modules/pm2-axon/lib/sockets/rep.js +73 -0
- package/modules/pm2-axon/lib/sockets/req.js +101 -0
- package/modules/pm2-axon/lib/sockets/sock.js +430 -0
- package/modules/pm2-axon/lib/sockets/sub-emitter.js +92 -0
- package/modules/pm2-axon/lib/sockets/sub.js +147 -0
- package/modules/pm2-axon/lib/utils.js +19 -0
- package/modules/pm2-axon-rpc/index.js +3 -0
- package/modules/pm2-axon-rpc/lib/client.js +63 -0
- package/modules/pm2-axon-rpc/lib/server.js +139 -0
- package/modules/pm2-io-agent/LICENSE +661 -0
- package/modules/pm2-io-agent/README.md +62 -0
- package/modules/pm2-io-agent/config.js +30 -0
- package/modules/pm2-io-agent/constants.js +118 -0
- package/modules/pm2-io-agent/index.js +2 -0
- package/modules/pm2-io-agent/src/InteractorClient.js +513 -0
- package/modules/pm2-io-agent/src/InteractorDaemon.js +455 -0
- package/modules/pm2-io-agent/src/PM2Client.js +112 -0
- package/modules/pm2-io-agent/src/PM2Interface.js +180 -0
- package/modules/pm2-io-agent/src/TransporterInterface.js +173 -0
- package/modules/pm2-io-agent/src/Utility.js +392 -0
- package/modules/pm2-io-agent/src/WatchDog.js +70 -0
- package/modules/pm2-io-agent/src/push/DataRetriever.js +77 -0
- package/modules/pm2-io-agent/src/push/PushInteractor.js +206 -0
- package/modules/pm2-io-agent/src/push/TransactionAggregator.js +670 -0
- package/modules/pm2-io-agent/src/reverse/ReverseInteractor.js +128 -0
- package/modules/pm2-io-agent/src/transporters/Transporter.js +129 -0
- package/modules/pm2-io-agent/src/transporters/WebsocketTransport.js +202 -0
- package/modules/pm2-io-agent/src/utils/BinaryHeap.js +135 -0
- package/modules/pm2-io-agent/src/utils/EDS.js +111 -0
- package/modules/pm2-io-agent/src/utils/probes/Histogram.js +204 -0
- package/modules/pm2-io-agent/src/utils/units.js +10 -0
- package/modules/pm2-io-bpm/configuration.js +141 -0
- package/modules/pm2-io-bpm/constants.js +10 -0
- package/modules/pm2-io-bpm/featureManager.js +110 -0
- package/modules/pm2-io-bpm/features/dependencies.js +48 -0
- package/modules/pm2-io-bpm/features/events.js +50 -0
- package/modules/pm2-io-bpm/features/metrics.js +102 -0
- package/modules/pm2-io-bpm/features/notify.js +238 -0
- package/modules/pm2-io-bpm/features/profiling.js +70 -0
- package/modules/pm2-io-bpm/features/tracing.js +174 -0
- package/modules/pm2-io-bpm/index.js +11 -0
- package/modules/pm2-io-bpm/metrics/eventLoopMetrics.js +136 -0
- package/modules/pm2-io-bpm/metrics/httpMetrics.js +175 -0
- package/modules/pm2-io-bpm/metrics/network.js +132 -0
- package/modules/pm2-io-bpm/metrics/runtime.js +161 -0
- package/modules/pm2-io-bpm/metrics/v8.js +104 -0
- package/modules/pm2-io-bpm/otel/constants.js +7 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/index.js +17 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/platform/node/util.js +51 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/transform.js +137 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/types.js +24 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/utils.js +23 -0
- package/modules/pm2-io-bpm/otel/custom-zipkin-exporter/zipkin.js +149 -0
- package/modules/pm2-io-bpm/pmx.js +380 -0
- package/modules/pm2-io-bpm/profilers/addonProfiler.js +193 -0
- package/modules/pm2-io-bpm/profilers/inspectorProfiler.js +302 -0
- package/modules/pm2-io-bpm/serviceManager.js +21 -0
- package/modules/pm2-io-bpm/services/actions.js +159 -0
- package/modules/pm2-io-bpm/services/inspector.js +43 -0
- package/modules/pm2-io-bpm/services/metrics.js +186 -0
- package/modules/pm2-io-bpm/services/runtimeStats.js +54 -0
- package/modules/pm2-io-bpm/services/transport.js +11 -0
- package/modules/pm2-io-bpm/transports/IPCTransport.js +115 -0
- package/modules/pm2-io-bpm/utils/BinaryHeap.js +134 -0
- package/modules/pm2-io-bpm/utils/EDS.js +113 -0
- package/modules/pm2-io-bpm/utils/EWMA.js +32 -0
- package/modules/pm2-io-bpm/utils/autocast.js +61 -0
- package/modules/pm2-io-bpm/utils/metrics/counter.js +33 -0
- package/modules/pm2-io-bpm/utils/metrics/gauge.js +23 -0
- package/modules/pm2-io-bpm/utils/metrics/histogram.js +192 -0
- package/modules/pm2-io-bpm/utils/metrics/meter.js +46 -0
- package/modules/pm2-io-bpm/utils/miscellaneous.js +19 -0
- package/modules/pm2-io-bpm/utils/module.js +67 -0
- package/modules/pm2-io-bpm/utils/shimmer.js +19 -0
- package/modules/pm2-io-bpm/utils/stackParser.js +160 -0
- package/modules/pm2-io-bpm/utils/transactionAggregator.js +429 -0
- package/modules/pm2-io-bpm/utils/units.js +16 -0
- package/modules/vizion/LICENSE +13 -0
- package/modules/vizion/README.md +133 -0
- package/modules/vizion/index.js +1 -0
- package/modules/vizion/lib/git/git.js +247 -0
- package/modules/vizion/lib/vizion.js +52 -0
- package/package.json +170 -4
- package/paths.js +121 -0
- package/pm2 +11 -0
- package/types/index.d.ts +732 -0
- package/types/tsconfig.json +14 -0
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
|
|
2
|
+
# configurable
|
|
3
|
+
|
|
4
|
+
Configuration mixin.
|
|
5
|
+
|
|
6
|
+
## API
|
|
7
|
+
|
|
8
|
+
Make something configurable:
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
var Configurable = require('configurable');
|
|
12
|
+
|
|
13
|
+
// plain obj
|
|
14
|
+
var obj = {};
|
|
15
|
+
Configurable(obj);
|
|
16
|
+
|
|
17
|
+
// returns the obj itself
|
|
18
|
+
var obj = Configurable({});
|
|
19
|
+
|
|
20
|
+
// make a prototype configurable
|
|
21
|
+
Configurable(MyThing.prototype);
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
.get(name)
|
|
26
|
+
.set(name, val)
|
|
27
|
+
.set(obj)
|
|
28
|
+
.enable(name)
|
|
29
|
+
.disable(name)
|
|
30
|
+
.enabled(name)
|
|
31
|
+
.disabled(name)
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
## License
|
|
35
|
+
|
|
36
|
+
(The MIT License)
|
|
37
|
+
|
|
38
|
+
Copyright (c) 2012 TJ Holowaychuk <tj@vision-media.ca>
|
|
39
|
+
|
|
40
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
|
41
|
+
a copy of this software and associated documentation files (the
|
|
42
|
+
'Software'), to deal in the Software without restriction, including
|
|
43
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
|
44
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
|
45
|
+
permit persons to whom the Software is furnished to do so, subject to
|
|
46
|
+
the following conditions:
|
|
47
|
+
|
|
48
|
+
The above copyright notice and this permission notice shall be
|
|
49
|
+
included in all copies or substantial portions of the Software.
|
|
50
|
+
|
|
51
|
+
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
52
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
53
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
54
|
+
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
55
|
+
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
56
|
+
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
57
|
+
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Make `obj` configurable.
|
|
4
|
+
*
|
|
5
|
+
* @param {Object} obj
|
|
6
|
+
* @return {Object} the `obj`
|
|
7
|
+
* @api public
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
module.exports = function(obj){
|
|
11
|
+
|
|
12
|
+
obj.settings = {};
|
|
13
|
+
|
|
14
|
+
obj.set = function(name, val){
|
|
15
|
+
if (1 == arguments.length) {
|
|
16
|
+
for (var key in name) {
|
|
17
|
+
this.set(key, name[key]);
|
|
18
|
+
}
|
|
19
|
+
} else {
|
|
20
|
+
this.settings[name] = val;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return this;
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
obj.get = function(name){
|
|
27
|
+
return this.settings[name];
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
obj.enable = function(name){
|
|
31
|
+
return this.set(name, true);
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
obj.disable = function(name){
|
|
35
|
+
return this.set(name, false);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
obj.enabled = function(name){
|
|
39
|
+
return !! this.get(name);
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
obj.disabled = function(name){
|
|
43
|
+
return ! this.get(name);
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
return obj;
|
|
47
|
+
};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_args": [
|
|
3
|
+
[
|
|
4
|
+
{
|
|
5
|
+
"raw": "configurable@0.0.1",
|
|
6
|
+
"scope": null,
|
|
7
|
+
"escapedName": "configurable",
|
|
8
|
+
"name": "configurable",
|
|
9
|
+
"rawSpec": "0.0.1",
|
|
10
|
+
"spec": "0.0.1",
|
|
11
|
+
"type": "version"
|
|
12
|
+
},
|
|
13
|
+
"/home/unitech/keymetrics/pm2-axon"
|
|
14
|
+
]
|
|
15
|
+
],
|
|
16
|
+
"_from": "configurable@0.0.1",
|
|
17
|
+
"_id": "configurable@0.0.1",
|
|
18
|
+
"_inCache": true,
|
|
19
|
+
"_installable": true,
|
|
20
|
+
"_location": "/configurable",
|
|
21
|
+
"_phantomChildren": {},
|
|
22
|
+
"_requested": {
|
|
23
|
+
"raw": "configurable@0.0.1",
|
|
24
|
+
"scope": null,
|
|
25
|
+
"escapedName": "configurable",
|
|
26
|
+
"name": "configurable",
|
|
27
|
+
"rawSpec": "0.0.1",
|
|
28
|
+
"spec": "0.0.1",
|
|
29
|
+
"type": "version"
|
|
30
|
+
},
|
|
31
|
+
"_requiredBy": [
|
|
32
|
+
"/"
|
|
33
|
+
],
|
|
34
|
+
"_resolved": "https://registry.npmjs.org/configurable/-/configurable-0.0.1.tgz",
|
|
35
|
+
"_shasum": "47d75b727b51b4eb84c1dadafe3f8240313833b1",
|
|
36
|
+
"_shrinkwrap": null,
|
|
37
|
+
"_spec": "configurable@0.0.1",
|
|
38
|
+
"_where": "/home/unitech/keymetrics/pm2-axon",
|
|
39
|
+
"author": {
|
|
40
|
+
"name": "TJ Holowaychuk",
|
|
41
|
+
"email": "tj@vision-media.ca"
|
|
42
|
+
},
|
|
43
|
+
"dependencies": {},
|
|
44
|
+
"description": "Configuration mixin",
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"mocha": "*",
|
|
47
|
+
"should": "*"
|
|
48
|
+
},
|
|
49
|
+
"directories": {},
|
|
50
|
+
"dist": {
|
|
51
|
+
"shasum": "47d75b727b51b4eb84c1dadafe3f8240313833b1",
|
|
52
|
+
"tarball": "https://registry.npmjs.org/configurable/-/configurable-0.0.1.tgz"
|
|
53
|
+
},
|
|
54
|
+
"keywords": [
|
|
55
|
+
"configuration"
|
|
56
|
+
],
|
|
57
|
+
"main": "index",
|
|
58
|
+
"maintainers": [
|
|
59
|
+
{
|
|
60
|
+
"name": "tjholowaychuk",
|
|
61
|
+
"email": "tj@vision-media.ca"
|
|
62
|
+
}
|
|
63
|
+
],
|
|
64
|
+
"name": "configurable",
|
|
65
|
+
"optionalDependencies": {},
|
|
66
|
+
"readme": "ERROR: No README data found!",
|
|
67
|
+
"version": "0.0.1"
|
|
68
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Constructors.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
exports.PubEmitterSocket = require('./sockets/pub-emitter');
|
|
7
|
+
exports.SubEmitterSocket = require('./sockets/sub-emitter');
|
|
8
|
+
exports.PushSocket = require('./sockets/push');
|
|
9
|
+
exports.PullSocket = require('./sockets/pull');
|
|
10
|
+
exports.PubSocket = require('./sockets/pub');
|
|
11
|
+
exports.SubSocket = require('./sockets/sub');
|
|
12
|
+
exports.ReqSocket = require('./sockets/req');
|
|
13
|
+
exports.RepSocket = require('./sockets/rep');
|
|
14
|
+
exports.Socket = require('./sockets/sock');
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Socket types.
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
exports.types = {
|
|
21
|
+
'pub-emitter': exports.PubEmitterSocket,
|
|
22
|
+
'sub-emitter': exports.SubEmitterSocket,
|
|
23
|
+
'push': exports.PushSocket,
|
|
24
|
+
'pull': exports.PullSocket,
|
|
25
|
+
'pub': exports.PubSocket,
|
|
26
|
+
'sub': exports.SubSocket,
|
|
27
|
+
'req': exports.ReqSocket,
|
|
28
|
+
'rep': exports.RepSocket
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Return a new socket of the given `type`.
|
|
33
|
+
*
|
|
34
|
+
* @param {String} type
|
|
35
|
+
* @param {Object} options
|
|
36
|
+
* @return {Socket}
|
|
37
|
+
* @api public
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
exports.socket = function(type, options){
|
|
41
|
+
var fn = exports.types[type];
|
|
42
|
+
if (!fn) throw new Error('invalid socket type "' + type + '"');
|
|
43
|
+
return new fn(options);
|
|
44
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var debug = require('debug')('axon:queue');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Queue plugin.
|
|
10
|
+
*
|
|
11
|
+
* Provides an `.enqueue()` method to the `sock`. Messages
|
|
12
|
+
* passed to `enqueue` will be buffered until the next
|
|
13
|
+
* `connect` event is emitted.
|
|
14
|
+
*
|
|
15
|
+
* Emits:
|
|
16
|
+
*
|
|
17
|
+
* - `drop` (msg) when a message is dropped
|
|
18
|
+
* - `flush` (msgs) when the queue is flushed
|
|
19
|
+
*
|
|
20
|
+
* @param {Object} options
|
|
21
|
+
* @api private
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
module.exports = function(options){
|
|
25
|
+
options = options || {};
|
|
26
|
+
|
|
27
|
+
return function(sock){
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Message buffer.
|
|
31
|
+
*/
|
|
32
|
+
|
|
33
|
+
sock.queue = [];
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* Flush `buf` on `connect`.
|
|
37
|
+
*/
|
|
38
|
+
|
|
39
|
+
sock.on('connect', function(){
|
|
40
|
+
var prev = sock.queue;
|
|
41
|
+
var len = prev.length;
|
|
42
|
+
sock.queue = [];
|
|
43
|
+
debug('flush %d messages', len);
|
|
44
|
+
|
|
45
|
+
for (var i = 0; i < len; ++i) {
|
|
46
|
+
this.send.apply(this, prev[i]);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
sock.emit('flush', prev);
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Pushes `msg` into `buf`.
|
|
54
|
+
*/
|
|
55
|
+
|
|
56
|
+
sock.enqueue = function(msg){
|
|
57
|
+
var hwm = sock.settings.hwm;
|
|
58
|
+
if (sock.queue.length >= hwm) return drop(msg);
|
|
59
|
+
sock.queue.push(msg);
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Drop the given `msg`.
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
function drop(msg) {
|
|
67
|
+
debug('drop');
|
|
68
|
+
sock.emit('drop', msg);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
};
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Deps.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var slice = require('../utils').slice;
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Round-robin plugin.
|
|
10
|
+
*
|
|
11
|
+
* Provides a `send` method which will
|
|
12
|
+
* write the `msg` to all connected peers.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object} options
|
|
15
|
+
* @api private
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
module.exports = function(options){
|
|
19
|
+
options = options || {};
|
|
20
|
+
var fallback = options.fallback || function(){};
|
|
21
|
+
|
|
22
|
+
return function(sock){
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Bind callback to `sock`.
|
|
26
|
+
*/
|
|
27
|
+
|
|
28
|
+
fallback = fallback.bind(sock);
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Initialize counter.
|
|
32
|
+
*/
|
|
33
|
+
|
|
34
|
+
var n = 0;
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Sends `msg` to all connected peers round-robin.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
sock.send = function(){
|
|
41
|
+
var socks = this.socks;
|
|
42
|
+
var len = socks.length;
|
|
43
|
+
var sock = socks[n++ % len];
|
|
44
|
+
|
|
45
|
+
var msg = slice(arguments);
|
|
46
|
+
|
|
47
|
+
if (sock && sock.writable) {
|
|
48
|
+
sock.write(this.pack(msg));
|
|
49
|
+
} else {
|
|
50
|
+
fallback(msg);
|
|
51
|
+
}
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
};
|
|
55
|
+
};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var PubSocket = require('./pub');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Expose `SubPubEmitterSocket`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
module.exports = PubEmitterSocket;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initialzie a new `PubEmitterSocket`.
|
|
16
|
+
*
|
|
17
|
+
* @api private
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function PubEmitterSocket() {
|
|
21
|
+
this.sock = new PubSocket;
|
|
22
|
+
this.emit = this.sock.send.bind(this.sock);
|
|
23
|
+
this.bind = this.sock.bind.bind(this.sock);
|
|
24
|
+
this.connect = this.sock.connect.bind(this.sock);
|
|
25
|
+
this.close = this.sock.close.bind(this.sock);
|
|
26
|
+
}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var Socket = require('./sock');
|
|
7
|
+
var slice = require('../utils').slice;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Expose `PubSocket`.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
module.exports = PubSocket;
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Initialize a new `PubSocket`.
|
|
17
|
+
*
|
|
18
|
+
* @api private
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
function PubSocket() {
|
|
22
|
+
Socket.call(this);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Inherits from `Socket.prototype`.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
PubSocket.prototype.__proto__ = Socket.prototype;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Send `msg` to all established peers.
|
|
33
|
+
*
|
|
34
|
+
* @param {Mixed} msg
|
|
35
|
+
* @api public
|
|
36
|
+
*/
|
|
37
|
+
|
|
38
|
+
PubSocket.prototype.send = function(msg){
|
|
39
|
+
var socks = this.socks;
|
|
40
|
+
var len = socks.length;
|
|
41
|
+
var buf = this.pack(arguments);
|
|
42
|
+
|
|
43
|
+
for (var sock of socks) {
|
|
44
|
+
if (sock.writable) sock.write(buf);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return this;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
PubSocket.prototype.sendv2 = function(data, cb){
|
|
51
|
+
var socks = this.socks;
|
|
52
|
+
var len = socks.length;
|
|
53
|
+
var sock;
|
|
54
|
+
|
|
55
|
+
if (len == 0)
|
|
56
|
+
return process.nextTick(cb);
|
|
57
|
+
|
|
58
|
+
var buf = this.pack([data]);
|
|
59
|
+
|
|
60
|
+
var i = 0;
|
|
61
|
+
|
|
62
|
+
socks.forEach(function(sock) {
|
|
63
|
+
if (sock.writable)
|
|
64
|
+
sock.write(buf, function() {
|
|
65
|
+
i++;
|
|
66
|
+
if (i == len)
|
|
67
|
+
process.nextTick(cb);
|
|
68
|
+
});
|
|
69
|
+
else {
|
|
70
|
+
i++;
|
|
71
|
+
if (i == len)
|
|
72
|
+
process.nextTick(cb);
|
|
73
|
+
}
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
return this;
|
|
77
|
+
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var Socket = require('./sock');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Expose `PullSocket`.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
module.exports = PullSocket;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Initialize a new `PullSocket`.
|
|
16
|
+
*
|
|
17
|
+
* @api private
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
function PullSocket() {
|
|
21
|
+
Socket.call(this);
|
|
22
|
+
// TODO: selective reception
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Inherits from `Socket.prototype`.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
PullSocket.prototype.__proto__ = Socket.prototype;
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Pull sockets should not send messages.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
PullSocket.prototype.send = function(){
|
|
36
|
+
throw new Error('pull sockets should not send messages');
|
|
37
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var roundrobin = require('../plugins/round-robin');
|
|
7
|
+
var queue = require('../plugins/queue');
|
|
8
|
+
var Socket = require('./sock');
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Expose `PushSocket`.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
module.exports = PushSocket;
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* Initialize a new `PushSocket`.
|
|
18
|
+
*
|
|
19
|
+
* @api private
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
function PushSocket() {
|
|
23
|
+
Socket.call(this);
|
|
24
|
+
this.use(queue());
|
|
25
|
+
this.use(roundrobin({ fallback: this.enqueue }));
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Inherits from `Socket.prototype`.
|
|
30
|
+
*/
|
|
31
|
+
|
|
32
|
+
PushSocket.prototype.__proto__ = Socket.prototype;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var slice = require('../utils').slice;
|
|
7
|
+
var debug = require('debug')('axon:rep');
|
|
8
|
+
var Message = require('amp-message');
|
|
9
|
+
var Socket = require('./sock');
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Expose `RepSocket`.
|
|
13
|
+
*/
|
|
14
|
+
|
|
15
|
+
module.exports = RepSocket;
|
|
16
|
+
|
|
17
|
+
/**
|
|
18
|
+
* Initialize a new `RepSocket`.
|
|
19
|
+
*
|
|
20
|
+
* @api private
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
function RepSocket() {
|
|
24
|
+
Socket.call(this);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Inherits from `Socket.prototype`.
|
|
29
|
+
*/
|
|
30
|
+
|
|
31
|
+
RepSocket.prototype.__proto__ = Socket.prototype;
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Incoming.
|
|
35
|
+
*
|
|
36
|
+
* @param {net.Socket} sock
|
|
37
|
+
* @return {Function} closure(msg, mulitpart)
|
|
38
|
+
* @api private
|
|
39
|
+
*/
|
|
40
|
+
|
|
41
|
+
RepSocket.prototype.onmessage = function(sock){
|
|
42
|
+
var self = this;
|
|
43
|
+
|
|
44
|
+
return function (buf){
|
|
45
|
+
var msg = new Message(buf);
|
|
46
|
+
var args = msg.args;
|
|
47
|
+
|
|
48
|
+
var id = args.pop();
|
|
49
|
+
args.unshift('message');
|
|
50
|
+
args.push(reply);
|
|
51
|
+
self.emit.apply(self, args);
|
|
52
|
+
|
|
53
|
+
function reply() {
|
|
54
|
+
var fn = function(){};
|
|
55
|
+
var args = slice(arguments);
|
|
56
|
+
args[0] = args[0] || null;
|
|
57
|
+
|
|
58
|
+
var hasCallback = 'function' == typeof args[args.length - 1];
|
|
59
|
+
if (hasCallback) fn = args.pop();
|
|
60
|
+
|
|
61
|
+
args.push(id);
|
|
62
|
+
|
|
63
|
+
if (sock.writable) {
|
|
64
|
+
sock.write(self.pack(args), function(){ fn(true) });
|
|
65
|
+
return true;
|
|
66
|
+
} else {
|
|
67
|
+
debug('peer went away');
|
|
68
|
+
process.nextTick(function(){ fn(false) });
|
|
69
|
+
return false;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
};
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
|
|
2
|
+
/**
|
|
3
|
+
* Module dependencies.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
var debug = require('debug')('axon:req');
|
|
7
|
+
var queue = require('../plugins/queue');
|
|
8
|
+
var slice = require('../utils').slice;
|
|
9
|
+
var Message = require('amp-message');
|
|
10
|
+
var Socket = require('./sock');
|
|
11
|
+
|
|
12
|
+
/**
|
|
13
|
+
* Expose `ReqSocket`.
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
module.exports = ReqSocket;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Initialize a new `ReqSocket`.
|
|
20
|
+
*
|
|
21
|
+
* @api private
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
function ReqSocket() {
|
|
25
|
+
Socket.call(this);
|
|
26
|
+
this.n = 0;
|
|
27
|
+
this.ids = 0;
|
|
28
|
+
this.callbacks = {};
|
|
29
|
+
this.identity = this.get('identity');
|
|
30
|
+
this.use(queue());
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Inherits from `Socket.prototype`.
|
|
35
|
+
*/
|
|
36
|
+
|
|
37
|
+
ReqSocket.prototype.__proto__ = Socket.prototype;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Return a message id.
|
|
41
|
+
*
|
|
42
|
+
* @return {String}
|
|
43
|
+
* @api private
|
|
44
|
+
*/
|
|
45
|
+
|
|
46
|
+
ReqSocket.prototype.id = function(){
|
|
47
|
+
return this.identity + ':' + this.ids++;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* Emits the "message" event with all message parts
|
|
52
|
+
* after the null delimeter part.
|
|
53
|
+
*
|
|
54
|
+
* @param {net.Socket} sock
|
|
55
|
+
* @return {Function} closure(msg, multipart)
|
|
56
|
+
* @api private
|
|
57
|
+
*/
|
|
58
|
+
|
|
59
|
+
ReqSocket.prototype.onmessage = function(){
|
|
60
|
+
var self = this;
|
|
61
|
+
|
|
62
|
+
return function(buf){
|
|
63
|
+
var msg = new Message(buf);
|
|
64
|
+
var id = msg.pop();
|
|
65
|
+
var fn = self.callbacks[id];
|
|
66
|
+
if (!fn) return debug('missing callback %s', id);
|
|
67
|
+
fn.apply(null, msg.args);
|
|
68
|
+
delete self.callbacks[id];
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Sends `msg` to the remote peers. Appends
|
|
74
|
+
* the null message part prior to sending.
|
|
75
|
+
*
|
|
76
|
+
* @param {Mixed} msg
|
|
77
|
+
* @api public
|
|
78
|
+
*/
|
|
79
|
+
|
|
80
|
+
ReqSocket.prototype.send = function(msg){
|
|
81
|
+
var socks = this.socks;
|
|
82
|
+
var len = socks.length;
|
|
83
|
+
var sock = socks[this.n++ % len];
|
|
84
|
+
var args = slice(arguments);
|
|
85
|
+
|
|
86
|
+
if (sock) {
|
|
87
|
+
var hasCallback = 'function' == typeof args[args.length - 1];
|
|
88
|
+
if (!hasCallback) args.push(function(){});
|
|
89
|
+
var fn = args.pop();
|
|
90
|
+
fn.id = this.id();
|
|
91
|
+
this.callbacks[fn.id] = fn;
|
|
92
|
+
args.push(fn.id);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
if (sock) {
|
|
96
|
+
sock.write(this.pack(args));
|
|
97
|
+
} else {
|
|
98
|
+
debug('no connected peers');
|
|
99
|
+
this.enqueue(args);
|
|
100
|
+
}
|
|
101
|
+
};
|