Page MenuHomePhabricator

D8253.diff
No OneTemporary

D8253.diff

Index: src/applications/notification/client/PhabricatorNotificationClient.php
===================================================================
--- src/applications/notification/client/PhabricatorNotificationClient.php
+++ src/applications/notification/client/PhabricatorNotificationClient.php
@@ -2,7 +2,7 @@
final class PhabricatorNotificationClient {
- const EXPECT_VERSION = 2;
+ const EXPECT_VERSION = 3;
public static function getServerStatus() {
$uri = PhabricatorEnv::getEnvConfig('notification.server-uri');
Index: support/aphlict/server/aphlict_server.js
===================================================================
--- support/aphlict/server/aphlict_server.js
+++ support/aphlict/server/aphlict_server.js
@@ -6,6 +6,11 @@
* You can also specify `port`, `admin`, `host` and `log`.
*/
+var JX = require('./lib/javelin').JX;
+JX.require('lib/AphlictIDGenerator', __dirname);
+
+var id_generator = new JX.AphlictIDGenerator();
+
var config = parse_command_line_arguments(process.argv);
function parse_command_line_arguments(argv) {
@@ -108,25 +113,9 @@
var clients = {};
var current_connections = 0;
-// According to the internet up to 2^53 can
-// be stored in javascript, this is less than that
-var MAX_ID = 9007199254740991;//2^53 -1
-
-// If we get one connections per millisecond this will
-// be fine as long as someone doesn't maintain a
-// connection for longer than 6854793 years. If
-// you want to write something pretty be my guest
-
-function generate_id() {
- if (typeof generate_id.current_id == 'undefined' ||
- generate_id.current_id > MAX_ID) {
- generate_id.current_id = 0;
- }
- return generate_id.current_id++;
-}
var send_server = net.createServer(function(socket) {
- var client_id = generate_id();
+ var client_id = id_generator.generateNext();
var client_name = '[' + socket.remoteAddress + '] [#' + client_id + '] ';
clients[client_id] = socket;
@@ -189,11 +178,11 @@
var status = {
'uptime': (new Date().getTime() - start_time),
'clients.active': current_connections,
- 'clients.total': generate_id.current_id || 0,
+ 'clients.total': id_generator.getTotalCount(),
'messages.in': messages_in,
'messages.out': messages_out,
'log': config.log,
- 'version': 2
+ 'version': 3
};
response.write(JSON.stringify(status));
Index: support/aphlict/server/lib/AphlictIDGenerator.js
===================================================================
--- /dev/null
+++ support/aphlict/server/lib/AphlictIDGenerator.js
@@ -0,0 +1,18 @@
+var JX = require('javelin').JX;
+
+JX.install('AphlictIDGenerator', {
+
+ members : {
+ _next : 0,
+
+ generateNext : function() {
+ this._next = ((this._next + 1) % 1000000000000);
+ return this._next;
+ },
+
+ getTotalCount : function() {
+ return this._next;
+ }
+ }
+
+});
Index: support/aphlict/server/lib/javelin.js
===================================================================
--- /dev/null
+++ support/aphlict/server/lib/javelin.js
@@ -0,0 +1,13 @@
+var javelin_root = '../../../../webroot/rsrc/externals/javelin/';
+var JX = require(javelin_root + 'core/init_node.js').JX;
+
+JX.require('core/util');
+JX.require('core/install');
+
+// NOTE: This is faking out a piece of code in JX.install which waits for
+// Stratcom before running static initializers.
+JX.Stratcom = {ready : true};
+JX.require('core/Event');
+JX.require('core/Stratcom');
+
+exports.JX = JX;
Index: webroot/rsrc/externals/javelin/core/init_node.js
===================================================================
--- /dev/null
+++ webroot/rsrc/externals/javelin/core/init_node.js
@@ -0,0 +1,45 @@
+/**
+ * Alternative Javelin init file for Node.js.
+ *
+ * @javelin-installs JX.enableDispatch
+ * @javelin-installs JX.onload
+ * @javelin-installs JX.flushHoldingQueue
+ * @javelin-installs JX.require
+ *
+ * @javelin
+ */
+
+var JX = {};
+var fs = require('fs');
+var vm = require('vm');
+var pathModule = require('path');
+
+var noop = function() {};
+
+JX.enableDispatch = noop;
+JX.flushHoldingQueue = noop;
+
+JX.onload = function(func) {
+ func();
+};
+
+JX.require = function(thing, relative) {
+ relative = relative || __dirname + '/..';
+ var path = relative + '/' + thing + '.js';
+ var content = fs.readFileSync(path);
+
+ var sandbox = {
+ JX : this,
+ __DEV__ : 0,
+ console : console,
+ window : {},
+ require : function (thing) {
+ return require(pathModule.dirname(path) + '/' + thing);
+ }
+ };
+
+ vm.createScript(content, path)
+ .runInNewContext(sandbox, path);
+};
+
+exports.JX = JX;

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 29, 4:07 PM (9 h, 20 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6942905
Default Alt Text
D8253.diff (4 KB)

Event Timeline