Modifier and Type | Method and Description |
---|---|
Config |
build()
Create a config instance from this builder.
|
Config.ConfigBuilder |
withConnectionAcquisitionTimeout(long value,
TimeUnit unit)
Configure maximum amount of time connection acquisition will attempt to acquire a connection from the
connection pool.
|
Config.ConfigBuilder |
withConnectionLivenessCheckTimeout(long value,
TimeUnit unit)
Pooled connections that have been idle in the pool for longer than this timeout
will be tested before they are used again, to ensure they are still live.
|
Config.ConfigBuilder |
withConnectionTimeout(long value,
TimeUnit unit)
Specify socket connection timeout.
|
Config.ConfigBuilder |
withDriverMetrics()
Enable driver metrics.
|
Config.ConfigBuilder |
withEncryption()
Set to use encrypted traffic.
|
Config.ConfigBuilder |
withEventLoopThreads(int size)
Configure the event loop thread count.
|
Config.ConfigBuilder |
withFetchSize(long size)
Specify how many records to fetch in each batch.
|
Config.ConfigBuilder |
withLeakedSessionsLogging()
Enable logging of leaked sessions.
|
Config.ConfigBuilder |
withLogging(Logging logging)
Provide a logging implementation for the driver to use.
|
Config.ConfigBuilder |
withMaxConnectionLifetime(long value,
TimeUnit unit)
Pooled connections older than this threshold will be closed and removed from the pool.
|
Config.ConfigBuilder |
withMaxConnectionPoolSize(int value)
Configure maximum amount of connections in the connection pool towards a single database.
|
Config.ConfigBuilder |
withMaxTransactionRetryTime(long value,
TimeUnit unit)
Specify the maximum time transactions are allowed to retry via
Session.readTransaction(TransactionWork) and Session.writeTransaction(TransactionWork)
methods. |
Config.ConfigBuilder |
withoutDriverMetrics()
Disable driver metrics.
|
Config.ConfigBuilder |
withoutEncryption()
Set to use unencrypted traffic.
|
Config.ConfigBuilder |
withResolver(ServerAddressResolver resolver)
Specify a custom server address resolver used by the routing driver to resolve the initial address used to create the driver.
|
Config.ConfigBuilder |
withRoutingFailureLimit(int routingFailureLimit)
Deprecated.
in 1.2 because driver memorizes seed URI used during construction and falls back to it at
runtime when all other known router servers failed to respond. Driver is also able to perform DNS lookup
for the seed URI during rediscovery. This means updates of cluster members will be picked up if they are
reflected in a DNS record. This configuration allowed driver to retry rediscovery procedure and postpone
failure. Currently there exists a better way of doing retries via
Session.readTransaction(TransactionWork) and Session.writeTransaction(TransactionWork) .
Method will be removed in the next major release. |
Config.ConfigBuilder |
withRoutingRetryDelay(long delay,
TimeUnit unit)
Deprecated.
in 1.2 because driver memorizes seed URI used during construction and falls back to it at
runtime when all other known router servers failed to respond. Driver is also able to perform DNS lookup
for the seed URI during rediscovery. This means updates of cluster members will be picked up if they are
reflected in a DNS record. This configuration allowed driver to retry rediscovery procedure and postpone
failure. Currently there exists a better way of doing retries via
Session.readTransaction(TransactionWork) and Session.writeTransaction(TransactionWork) .
Method will be removed in the next major release. |
Config.ConfigBuilder |
withRoutingTablePurgeDelay(long delay,
TimeUnit unit)
Specify how long to wait before purging stale routing tables.
|
Config.ConfigBuilder |
withTrustStrategy(Config.TrustStrategy trustStrategy)
Specify how to determine the authenticity of an encryption certificate provided by the Neo4j instance we are connecting to.
|
Config.ConfigBuilder |
withUserAgent(String userAgent)
Configure the user_agent field sent to the server to identify the connected client.
|
public Config.ConfigBuilder withLogging(Logging logging)
java.util.logging
with Level.INFO
is used by default.
Callers are expected to either implement Logging
interface or provide one of the existing implementations available from static factory
methods in the Logging
interface.
Please see documentation in Logging
for more information.
logging
- the logging instance to useLogging
public Config.ConfigBuilder withLeakedSessionsLogging()
Each session
is associated with a network connection and thus is a
resource
that needs to be explicitly closed.
Unclosed sessions will result in socket leaks and could cause OutOfMemoryError
s.
Session is considered to be leaked when it is finalized via Object.finalize()
while not being
closed. This option turns on logging of such sessions and stacktraces of where they were created.
Note: this option should mostly be used in testing environments for session leak investigations. Enabling it will add object finalization overhead.
public Config.ConfigBuilder withConnectionLivenessCheckTimeout(long value, TimeUnit unit)
If this option is set too low, an additional network call will be incurred when acquiring a connection, which causes a performance hit.
If this is set high, you may receive sessions that are backed by no longer live connections, which will lead to exceptions in your application. Assuming the database is running, these exceptions will go away if you retry acquiring sessions.
Hence, this parameter tunes a balance between the likelihood of your application seeing connection problems, and performance.
You normally should not need to tune this parameter.
No connection liveliness check is done by default.
Value 0
means connections will always be tested for
validity and negative values mean connections will never be tested.
value
- the minimum idle timeunit
- the unit in which the duration is givenpublic Config.ConfigBuilder withMaxConnectionLifetime(long value, TimeUnit unit)
Setting this option to a low value will cause a high connection churn and might result in a performance hit.
It is recommended to set maximum lifetime to a slightly smaller value than the one configured in network equipment (load balancer, proxy, firewall, etc. can also limit maximum connection lifetime).
Setting can also be used in combination with withConnectionLivenessCheckTimeout(long, TimeUnit)
. In
this case, it is recommended to set liveness check to a value smaller than network equipment has and maximum
lifetime to a reasonably large value to "renew" connections once in a while.
Default maximum connection lifetime is 1 hour. Zero and negative values result in lifetime not being checked.
value
- the maximum connection lifetimeunit
- the unit in which the duration is givenpublic Config.ConfigBuilder withMaxConnectionPoolSize(int value)
Acquisition will be attempted for at most configured timeout
withConnectionAcquisitionTimeout(long, TimeUnit)
when limit is reached.
Default value is 100
. Negative values are allowed and result in unlimited pool. Value of 0
is not allowed.
value
- the maximum connection pool size.withConnectionAcquisitionTimeout(long, TimeUnit)
public Config.ConfigBuilder withConnectionAcquisitionTimeout(long value, TimeUnit unit)
Exception is raised when connection can't be acquired within configured time.
Default value is 60 seconds. Negative values are allowed and result in unlimited acquisition timeout. Value
of 0
is allowed and results in no timeout and immediate failure when connection is unavailable.
value
- the acquisition timeoutunit
- the unit in which the duration is givenwithMaxConnectionPoolSize(int)
public Config.ConfigBuilder withEncryption()
public Config.ConfigBuilder withoutEncryption()
public Config.ConfigBuilder withTrustStrategy(Config.TrustStrategy trustStrategy)
Config.TrustStrategy.trustSystemCertificates()
. See Config.TrustStrategy.trustCustomCertificateSignedBy(File)
for using certificate signatures instead to
verify trust.
This is an important setting to understand, because unless we know that the remote server we have an encrypted connection to is really Neo4j, there is no point to encrypt at all, since anyone could pretend to be the remote Neo4j instance.
For this reason, there is no option to disable trust verification. However, it is possible to turn off encryption using the withoutEncryption()
option.
trustStrategy
- TLS authentication strategy@Deprecated public Config.ConfigBuilder withRoutingFailureLimit(int routingFailureLimit)
Session.readTransaction(TransactionWork)
and Session.writeTransaction(TransactionWork)
.
Method will be removed in the next major release.The routing servers are tried in order. If connecting any of them fails, they are all retried after a delay. This process of retrying all servers is then repeated for the number of times specified here before considering the cluster unavailable.
The default value of this parameter is 1
, which means that the the driver will not re-attempt to
connect to the cluster when connecting has failed to each individual server in the list of routers. This
default value is sensible under this assumption that if the attempt to connect fails for all servers, then
the entire cluster is down, or the client is disconnected from the network, and retrying to connect will
not bring it back up, in which case it is better to report the failure sooner.
routingFailureLimit
- the number of times to retry each server in the list of routing servers@Deprecated public Config.ConfigBuilder withRoutingRetryDelay(long delay, TimeUnit unit)
Session.readTransaction(TransactionWork)
and Session.writeTransaction(TransactionWork)
.
Method will be removed in the next major release.When connecting to all routing servers fail, connecting will be retried after the delay specified here. The delay is measured from when the first attempt to connect was made, so that the delay time specifies a retry interval.
For each retry attempt the delay time will be doubled. The time
specified here is the base time, i.e. the time to wait before the first retry. If that attempt (on all
servers) also fails, the delay before the next retry will be double the time specified here, and the next
attempt after that will be double that, et.c. So if, for example, the delay specified here is
5 SECONDS
, then after attempting to connect to each server fails reconnecting will be attempted
5 seconds after the first connection attempt to the first server. If that attempt also fails to connect to
all servers, the next attempt will start 10 seconds after the second attempt started.
The default value of this parameter is 5 SECONDS
.
delay
- the amount of time between attempts to reconnect to the same serverunit
- the unit in which the duration is givenpublic Config.ConfigBuilder withRoutingTablePurgeDelay(long delay, TimeUnit unit)
When a routing table is timed out, the routing table will be marked ready to remove after the delay specified here. Driver keeps a routing table for each database seen by the driver. The routing table of a database get refreshed if the database is used frequently. If the database is not used for a long time, the driver use the timeout specified here to purge the stale routing table. After a routing table is removed, next time when using the database of the purged routing table, the driver will fall back to use seed URI for a new routing table.
delay
- the amount of time to wait before purging routing tablesunit
- the unit in which the duration is givenpublic Config.ConfigBuilder withFetchSize(long size)
Session
and AsyncSession
.
By default, the value is set to 1000
.
Use -1
to disables back pressure and config client to pull all records at once after each run.
This config only applies to run result obtained via Session
and AsyncSession
.
As with RxSession
, the batch size is provided via
Subscription.request(long)
instead.size
- the default record fetch size when pulling records in batches using Bolt V4.public Config.ConfigBuilder withConnectionTimeout(long value, TimeUnit unit)
A timeout of zero is treated as an infinite timeout and will be bound by the timeout configured on the operating system level. The connection will block until established or an error occurs.
Timeout value should be greater or equal to zero and represent a valid int
value when converted to
milliseconds
.
The default value of this parameter is 30 SECONDS
.
value
- the timeout durationunit
- the unit in which duration is givenIllegalArgumentException
- when given value is negative or does not fit in int
when
converted to milliseconds.public Config.ConfigBuilder withMaxTransactionRetryTime(long value, TimeUnit unit)
Session.readTransaction(TransactionWork)
and Session.writeTransaction(TransactionWork)
methods. These methods will retry the given unit of work on ServiceUnavailableException
,
SessionExpiredException
and TransientException
with
exponential backoff using initial delay of 1 second.
Default value is 30 seconds.
value
- the timeout durationunit
- the unit in which duration is givenIllegalArgumentException
- when given value is negativepublic Config.ConfigBuilder withResolver(ServerAddressResolver resolver)
InetAddress.getAllByName(String)
.resolver
- the resolver to use.NullPointerException
- when the given resolver is null
.public Config.ConfigBuilder withDriverMetrics()
Driver.metrics()
.public Config.ConfigBuilder withoutDriverMetrics()
Driver.metrics()
.public Config.ConfigBuilder withEventLoopThreads(int size)
size
- the thread count.IllegalArgumentException
- if the value of the size is set to a number that is less than 1.public Config.ConfigBuilder withUserAgent(String userAgent)
userAgent
- the string to configure user_agent.