Skip to content

Commit e42c360

Browse files
committed
JS driver v1.5.0-alpha01: Checking in transpiled files for bower
1 parent 2e5b292 commit e42c360

15 files changed

+4288
-1893
lines changed

lib/browser/neo4j-web.js

Lines changed: 926 additions & 487 deletions
Large diffs are not rendered by default.

lib/browser/neo4j-web.min.js

Lines changed: 17 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/browser/neo4j-web.test.js

Lines changed: 2705 additions & 1273 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/v1/driver.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,9 @@ var Driver = function () {
9090
* @constructor
9191
* @param {string} url
9292
* @param {string} userAgent
93-
* @param {Object} token
94-
* @param {Object} config
95-
* @access private
93+
* @param {object} token
94+
* @param {object} config
95+
* @protected
9696
*/
9797
function Driver(url, userAgent) {
9898
var token = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};

lib/v1/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,12 @@ var USER_AGENT = "neo4j-javascript/" + _version2.default;
149149
* // will retry the given unit of work on `ServiceUnavailable`, `SessionExpired` and transient errors with
150150
* // exponential backoff using initial delay of 1 second. Default value is 30000 which is 30 seconds.
151151
* maxTransactionRetryTime: 30000,
152+
*
153+
* // Provide an alternative load balancing strategy for the routing driver to use.
154+
* // Driver uses "least_connected" by default.
155+
* // <b>Note:</b> We are experimenting with different strategies. This could be removed in the next minor
156+
* // version.
157+
* loadBalancingStrategy: "least_connected" | "round_robin",
152158
* }
153159
*
154160
* @param {string} url The URL for the Neo4j database, for instance "bolt://localhost"

lib/v1/internal/connection-providers.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ var _session = require('../session');
3737

3838
var _session2 = _interopRequireDefault(_session);
3939

40-
var _roundRobinArray = require('./round-robin-array');
41-
42-
var _roundRobinArray2 = _interopRequireDefault(_roundRobinArray);
43-
4440
var _routingTable = require('./routing-table');
4541

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

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

60+
/**
61+
* Copyright (c) 2002-2017 "Neo Technology,","
62+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
63+
*
64+
* This file is part of Neo4j.
65+
*
66+
* Licensed under the Apache License, Version 2.0 (the "License");
67+
* you may not use this file except in compliance with the License.
68+
* You may obtain a copy of the License at
69+
*
70+
* http://www.apache.org/licenses/LICENSE-2.0
71+
*
72+
* Unless required by applicable law or agreed to in writing, software
73+
* distributed under the License is distributed on an "AS IS" BASIS,
74+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
75+
* See the License for the specific language governing permissions and
76+
* limitations under the License.
77+
*/
78+
6479
var ConnectionProvider = function () {
6580
function ConnectionProvider() {
6681
(0, _classCallCheck3.default)(this, ConnectionProvider);
@@ -84,24 +99,7 @@ var ConnectionProvider = function () {
8499
}
85100
}]);
86101
return ConnectionProvider;
87-
}(); /**
88-
* Copyright (c) 2002-2017 "Neo Technology,","
89-
* Network Engine for Objects in Lund AB [http://neotechnology.com]
90-
*
91-
* This file is part of Neo4j.
92-
*
93-
* Licensed under the Apache License, Version 2.0 (the "License");
94-
* you may not use this file except in compliance with the License.
95-
* You may obtain a copy of the License at
96-
*
97-
* http://www.apache.org/licenses/LICENSE-2.0
98-
*
99-
* Unless required by applicable law or agreed to in writing, software
100-
* distributed under the License is distributed on an "AS IS" BASIS,
101-
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
102-
* See the License for the specific language governing permissions and
103-
* limitations under the License.
104-
*/
102+
}();
105103

