Skip to content

Commit

Permalink
JS driver v1.5.0-alpha01: Checking in transpiled files for bower
Browse files Browse the repository at this point in the history
  • Loading branch information
lutovich committed Jul 18, 2017
1 parent 2e5b292 commit e42c360
Show file tree
Hide file tree
Showing 15 changed files with 4,288 additions and 1,893 deletions.
1,413 changes: 926 additions & 487 deletions lib/browser/neo4j-web.js

Large diffs are not rendered by default.

34 changes: 17 additions & 17 deletions lib/browser/neo4j-web.min.js

Large diffs are not rendered by default.

3,978 changes: 2,705 additions & 1,273 deletions lib/browser/neo4j-web.test.js

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions lib/v1/driver.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ var Driver = function () {
* @constructor
* @param {string} url
* @param {string} userAgent
* @param {Object} token
* @param {Object} config
* @access private
* @param {object} token
* @param {object} config
* @protected
*/
function Driver(url, userAgent) {
var token = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
Expand Down
6 changes: 6 additions & 0 deletions lib/v1/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,12 @@ var USER_AGENT = "neo4j-javascript/" + _version2.default;
* // will retry the given unit of work on `ServiceUnavailable`, `SessionExpired` and transient errors with
* // exponential backoff using initial delay of 1 second. Default value is 30000 which is 30 seconds.
* maxTransactionRetryTime: 30000,
*
* // Provide an alternative load balancing strategy for the routing driver to use.
* // Driver uses "least_connected" by default.
* // <b>Note:</b> We are experimenting with different strategies. This could be removed in the next minor
* // version.
* loadBalancingStrategy: "least_connected" | "round_robin",
* }
*
* @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"
Expand Down
60 changes: 30 additions & 30 deletions lib/v1/internal/connection-providers.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,6 @@ var _session = require('../session');

var _session2 = _interopRequireDefault(_session);

var _roundRobinArray = require('./round-robin-array');

var _roundRobinArray2 = _interopRequireDefault(_roundRobinArray);

var _routingTable = require('./routing-table');

var _routingTable2 = _interopRequireDefault(_routingTable);
Expand All @@ -61,6 +57,25 @@ var _routingUtil2 = _interopRequireDefault(_routingUtil);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.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 ConnectionProvider = function () {
function ConnectionProvider() {
(0, _classCallCheck3.default)(this, ConnectionProvider);
Expand All @@ -84,24 +99,7 @@ var ConnectionProvider = function () {
}
}]);
return ConnectionProvider;
}(); /**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.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 DirectConnectionProvider = exports.DirectConnectionProvider = function (_ConnectionProvider) {
(0, _inherits3.default)(DirectConnectionProvider, _ConnectionProvider);
Expand Down Expand Up @@ -131,17 +129,18 @@ var DirectConnectionProvider = exports.DirectConnectionProvider = function (_Con
var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
(0, _inherits3.default)(LoadBalancer, _ConnectionProvider2);

function LoadBalancer(address, routingContext, connectionPool, driverOnErrorCallback) {
function LoadBalancer(address, routingContext, connectionPool, loadBalancingStrategy, driverOnErrorCallback) {
(0, _classCallCheck3.default)(this, LoadBalancer);

var _this2 = (0, _possibleConstructorReturn3.default)(this, (LoadBalancer.__proto__ || (0, _getPrototypeOf2.default)(LoadBalancer)).call(this));

_this2._seedRouter = address;
_this2._routingTable = new _routingTable2.default(new _roundRobinArray2.default([_this2._seedRouter]));
_this2._routingTable = new _routingTable2.default([_this2._seedRouter]);
_this2._rediscovery = new _rediscovery2.default(new _routingUtil2.default(routingContext));
_this2._connectionPool = connectionPool;
_this2._driverOnErrorCallback = driverOnErrorCallback;
_this2._hostNameResolver = LoadBalancer._createHostNameResolver();
_this2._loadBalancingStrategy = loadBalancingStrategy;
_this2._useSeedRouter = false;
return _this2;
}
Expand All @@ -153,9 +152,11 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {

var connectionPromise = this._freshRoutingTable(accessMode).then(function (routingTable) {
if (accessMode === _driver.READ) {
return _this3._acquireConnectionToServer(routingTable.readers, 'read');
var address = _this3._loadBalancingStrategy.selectReader(routingTable.readers);
return _this3._acquireConnectionToServer(address, 'read');
} else if (accessMode === _driver.WRITE) {
return _this3._acquireConnectionToServer(routingTable.writers, 'write');
var _address = _this3._loadBalancingStrategy.selectWriter(routingTable.writers);
return _this3._acquireConnectionToServer(_address, 'write');
} else {
throw (0, _error.newError)('Illegal mode ' + accessMode);
}
Expand All @@ -175,8 +176,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
}
}, {
key: '_acquireConnectionToServer',
value: function _acquireConnectionToServer(serversRoundRobinArray, serverName) {
var address = serversRoundRobinArray.next();
value: function _acquireConnectionToServer(address, serverName) {
if (!address) {
return _promise2.default.reject((0, _error.newError)('Failed to obtain connection towards ' + serverName + ' server. Known routing table is: ' + this._routingTable, _error.SESSION_EXPIRED));
}
Expand All @@ -195,7 +195,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
}, {
key: '_refreshRoutingTable',
value: function _refreshRoutingTable(currentRoutingTable) {
var knownRouters = currentRoutingTable.routers.toArray();
var knownRouters = currentRoutingTable.routers;

if (this._useSeedRouter) {
return this._fetchRoutingTableFromSeedRouterFallbackToKnownRouters(knownRouters, currentRoutingTable);
Expand Down Expand Up @@ -310,7 +310,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
throw (0, _error.newError)('Could not perform discovery. No routing servers available. Known routing table: ' + this._routingTable, _error.SERVICE_UNAVAILABLE);
}

if (newRoutingTable.writers.isEmpty()) {
if (newRoutingTable.writers.length === 0) {
// use seed router next time. this is important when cluster is partitioned. it tries to make sure driver
// does not always get routing table without writers because it talks exclusively to a minority partition
this._useSeedRouter = true;
Expand Down
139 changes: 139 additions & 0 deletions lib/v1/internal/least-connected-load-balancing-strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});
exports.LEAST_CONNECTED_STRATEGY_NAME = undefined;

var _maxSafeInteger = require('babel-runtime/core-js/number/max-safe-integer');

var _maxSafeInteger2 = _interopRequireDefault(_maxSafeInteger);

var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');

var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);

var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');

var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);

var _createClass2 = require('babel-runtime/helpers/createClass');

var _createClass3 = _interopRequireDefault(_createClass2);

var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');

var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);

var _inherits2 = require('babel-runtime/helpers/inherits');

var _inherits3 = _interopRequireDefault(_inherits2);

var _roundRobinArrayIndex = require('./round-robin-array-index');

var _roundRobinArrayIndex2 = _interopRequireDefault(_roundRobinArrayIndex);

var _loadBalancingStrategy = require('./load-balancing-strategy');

var _loadBalancingStrategy2 = _interopRequireDefault(_loadBalancingStrategy);

function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }

/**
* Copyright (c) 2002-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.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 LEAST_CONNECTED_STRATEGY_NAME = exports.LEAST_CONNECTED_STRATEGY_NAME = 'least_connected';

var LeastConnectedLoadBalancingStrategy = function (_LoadBalancingStrateg) {
(0, _inherits3.default)(LeastConnectedLoadBalancingStrategy, _LoadBalancingStrateg);

/**
* @constructor
* @param {Pool} connectionPool the connection pool of this driver.
*/
function LeastConnectedLoadBalancingStrategy(connectionPool) {
(0, _classCallCheck3.default)(this, LeastConnectedLoadBalancingStrategy);

var _this = (0, _possibleConstructorReturn3.default)(this, (LeastConnectedLoadBalancingStrategy.__proto__ || (0, _getPrototypeOf2.default)(LeastConnectedLoadBalancingStrategy)).call(this));

_this._readersIndex = new _roundRobinArrayIndex2.default();
_this._writersIndex = new _roundRobinArrayIndex2.default();
_this._connectionPool = connectionPool;
return _this;
}

