Skip to content

Commit d39d357

Browse files
committed
Add CloudI API functions for service process constant value access before CloudI API initialization: timeout_initialize, timeout_terminate, process_index, process_count_max, process_count_min.
1 parent abe8cc6 commit d39d357

File tree

1 file changed

+39
-10
lines changed

1 file changed

+39
-10
lines changed

CloudI.js

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,17 @@ if (Erlang.nodejs_version_after('10.0.0',true)) {
109109
originalEmitWarning(warning, type, code, ctor);
110110
};
111111
}
112+
var getEnvToUnsignedInt = function getEnvToUnsignedInt (name) {
113+
var value_str = process.env[name];
114+
if (value_str === undefined) {
115+
throw new InvalidInputException();
116+
}
117+
var value = parseInt(value_str);
118+
if (value < 0) {
119+
throw new InvalidInputException();
120+
}
121+
return value;
122+
};
112123

113124
var InvalidInputException = function InvalidInputException () {
114125
var error = new Error('Invalid Input');
@@ -236,10 +247,7 @@ CloudI.API = function API (thread_index, callback) {
236247
CloudI.stderr_write('CloudI service execution must occur in CloudI\n');
237248
throw new InvalidInputException();
238249
}
239-
var buffer_size_str = process.env.CLOUDI_API_INIT_BUFFER_SIZE;
240-
if (buffer_size_str === undefined) {
241-
throw new InvalidInputException();
242-
}
250+
var buffer_size = getEnvToUnsignedInt('CLOUDI_API_INIT_BUFFER_SIZE');
243251
if (protocol_str == 'tcp') {
244252
API._use_header = true;
245253
}
@@ -259,7 +267,7 @@ CloudI.API = function API (thread_index, callback) {
259267
API._fatal_exceptions = false;
260268
API._terminate = false;
261269
API._terminate_callback = undefined;
262-
API._size = parseInt(buffer_size_str);
270+
API._size = buffer_size;
263271
API._callbacks = {};
264272
API._timeout_terminate = 10; // TIMEOUT_TERMINATE_MIN
265273
API._poll_callback = callback;
@@ -319,11 +327,7 @@ CloudI.API = function API (thread_index, callback) {
319327

320328
// class method
321329
CloudI.API.thread_count = function thread_count () {
322-
var count_str = process.env.CLOUDI_API_INIT_THREAD_COUNT;
323-
if (count_str === undefined) {
324-
throw new InvalidInputException();
325-
}
326-
return parseInt(count_str);
330+
return getEnvToUnsignedInt('CLOUDI_API_INIT_THREAD_COUNT');
327331
};
328332

329333
CloudI.API.prototype.subscribe = function (pattern, obj, obj_f, callback) {
@@ -538,6 +542,11 @@ CloudI.API.prototype.process_index = function () {
538542
return this._process_index;
539543
};
540544

545+
// class method
546+
CloudI.API.process_index_ = function process_index_ () {
547+
return getEnvToUnsignedInt('CLOUDI_API_INIT_PROCESS_INDEX');
548+
};
549+
541550
CloudI.API.prototype.process_count = function () {
542551
return this._process_count;
543552
};
@@ -546,10 +555,20 @@ CloudI.API.prototype.process_count_max = function () {
546555
return this._process_count_max;
547556
};
548557

558+
// class method
559+
CloudI.API.process_count_max_ = function process_count_max_ () {
560+
return getEnvToUnsignedInt('CLOUDI_API_INIT_PROCESS_COUNT_MAX');
561+
};
562+
549563
CloudI.API.prototype.process_count_min = function () {
550564
return this._process_count_min;
551565
};
552566

567+
// class method
568+
CloudI.API.process_count_min_ = function process_count_min_ () {
569+
return getEnvToUnsignedInt('CLOUDI_API_INIT_PROCESS_COUNT_MIN');
570+
};
571+
553572
CloudI.API.prototype.prefix = function () {
554573
return this._prefix;
555574
};
@@ -558,6 +577,11 @@ CloudI.API.prototype.timeout_initialize = function () {
558577
return this._timeout_initialize;
559578
};
560579

580+
// class method
581+
CloudI.API.timeout_initialize_ = function timeout_initialize_ () {
582+
return getEnvToUnsignedInt('CLOUDI_API_INIT_TIMEOUT_INITIALIZE');
583+
};
584+
561585
CloudI.API.prototype.timeout_async = function () {
562586
return this._timeout_async;
563587
};
@@ -570,6 +594,11 @@ CloudI.API.prototype.timeout_terminate = function () {
570594
return this._timeout_terminate;
571595
};
572596

597+
// class method
598+
CloudI.API.timeout_terminate_ = function timeout_terminate_ () {
599+
return getEnvToUnsignedInt('CLOUDI_API_INIT_TIMEOUT_TERMINATE');
600+
};
601+
573602
CloudI.API.prototype.priority_default = function () {
574603
return this._priority_default;
575604
};

0 commit comments

Comments
 (0)