106104
var DirectConnectionProvider = exports.DirectConnectionProvider = function (_ConnectionProvider) {
107105
(0, _inherits3.default)(DirectConnectionProvider, _ConnectionProvider);
@@ -131,17 +129,18 @@ var DirectConnectionProvider = exports.DirectConnectionProvider = function (_Con
131129
var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
132130
(0, _inherits3.default)(LoadBalancer, _ConnectionProvider2);
133131

134-
function LoadBalancer(address, routingContext, connectionPool, driverOnErrorCallback) {
132+
function LoadBalancer(address, routingContext, connectionPool, loadBalancingStrategy, driverOnErrorCallback) {
135133
(0, _classCallCheck3.default)(this, LoadBalancer);
136134

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

139137
_this2._seedRouter = address;
140-
_this2._routingTable = new _routingTable2.default(new _roundRobinArray2.default([_this2._seedRouter]));
138+
_this2._routingTable = new _routingTable2.default([_this2._seedRouter]);
141139
_this2._rediscovery = new _rediscovery2.default(new _routingUtil2.default(routingContext));
142140
_this2._connectionPool = connectionPool;
143141
_this2._driverOnErrorCallback = driverOnErrorCallback;
144142
_this2._hostNameResolver = LoadBalancer._createHostNameResolver();
143+
_this2._loadBalancingStrategy = loadBalancingStrategy;
145144
_this2._useSeedRouter = false;
146145
return _this2;
147146
}
@@ -153,9 +152,11 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
153152

154153
var connectionPromise = this._freshRoutingTable(accessMode).then(function (routingTable) {
155154
if (accessMode === _driver.READ) {
156-
return _this3._acquireConnectionToServer(routingTable.readers, 'read');
155+
var address = _this3._loadBalancingStrategy.selectReader(routingTable.readers);
156+
return _this3._acquireConnectionToServer(address, 'read');
157157
} else if (accessMode === _driver.WRITE) {
158-
return _this3._acquireConnectionToServer(routingTable.writers, 'write');
158+
var _address = _this3._loadBalancingStrategy.selectWriter(routingTable.writers);
159+
return _this3._acquireConnectionToServer(_address, 'write');
159160
} else {
160161
throw (0, _error.newError)('Illegal mode ' + accessMode);
161162
}
@@ -175,8 +176,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
175176
}
176177
}, {
177178
key: '_acquireConnectionToServer',
178-
value: function _acquireConnectionToServer(serversRoundRobinArray, serverName) {
179-
var address = serversRoundRobinArray.next();
179+
value: function _acquireConnectionToServer(address, serverName) {
180180
if (!address) {
181181
return _promise2.default.reject((0, _error.newError)('Failed to obtain connection towards ' + serverName + ' server. Known routing table is: ' + this._routingTable, _error.SESSION_EXPIRED));
182182
}
@@ -195,7 +195,7 @@ var LoadBalancer = exports.LoadBalancer = function (_ConnectionProvider2) {
195195
}, {
196196
key: '_refreshRoutingTable',
197197
value: function _refreshRoutingTable(currentRoutingTable) {
198-
var knownRouters = currentRoutingTable.routers.toArray();
198+
var knownRouters = currentRoutingTable.routers;
199199

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

313-
if (newRoutingTable.writers.isEmpty()) {
313+
if (newRoutingTable.writers.length === 0) {
314314
// use seed router next time. this is important when cluster is partitioned. it tries to make sure driver
315315
// does not always get routing table without writers because it talks exclusively to a minority partition
316316
this._useSeedRouter = true;
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
exports.LEAST_CONNECTED_STRATEGY_NAME = undefined;
7+
8+
var _maxSafeInteger = require('babel-runtime/core-js/number/max-safe-integer');
9+
10+
var _maxSafeInteger2 = _interopRequireDefault(_maxSafeInteger);
11+
12+
var _getPrototypeOf = require('babel-runtime/core-js/object/get-prototype-of');
13+
14+
var _getPrototypeOf2 = _interopRequireDefault(_getPrototypeOf);
15+
16+
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
17+
18+
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
19+
20+
var _createClass2 = require('babel-runtime/helpers/createClass');
21+
22+
var _createClass3 = _interopRequireDefault(_createClass2);
23+
24+
var _possibleConstructorReturn2 = require('babel-runtime/helpers/possibleConstructorReturn');
25+
26+
var _possibleConstructorReturn3 = _interopRequireDefault(_possibleConstructorReturn2);
27+
28+
var _inherits2 = require('babel-runtime/helpers/inherits');
29+
30+
var _inherits3 = _interopRequireDefault(_inherits2);
31+
32+
var _roundRobinArrayIndex = require('./round-robin-array-index');
33+
34+
var _roundRobinArrayIndex2 = _interopRequireDefault(_roundRobinArrayIndex);
35+
36+
var _loadBalancingStrategy = require('./load-balancing-strategy');
37+
38+
var _loadBalancingStrategy2 = _interopRequireDefault(_loadBalancingStrategy);
39+
40+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
41+
42+
/**
43+
* Copyright (c) 2002-2017 "Neo Technology,","
44+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
45+
*
46+
* This file is part of Neo4j.
47+
*
48+
* Licensed under the Apache License, Version 2.0 (the "License");
49+
* you may not use this file except in compliance with the License.
50+
* You may obtain a copy of the License at
51+
*
52+
* http://www.apache.org/licenses/LICENSE-2.0
53+
*
54+
* Unless required by applicable law or agreed to in writing, software
55+
* distributed under the License is distributed on an "AS IS" BASIS,
56+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
57+
* See the License for the specific language governing permissions and
58+
* limitations under the License.
59+
*/
60+
var LEAST_CONNECTED_STRATEGY_NAME = exports.LEAST_CONNECTED_STRATEGY_NAME = 'least_connected';
61+
62+
var LeastConnectedLoadBalancingStrategy = function (_LoadBalancingStrateg) {
63+
(0, _inherits3.default)(LeastConnectedLoadBalancingStrategy, _LoadBalancingStrateg);
64+
65+
/**
66+
* @constructor
67+
* @param {Pool} connectionPool the connection pool of this driver.
68+
*/
69+
function LeastConnectedLoadBalancingStrategy(connectionPool) {
70+
(0, _classCallCheck3.default)(this, LeastConnectedLoadBalancingStrategy);
71+
72+
var _this = (0, _possibleConstructorReturn3.default)(this, (LeastConnectedLoadBalancingStrategy.__proto__ || (0, _getPrototypeOf2.default)(LeastConnectedLoadBalancingStrategy)).call(this));
73+
74+
_this._readersIndex = new _roundRobinArrayIndex2.default();
75+
_this._writersIndex = new _roundRobinArrayIndex2.default();
76+
_this._connectionPool = connectionPool;
77+
return _this;
78+
}
79+
80+
/**
81+
* @inheritDoc
82+
*/
83+
84+
85+
(0, _createClass3.default)(LeastConnectedLoadBalancingStrategy, [{
86+
key: 'selectReader',
87+
value: function selectReader(knownReaders) {
88+
return this._select(knownReaders, this._readersIndex);
89+
}
90+
91+
/**
92+
* @inheritDoc
93+
*/
94+
95+
}, {
96+
key: 'selectWriter',
97+
value: function selectWriter(knownWriters) {
98+
return this._select(knownWriters, this._writersIndex);
99+
}
100+
}, {
101+
key: '_select',
102+
value: function _select(addresses, roundRobinIndex) {
103+
var length = addresses.length;
104+
if (length === 0) {
105+
return null;
106+
}
107+
108+
// choose start index for iteration in round-rodin fashion
109+
var startIndex = roundRobinIndex.next(length);
110+
var index = startIndex;
111+
112+
var leastConnectedAddress = null;
113+
var leastActiveConnections = _maxSafeInteger2.default;
114+
115+
// iterate over the array to find least connected address
116+
do {
117+
var address = addresses[index];
118+
var activeConnections = this._connectionPool.activeResourceCount(address);
119+
120+
if (activeConnections < leastActiveConnections) {
121+
leastConnectedAddress = address;
122+
leastActiveConnections = activeConnections;
123+
}
124+
125+
// loop over to the start of the array when end is reached
126+
if (index === length - 1) {
127+
index = 0;
128+
} else {
129+
index++;
130+
}
131+
} while (index !== startIndex);
132+
133+
return leastConnectedAddress;
134+
}
135+
}]);
136+
return LeastConnectedLoadBalancingStrategy;
137+
}(_loadBalancingStrategy2.default);
138+
139+
exports.default = LeastConnectedLoadBalancingStrategy;
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
'use strict';
2+
3+
Object.defineProperty(exports, "__esModule", {
4+
value: true
5+
});
6+
7+
var _classCallCheck2 = require('babel-runtime/helpers/classCallCheck');
8+
9+
var _classCallCheck3 = _interopRequireDefault(_classCallCheck2);
10+
11+
var _createClass2 = require('babel-runtime/helpers/createClass');
12+
13+
var _createClass3 = _interopRequireDefault(_createClass2);
14+
15+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16+
17+
/**
18+
* Copyright (c) 2002-2017 "Neo Technology,","
19+
* Network Engine for Objects in Lund AB [http://neotechnology.com]
20+
*
21+
* This file is part of Neo4j.
22+
*
23+
* Licensed under the Apache License, Version 2.0 (the "License");
24+
* you may not use this file except in compliance with the License.
25+
* You may obtain a copy of the License at
26+
*
27+
* http://www.apache.org/licenses/LICENSE-2.0
28+
*
29+
* Unless required by applicable law or agreed to in writing, software
30+
* distributed under the License is distributed on an "AS IS" BASIS,
31+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32+
* See the License for the specific language governing permissions and
33+
* limitations under the License.
34+
*/
35+
36+
/**
37+
* A facility to select most appropriate reader or writer among the given addresses for request processing.
38+
*/
39+
var LoadBalancingStrategy = function () {
40+
function LoadBalancingStrategy() {
41+
(0, _classCallCheck3.default)(this, LoadBalancingStrategy);
42+
}
43+
44+
(0, _createClass3.default)(LoadBalancingStrategy, [{
45+
key: 'selectReader',
46+
47+
48+
/**
49+
* Select next most appropriate reader from the list of given readers.
50+
* @param {string[]} knownReaders an array of currently known readers to select from.
51+
* @return {string} most appropriate reader or <code>null</code> if given array is empty.
52+
*/
53+
value: function selectReader(knownReaders) {
54+
throw new Error('Abstract function');
55+
}
56+
57+
/**
58+
* Select next most appropriate writer from the list of given writers.
59+
* @param {string[]} knownWriters an array of currently known writers to select from.
60+
* @return {string} most appropriate writer or <code>null</code> if given array is empty.
61+
*/
62+
63+
}, {
64+
key: 'selectWriter',
65+
value: function selectWriter(knownWriters) {
66+
throw new Error('Abstract function');
67+
}
68+
}]);
69+
return LoadBalancingStrategy;
70+
}();
71+
72+
exports.default = LoadBalancingStrategy;

0 commit comments

Comments
 (0)