93 lines
3.1 KiB
JavaScript
93 lines
3.1 KiB
JavaScript
'use strict';
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
value: true
|
|
});
|
|
exports.DEFAULT_ACQUISITION_TIMEOUT = exports.DEFAULT_MAX_SIZE = undefined;
|
|
|
|
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
|
|
|
|
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
|
|
|
|
var _createClass2 = require('babel-runtime/helpers/createClass');
|
|
|
|
var _createClass3 = _interopRequireDefault(_createClass2);
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
/**
|
|
* Copyright (c) 2002-2018 "Neo4j,"
|
|
* Neo4j Sweden AB [http://neo4j.com]
|
|
*
|
|
* This file is part of Neo4j.
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
var DEFAULT_MAX_SIZE = 100;
|
|
var DEFAULT_ACQUISITION_TIMEOUT = 60 * 1000; // 60 seconds
|
|
|
|
var PoolConfig = function () {
|
|
function PoolConfig(maxSize, acquisitionTimeout) {
|
|
(0, _classCallCheck3.default)(this, PoolConfig);
|
|
|
|
this.maxSize = valueOrDefault(maxSize, DEFAULT_MAX_SIZE);
|
|
this.acquisitionTimeout = valueOrDefault(acquisitionTimeout, DEFAULT_ACQUISITION_TIMEOUT);
|
|
}
|
|
|
|
(0, _createClass3.default)(PoolConfig, null, [{
|
|
key: 'defaultConfig',
|
|
value: function defaultConfig() {
|
|
return new PoolConfig(DEFAULT_MAX_SIZE, DEFAULT_ACQUISITION_TIMEOUT);
|
|
}
|
|
}, {
|
|
key: 'fromDriverConfig',
|
|
value: function fromDriverConfig(config) {
|
|
var maxIdleSizeConfigured = isConfigured(config.connectionPoolSize);
|
|
var maxSizeConfigured = isConfigured(config.maxConnectionPoolSize);
|
|
|
|
var maxSize = void 0;
|
|
|
|
if (maxSizeConfigured) {
|
|
// correct size setting is set - use it's value
|
|
maxSize = config.maxConnectionPoolSize;
|
|
} else if (maxIdleSizeConfigured) {
|
|
// deprecated size setting is set - use it's value
|
|
console.warn('WARNING: neo4j-driver setting "connectionPoolSize" is deprecated, please use "maxConnectionPoolSize" instead');
|
|
maxSize = config.connectionPoolSize;
|
|
} else {
|
|
maxSize = DEFAULT_MAX_SIZE;
|
|
}
|
|
|
|
var acquisitionTimeoutConfigured = isConfigured(config.connectionAcquisitionTimeout);
|
|
var acquisitionTimeout = acquisitionTimeoutConfigured ? config.connectionAcquisitionTimeout : DEFAULT_ACQUISITION_TIMEOUT;
|
|
|
|
return new PoolConfig(maxSize, acquisitionTimeout);
|
|
}
|
|
}]);
|
|
return PoolConfig;
|
|
}();
|
|
|
|
exports.default = PoolConfig;
|
|
|
|
|
|
function valueOrDefault(value, defaultValue) {
|
|
return value === 0 || value ? value : defaultValue;
|
|
}
|
|
|
|
function isConfigured(value) {
|
|
return value === 0 || value;
|
|
}
|
|
|
|
exports.DEFAULT_MAX_SIZE = DEFAULT_MAX_SIZE;
|
|
exports.DEFAULT_ACQUISITION_TIMEOUT = DEFAULT_ACQUISITION_TIMEOUT; |