Skip to content

Commit 56ff62c

Browse files
committed
Improve naming of variable and properties
To clarify that address being used for connection is not a URL but a host-port string.
1 parent 8a5a2a3 commit 56ff62c

File tree

6 files changed

+37
-37
lines changed

6 files changed

+37
-37
lines changed

src/v1/driver.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -57,16 +57,16 @@ class Driver {
5757
/**
5858
* You should not be calling this directly, instead use {@link driver}.
5959
* @constructor
60-
* @param {string} url
60+
* @param {string} hostPort
6161
* @param {string} userAgent
6262
* @param {object} token
6363
* @param {object} config
6464
* @protected
6565
*/
66-
constructor(url, userAgent, token = {}, config = {}) {
66+
constructor(hostPort, userAgent, token = {}, config = {}) {
6767
sanitizeConfig(config);
6868

69-
this._url = url;
69+
this._hostPort = hostPort;
7070
this._userAgent = userAgent;
7171
this._openSessions = {};
7272
this._sessionIdGenerator = 0;
@@ -117,13 +117,13 @@ class Driver {
117117
* @return {Connection} new connector-api session instance, a low level session API.
118118
* @access private
119119
*/
120-
_createConnection(url, release) {
120+
_createConnection(hostPort, release) {
121121
let sessionId = this._sessionIdGenerator++;
122-
let conn = connect(url, this._config, this._connectionErrorCode());
122+
let conn = connect(hostPort, this._config, this._connectionErrorCode());
123123
let streamObserver = new _ConnectionStreamObserver(this, conn);
124124
conn.initialize(this._userAgent, this._token, streamObserver);
125125
conn._id = sessionId;
126-
conn._release = () => release(url, conn);
126+
conn._release = () => release(hostPort, conn);
127127

128128
this._openSessions[sessionId] = conn;
129129
return conn;
@@ -186,8 +186,8 @@ class Driver {
186186
}
187187

188188
// Extension point
189-
_createConnectionProvider(address, connectionPool, driverOnErrorCallback) {
190-
return new DirectConnectionProvider(address, connectionPool, driverOnErrorCallback);
189+
_createConnectionProvider(hostPort, connectionPool, driverOnErrorCallback) {
190+
return new DirectConnectionProvider(hostPort, connectionPool, driverOnErrorCallback);
191191
}
192192

193193
// Extension point
@@ -204,7 +204,7 @@ class Driver {
204204
_getOrCreateConnectionProvider() {
205205
if (!this._connectionProvider) {
206206
const driverOnErrorCallback = this._driverOnErrorCallback.bind(this);
207-
this._connectionProvider = this._createConnectionProvider(this._url, this._pool, driverOnErrorCallback);
207+
this._connectionProvider = this._createConnectionProvider(this._hostPort, this._pool, driverOnErrorCallback);
208208
}
209209
return this._connectionProvider;
210210
}

src/v1/internal/connection-providers.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -45,24 +45,24 @@ class ConnectionProvider {
4545

4646
export class DirectConnectionProvider extends ConnectionProvider {
4747

48-
constructor(address, connectionPool, driverOnErrorCallback) {
48+
constructor(hostPort, connectionPool, driverOnErrorCallback) {
4949
super();
50-
this._address = address;
50+
this._hostPort = hostPort;
5151
this._connectionPool = connectionPool;
5252
this._driverOnErrorCallback = driverOnErrorCallback;
5353
}
5454

5555
acquireConnection(mode) {
56-
const connectionPromise = this._connectionPool.acquire(this._address);
56+
const connectionPromise = this._connectionPool.acquire(this._hostPort);
5757
return this._withAdditionalOnErrorCallback(connectionPromise, this._driverOnErrorCallback);
5858
}
5959
}
6060

6161
export class LoadBalancer extends ConnectionProvider {
6262

63-
constructor(address, routingContext, connectionPool, loadBalancingStrategy, driverOnErrorCallback) {
63+
constructor(hostPort, routingContext, connectionPool, loadBalancingStrategy, driverOnErrorCallback) {
6464
super();
65-
this._seedRouter = address;
65+
this._seedRouter = hostPort;
6666
this._routingTable = new RoutingTable([this._seedRouter]);
6767
this._rediscovery = new Rediscovery(new RoutingUtil(routingContext));
6868
this._connectionPool = connectionPool;

src/v1/internal/connector.js

+10-10
Original file line numberDiff line numberDiff line change
@@ -97,17 +97,17 @@ class Connection {
9797
/**
9898
* @constructor
9999
* @param {NodeChannel|WebSocketChannel} channel - channel with a 'write' function and a 'onmessage' callback property.
100-
* @param {string} url - the hostname and port to connect to.
100+
* @param {string} hostPort - the hostname and port to connect to.
101101
* @param {boolean} disableLosslessIntegers if this connection should convert all received integers to native JS numbers.
102102
*/
103-
constructor(channel, url, disableLosslessIntegers = false) {
103+
constructor(channel, hostPort, disableLosslessIntegers = false) {
104104
/**
105105
* An ordered queue of observers, each exchange response (zero or more
106106
* RECORD messages followed by a SUCCESS message) we receive will be routed
107107
* to the next pending observer.
108108
*/
109-
this.url = url;
110-
this.server = {address: url};
109+
this.hostPort = hostPort;
110+
this.server = {address: hostPort};
111111
this.creationTimestamp = Date.now();
112112
this._disableLosslessIntegers = disableLosslessIntegers;
113113
this._pendingObservers = [];
@@ -517,18 +517,18 @@ class ConnectionState {
517517
}
518518

519519
/**
520-
* Crete new connection to the provided url.
520+
* Crete new connection to the provided address.
521521
* @access private
522-
* @param {string} url - 'neo4j'-prefixed URL to Neo4j Bolt endpoint
522+
* @param {string} hostPort - the Bolt endpoint to connect to
523523
* @param {object} config - this driver configuration
524524
* @param {string=null} connectionErrorCode - error code for errors raised on connection errors
525525
* @return {Connection} - New connection
526526
*/
527-
function connect(url, config = {}, connectionErrorCode = null) {
527+
function connect(hostPort, config = {}, connectionErrorCode = null) {
528528
const Ch = config.channel || Channel;
529-
const parsedUrl = urlUtil.parseDatabaseUrl(url);
530-
const channelConfig = new ChannelConfig(parsedUrl, config, connectionErrorCode);
531-
return new Connection(new Ch(channelConfig), parsedUrl.hostAndPort, config.disableLosslessIntegers);
529+
const parsedAddress = urlUtil.parseDatabaseUrl(hostPort);
530+
const channelConfig = new ChannelConfig(parsedAddress, config, connectionErrorCode);
531+
return new Connection(new Ch(channelConfig), parsedAddress.hostAndPort, config.disableLosslessIntegers);
532532
}
533533

534534
export {

src/v1/internal/http/http-driver.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,13 @@ import HttpSessionTracker from './http-session-tracker';
2323

2424
export default class HttpDriver extends Driver {
2525

26-
constructor(url, userAgent, token, config) {
27-
super(url, userAgent, token, config);
26+
constructor(hostPort, userAgent, token, config) {
27+
super(hostPort, userAgent, token, config);
2828
this._sessionTracker = new HttpSessionTracker();
2929
}
3030

3131
session() {
32-
return new HttpSession(this._url, this._token, this._config, this._sessionTracker);
32+
return new HttpSession(this._hostPort, this._token, this._config, this._sessionTracker);
3333
}
3434

3535
close() {

src/v1/routing-driver.js

+9-9
Original file line numberDiff line numberDiff line change
@@ -25,19 +25,19 @@ import LeastConnectedLoadBalancingStrategy, {LEAST_CONNECTED_STRATEGY_NAME} from
2525
import RoundRobinLoadBalancingStrategy, {ROUND_ROBIN_STRATEGY_NAME} from './internal/round-robin-load-balancing-strategy';
2626

2727
/**
28-
* A driver that supports routing in a core-edge cluster.
28+
* A driver that supports routing in a causal cluster.
2929
* @private
3030
*/
3131
class RoutingDriver extends Driver {
3232

33-
constructor(url, routingContext, userAgent, token = {}, config = {}) {
34-
super(url, userAgent, token, validateConfig(config));
33+
constructor(hostPort, routingContext, userAgent, token = {}, config = {}) {
34+
super(hostPort, userAgent, token, validateConfig(config));
3535
this._routingContext = routingContext;
3636
}
3737

38-
_createConnectionProvider(address, connectionPool, driverOnErrorCallback) {
38+
_createConnectionProvider(hostPort, connectionPool, driverOnErrorCallback) {
3939
const loadBalancingStrategy = RoutingDriver._createLoadBalancingStrategy(this._config, connectionPool);
40-
return new LoadBalancer(address, this._routingContext, connectionPool, loadBalancingStrategy, driverOnErrorCallback);
40+
return new LoadBalancer(hostPort, this._routingContext, connectionPool, loadBalancingStrategy, driverOnErrorCallback);
4141
}
4242

4343
_createSession(mode, connectionProvider, bookmark, config) {
@@ -47,14 +47,14 @@ class RoutingDriver extends Driver {
4747
return error;
4848
}
4949

50-
const url = conn.url;
50+
const hostPort = conn.hostPort;
5151

5252
if (error.code === SESSION_EXPIRED || isDatabaseUnavailable(error)) {
53-
this._connectionProvider.forget(url);
53+
this._connectionProvider.forget(hostPort);
5454
return error;
5555
} else if (isFailureToWrite(error)) {
56-
this._connectionProvider.forgetWriter(url);
57-
return newError('No longer possible to write to server at ' + url, SESSION_EXPIRED);
56+
this._connectionProvider.forgetWriter(hostPort);
57+
return newError('No longer possible to write to server at ' + hostPort, SESSION_EXPIRED);
5858
} else {
5959
return error;
6060
}

test/v1/session.test.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -1124,7 +1124,7 @@ describe('session', () => {
11241124

11251125
function idleConnectionCount(driver) {
11261126
const connectionProvider = driver._connectionProvider;
1127-
const address = connectionProvider._address;
1127+
const address = connectionProvider._hostPort;
11281128
const connectionPool = connectionProvider._connectionPool;
11291129
const idleConnections = connectionPool._pools[address];
11301130
return idleConnections.length;

0 commit comments

Comments
 (0)