@@ -37,10 +37,6 @@ var _session = require('../session');
3737
3838var _session2 = _interopRequireDefault ( _session ) ;
3939
40- var _roundRobinArray = require ( './round-robin-array' ) ;
41-
42- var _roundRobinArray2 = _interopRequireDefault ( _roundRobinArray ) ;
43-
4440var _routingTable = require ( './routing-table' ) ;
4541
4642var _routingTable2 = _interopRequireDefault ( _routingTable ) ;
@@ -61,6 +57,25 @@ var _routingUtil2 = _interopRequireDefault(_routingUtil);
6157
6258function _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+
6479var 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
106104var DirectConnectionProvider = exports . DirectConnectionProvider = function ( _ConnectionProvider ) {
107105 ( 0 , _inherits3 . default ) ( DirectConnectionProvider , _ConnectionProvider ) ;
@@ -131,17 +129,18 @@ var DirectConnectionProvider = exports.DirectConnectionProvider = function (_Con
131129var 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 ;
0 commit comments