@@ -23,6 +23,8 @@ import Session from '../session';
2323import RoutingTable from './routing-table' ;
2424import Rediscovery from './rediscovery' ;
2525import RoutingUtil from './routing-util' ;
26+ import { HostNameResolver } from './node' ;
27+ import { flatMap } from 'lodash/collection' ;
2628
2729const UNAUTHORIZED_ERROR_CODE = 'Neo.ClientError.Security.Unauthorized' ;
2830
@@ -45,38 +47,40 @@ class ConnectionProvider {
4547
4648export class DirectConnectionProvider extends ConnectionProvider {
4749
48- constructor ( hostPort , connectionPool , driverOnErrorCallback ) {
50+ constructor ( address , connectionPool , driverOnErrorCallback ) {
4951 super ( ) ;
50- this . _hostPort = hostPort ;
52+ this . _address = address ;
5153 this . _connectionPool = connectionPool ;
5254 this . _driverOnErrorCallback = driverOnErrorCallback ;
5355 }
5456
5557 acquireConnection ( mode ) {
56- const connectionPromise = this . _connectionPool . acquire ( this . _hostPort ) ;
58+ const connectionPromise = this . _connectionPool . acquire ( this . _address ) ;
5759 return this . _withAdditionalOnErrorCallback ( connectionPromise , this . _driverOnErrorCallback ) ;
5860 }
5961}
6062
6163export class LoadBalancer extends ConnectionProvider {
6264
63- constructor ( hostPort , routingContext , connectionPool , loadBalancingStrategy , hostNameResolver , driverOnErrorCallback , log ) {
65+ constructor ( address , routingContext , connectionPool , loadBalancingStrategy , hostNameResolver , driverOnErrorCallback , log ) {
6466 super ( ) ;
65- this . _seedRouter = hostPort ;
67+ this . _seedRouter = address ;
6668 this . _routingTable = new RoutingTable ( [ this . _seedRouter ] ) ;
6769 this . _rediscovery = new Rediscovery ( new RoutingUtil ( routingContext ) ) ;
6870 this . _connectionPool = connectionPool ;
6971 this . _driverOnErrorCallback = driverOnErrorCallback ;
7072 this . _loadBalancingStrategy = loadBalancingStrategy ;
7173 this . _hostNameResolver = hostNameResolver ;
74+ this . _dnsResolver = new HostNameResolver ( ) ;
7275 this . _log = log ;
7376 this . _useSeedRouter = false ;
7477 }
7578
7679 acquireConnection ( accessMode ) {
80+ let that = this ;
7781 const connectionPromise = this . _freshRoutingTable ( accessMode ) . then ( routingTable => {
7882 if ( accessMode === READ ) {
79- const address = this . _loadBalancingStrategy . selectReader ( routingTable . readers ) ;
83+ const address = that . _loadBalancingStrategy . selectReader ( routingTable . readers ) ;
8084 return this . _acquireConnectionToServer ( address , 'read' ) ;
8185 } else if ( accessMode === WRITE ) {
8286 const address = this . _loadBalancingStrategy . selectWriter ( routingTable . writers ) ;
@@ -173,14 +177,26 @@ export class LoadBalancer extends ConnectionProvider {
173177 }
174178
175179 _fetchRoutingTableUsingSeedRouter ( seenRouters , seedRouter ) {
176- const resolvedAddresses = this . _hostNameResolver . resolve ( seedRouter ) ;
180+ const resolvedAddresses = this . _resolveSeedRouter ( seedRouter ) ;
177181 return resolvedAddresses . then ( resolvedRouterAddresses => {
178182 // filter out all addresses that we've already tried
179183 const newAddresses = resolvedRouterAddresses . filter ( address => seenRouters . indexOf ( address ) < 0 ) ;
180184 return this . _fetchRoutingTable ( newAddresses , null ) ;
181185 } ) ;
182186 }
183187
188+ _resolveSeedRouter ( seedRouter ) {
189+ const customResolution = this . _hostNameResolver . resolve ( seedRouter ) ;
190+ const dnsResolutions = customResolution . then ( resolvedAddresses => {
191+ return Promise . all ( resolvedAddresses . map ( address => {
192+ return this . _dnsResolver . resolve ( address ) ;
193+ } ) ) ;
194+ } ) ;
195+ return dnsResolutions . then ( results => {
196+ return [ ] . concat . apply ( [ ] , results ) ;
197+ } ) ;
198+ }
199+
184200 _fetchRoutingTable ( routerAddresses , routingTable ) {
185201 return routerAddresses . reduce ( ( refreshedTablePromise , currentRouter , currentIndex ) => {
186202 return refreshedTablePromise . then ( newRoutingTable => {
0 commit comments