Skip to content

Move Pool module to core #1212

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Aug 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@
*/

import { createChannelConnection, ConnectionErrorHandler } from '../connection'
import Pool, { PoolConfig } from '../pool'
import { error, ConnectionProvider, ServerInfo, newError } from 'neo4j-driver-core'
import { error, ConnectionProvider, ServerInfo, newError, internal } from 'neo4j-driver-core'
import AuthenticationProvider from './authentication-provider'
import { object } from '../lang'
import LivenessCheckProvider from './liveness-check-provider'
Expand All @@ -31,6 +30,12 @@ const AUTHENTICATION_ERRORS = [
'Neo.ClientError.Security.Unauthorized'
]

const {
pool: {
Pool, PoolConfig
}
} = internal

export default class PooledConnectionProvider extends ConnectionProvider {
constructor (
{ id, config, log, userAgent, boltAgent, authTokenManager, newPool = (...args) => new Pool(...args) },
Expand Down
1 change: 0 additions & 1 deletion packages/bolt-connection/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,5 @@ export * as bolt from './bolt'
export * as buf from './buf'
export * as channel from './channel'
export * as packstream from './packstream'
export * as pool from './pool'

export * from './connection-provider'
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/

import DirectConnectionProvider from '../../src/connection-provider/connection-provider-direct'
import { Pool } from '../../src/pool'
import { Connection, DelegateConnection } from '../../src/connection'
import { authTokenManagers, internal, newError, ServerInfo, staticAuthTokenManager } from 'neo4j-driver-core'
import AuthenticationProvider from '../../src/connection-provider/authentication-provider'
Expand All @@ -25,7 +24,8 @@ import LivenessCheckProvider from '../../src/connection-provider/liveness-check-

const {
serverAddress: { ServerAddress },
logger: { Logger }
logger: { Logger },
pool: { Pool }
} = internal

describe('#unit DirectConnectionProvider', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ import {
authTokenManagers
} from 'neo4j-driver-core'
import { RoutingTable } from '../../src/rediscovery/'
import { Pool } from '../../src/pool'
import SimpleHostNameResolver from '../../src/channel/browser/browser-host-name-resolver'
import RoutingConnectionProvider from '../../src/connection-provider/connection-provider-routing'
import { DelegateConnection, Connection } from '../../src/connection'
Expand All @@ -37,7 +36,8 @@ import LivenessCheckProvider from '../../src/connection-provider/liveness-check-

const {
serverAddress: { ServerAddress },
logger: { Logger }
logger: { Logger },
pool: { Pool }
} = internal

const { SERVICE_UNAVAILABLE, SESSION_EXPIRED } = error
Expand Down
4 changes: 3 additions & 1 deletion packages/core/src/internal/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import * as serverAddress from './server-address'
import * as resolver from './resolver'
import * as objectUtil from './object-util'
import * as boltAgent from './bolt-agent/index'
import * as pool from './pool'

export {
util,
Expand All @@ -44,5 +45,6 @@ export {
serverAddress,
resolver,
objectUtil,
boltAgent
boltAgent,
pool
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,42 @@ const DEFAULT_MAX_SIZE = 100
const DEFAULT_ACQUISITION_TIMEOUT = 60 * 1000 // 60 seconds

export default class PoolConfig {
constructor (maxSize, acquisitionTimeout) {
public readonly maxSize: number
public readonly acquisitionTimeout: number

constructor (maxSize: number, acquisitionTimeout: number) {
this.maxSize = valueOrDefault(maxSize, DEFAULT_MAX_SIZE)
this.acquisitionTimeout = valueOrDefault(
acquisitionTimeout,
DEFAULT_ACQUISITION_TIMEOUT
)
}

static defaultConfig () {
static defaultConfig (): PoolConfig {
return new PoolConfig(DEFAULT_MAX_SIZE, DEFAULT_ACQUISITION_TIMEOUT)
}

static fromDriverConfig (config) {
const maxSizeConfigured = isConfigured(config.maxConnectionPoolSize)
const maxSize = maxSizeConfigured
static fromDriverConfig (config: { maxConnectionPoolSize?: number, connectionAcquisitionTimeout?: number }): PoolConfig {
const maxSize = isConfigured(config.maxConnectionPoolSize)
? config.maxConnectionPoolSize
: DEFAULT_MAX_SIZE
const acquisitionTimeoutConfigured = isConfigured(

const acquisitionTimeout = isConfigured(
config.connectionAcquisitionTimeout
)
const acquisitionTimeout = acquisitionTimeoutConfigured
? config.connectionAcquisitionTimeout
: DEFAULT_ACQUISITION_TIMEOUT

return new PoolConfig(maxSize, acquisitionTimeout)
}
}

function valueOrDefault (value, defaultValue) {
return value === 0 || value ? value : defaultValue
function valueOrDefault (value: number | undefined, defaultValue: number): number {
return isConfigured(value) ? value : defaultValue
}

function isConfigured (value) {
return value === 0 || value
function isConfigured (value?: number): value is number {
return value === 0 || value != null
}

export { DEFAULT_MAX_SIZE, DEFAULT_ACQUISITION_TIMEOUT }
Loading