/**
* @inheritDoc
*/


(0, _createClass3.default)(LeastConnectedLoadBalancingStrategy, [{
key: 'selectReader',
value: function selectReader(knownReaders) {
return this._select(knownReaders, this._readersIndex);
}

/**
* @inheritDoc
*/

}, {
key: 'selectWriter',
value: function selectWriter(knownWriters) {
return this._select(knownWriters, this._writersIndex);
}
}, {
key: '_select',
value: function _select(addresses, roundRobinIndex) {
var length = addresses.length;
if (length === 0) {
return null;
}

// choose start index for iteration in round-rodin fashion
var startIndex = roundRobinIndex.next(length);
var index = startIndex;

var leastConnectedAddress = null;
var leastActiveConnections = _maxSafeInteger2.default;

// iterate over the array to find least connected address
do {
var address = addresses[index];
var activeConnections = this._connectionPool.activeResourceCount(address);

if (activeConnections < leastActiveConnections) {
leastConnectedAddress = address;
leastActiveConnections = activeConnections;
}

// loop over to the start of the array when end is reached
if (index === length - 1) {
index = 0;
} else {
index++;
}
} while (index !== startIndex);

return leastConnectedAddress;
}
}]);
return LeastConnectedLoadBalancingStrategy;
}(_loadBalancingStrategy2.default);

exports.default = LeastConnectedLoadBalancingStrategy;
72 changes: 72 additions & 0 deletions lib/v1/internal/load-balancing-strategy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
'use strict';

Object.defineProperty(exports, "__esModule", {
value: true
});

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-2017 "Neo Technology,","
* Network Engine for Objects in Lund AB [http://neotechnology.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.
*/

/**
* A facility to select most appropriate reader or writer among the given addresses for request processing.
*/
var LoadBalancingStrategy = function () {
function LoadBalancingStrategy() {
(0, _classCallCheck3.default)(this, LoadBalancingStrategy);
}

(0, _createClass3.default)(LoadBalancingStrategy, [{
key: 'selectReader',


/**
* Select next most appropriate reader from the list of given readers.
* @param {string[]} knownReaders an array of currently known readers to select from.
* @return {string} most appropriate reader or <code>null</code> if given array is empty.
*/
value: function selectReader(knownReaders) {
throw new Error('Abstract function');
}

/**
* Select next most appropriate writer from the list of given writers.
* @param {string[]} knownWriters an array of currently known writers to select from.
* @return {string} most appropriate writer or <code>null</code> if given array is empty.
*/

}, {
key: 'selectWriter',
value: function selectWriter(knownWriters) {
throw new Error('Abstract function');
}
}]);
return LoadBalancingStrategy;
}();

exports.default = LoadBalancingStrategy;
Loading

0 comments on commit e42c360

Please sign in to comment.