@@ -109,6 +109,17 @@ if (Erlang.nodejs_version_after('10.0.0',true)) {
109
109
originalEmitWarning ( warning , type , code , ctor ) ;
110
110
} ;
111
111
}
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
+ } ;
112
123
113
124
var InvalidInputException = function InvalidInputException ( ) {
114
125
var error = new Error ( 'Invalid Input' ) ;
@@ -236,10 +247,7 @@ CloudI.API = function API (thread_index, callback) {
236
247
CloudI . stderr_write ( 'CloudI service execution must occur in CloudI\n' ) ;
237
248
throw new InvalidInputException ( ) ;
238
249
}
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' ) ;
243
251
if ( protocol_str == 'tcp' ) {
244
252
API . _use_header = true ;
245
253
}
@@ -259,7 +267,7 @@ CloudI.API = function API (thread_index, callback) {
259
267
API . _fatal_exceptions = false ;
260
268
API . _terminate = false ;
261
269
API . _terminate_callback = undefined ;
262
- API . _size = parseInt ( buffer_size_str ) ;
270
+ API . _size = buffer_size ;
263
271
API . _callbacks = { } ;
264
272
API . _timeout_terminate = 10 ; // TIMEOUT_TERMINATE_MIN
265
273
API . _poll_callback = callback ;
@@ -319,11 +327,7 @@ CloudI.API = function API (thread_index, callback) {
319
327
320
328
// class method
321
329
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' ) ;
327
331
} ;
328
332
329
333
CloudI . API . prototype . subscribe = function ( pattern , obj , obj_f , callback ) {
@@ -538,6 +542,11 @@ CloudI.API.prototype.process_index = function () {
538
542
return this . _process_index ;
539
543
} ;
540
544
545
+ // class method
546
+ CloudI . API . process_index_ = function process_index_ ( ) {
547
+ return getEnvToUnsignedInt ( 'CLOUDI_API_INIT_PROCESS_INDEX' ) ;
548
+ } ;
549
+
541
550
CloudI . API . prototype . process_count = function ( ) {
542
551
return this . _process_count ;
543
552
} ;
@@ -546,10 +555,20 @@ CloudI.API.prototype.process_count_max = function () {
546
555
return this . _process_count_max ;
547
556
} ;
548
557
558
+ // class method
559
+ CloudI . API . process_count_max_ = function process_count_max_ ( ) {
560
+ return getEnvToUnsignedInt ( 'CLOUDI_API_INIT_PROCESS_COUNT_MAX' ) ;
561
+ } ;
562
+
549
563
CloudI . API . prototype . process_count_min = function ( ) {
550
564
return this . _process_count_min ;
551
565
} ;
552
566
567
+ // class method
568
+ CloudI . API . process_count_min_ = function process_count_min_ ( ) {
569
+ return getEnvToUnsignedInt ( 'CLOUDI_API_INIT_PROCESS_COUNT_MIN' ) ;
570
+ } ;
571
+
553
572
CloudI . API . prototype . prefix = function ( ) {
554
573
return this . _prefix ;
555
574
} ;
@@ -558,6 +577,11 @@ CloudI.API.prototype.timeout_initialize = function () {
558
577
return this . _timeout_initialize ;
559
578
} ;
560
579
580
+ // class method
581
+ CloudI . API . timeout_initialize_ = function timeout_initialize_ ( ) {
582
+ return getEnvToUnsignedInt ( 'CLOUDI_API_INIT_TIMEOUT_INITIALIZE' ) ;
583
+ } ;
584
+
561
585
CloudI . API . prototype . timeout_async = function ( ) {
562
586
return this . _timeout_async ;
563
587
} ;
@@ -570,6 +594,11 @@ CloudI.API.prototype.timeout_terminate = function () {
570
594
return this . _timeout_terminate ;
571
595
} ;
572
596
597
+ // class method
598
+ CloudI . API . timeout_terminate_ = function timeout_terminate_ ( ) {
599
+ return getEnvToUnsignedInt ( 'CLOUDI_API_INIT_TIMEOUT_TERMINATE' ) ;
600
+ } ;
601
+
573
602
CloudI . API . prototype . priority_default = function ( ) {
574
603
return this . _priority_default ;
575
604
} ;
0 commit comments