public static final class NonBlockingConnectionPool.Builder<T>
extends java.lang.Object
Constructor and Description |
---|
Builder(java.util.function.Function<NonBlockingConnectionPool,T> transform) |
Modifier and Type | Method and Description |
---|---|
T |
build() |
NonBlockingConnectionPool.Builder<T> |
connectionListener(io.reactivex.functions.Consumer<? super java.util.Optional<java.lang.Throwable>> c)
Sets a listener for connection success and failure.
|
NonBlockingConnectionPool.Builder<T> |
connectionProvider(ConnectionProvider cp)
Sets the provider of
Connection objects to be used by the pool. |
NonBlockingConnectionPool.Builder<T> |
connectionProvider(javax.sql.DataSource ds)
Sets the provider of
Connection objects to be used by the pool. |
NonBlockingConnectionPool.Builder<T> |
connectionRetryInterval(long duration,
java.util.concurrent.TimeUnit unit)
Sets the retry interval in the case that creating/reestablishing a
Connection for use in the pool fails. |
NonBlockingConnectionPool.Builder<T> |
healthCheck(DatabaseType databaseType)
Sets the health check for a Connection in the pool that is run only if the
time since the last checkout of this Connection finished is more than
idleTimeBeforeHealthCheck and a checkout of this Connection has just been
requested.
|
NonBlockingConnectionPool.Builder<T> |
healthCheck(io.reactivex.functions.Predicate<? super java.sql.Connection> healthCheck)
Sets the health check for a Connection in the pool that is run only if the
time since the last checkout of this Connection finished is more than
idleTimeBeforeHealthCheck and a checkout of this Connection has just been
requested.
|
NonBlockingConnectionPool.Builder<T> |
healthCheck(java.lang.String sql)
Sets the health check for a Connection in the pool that is run only if the
time since the last checkout of this Connection finished is more than
idleTimeBeforeHealthCheck and a checkout of this Connection has just been
requested.
|
NonBlockingConnectionPool.Builder<T> |
idleTimeBeforeHealthCheck(long duration,
java.util.concurrent.TimeUnit unit)
Sets the minimum time that a connection must be idle (checked in) before on
the next checkout its validity is checked using the health check function.
|
NonBlockingConnectionPool.Builder<T> |
maxIdleTime(long duration,
java.util.concurrent.TimeUnit unit)
Sets the max time a
Connection can be idle (checked in to pool)
before it is released from the pool (the Connection is closed). |
NonBlockingConnectionPool.Builder<T> |
maxPoolSize(int maxPoolSize)
Sets the maximum connection pool size.
|
NonBlockingConnectionPool.Builder<T> |
password(java.lang.String password) |
NonBlockingConnectionPool.Builder<T> |
properties(java.util.Properties properties)
Sets the JDBC properties that will be passed to
DriverManager.getConnection(java.lang.String, java.util.Properties) . |
NonBlockingConnectionPool.Builder<T> |
property(java.lang.Object key,
java.lang.Object value)
Adds the given property specified by key and value to the JDBC properties
that will be passed to
DriverManager.getConnection(java.lang.String, java.util.Properties) . |
NonBlockingConnectionPool.Builder<T> |
scheduler(io.reactivex.Scheduler scheduler)
Sets the scheduler used for emitting connections (must be scheduled to
another thread to break the chain of stack calls otherwise can get
StackOverflowError) and for scheduling timeouts and retries.
|
NonBlockingConnectionPool.Builder<T> |
url(java.lang.String url)
Sets the jdbc url of the
Connection objects to be used by the pool. |
NonBlockingConnectionPool.Builder<T> |
user(java.lang.String user) |
public Builder(java.util.function.Function<NonBlockingConnectionPool,T> transform)
public NonBlockingConnectionPool.Builder<T> connectionProvider(ConnectionProvider cp)
Connection
objects to be used by the pool.cp
- connection providerpublic NonBlockingConnectionPool.Builder<T> connectionProvider(javax.sql.DataSource ds)
Connection
objects to be used by the pool.ds
- dataSource that providers Connectionspublic NonBlockingConnectionPool.Builder<T> url(java.lang.String url)
Connection
objects to be used by the pool.url
- jdbc urlpublic NonBlockingConnectionPool.Builder<T> user(java.lang.String user)
public NonBlockingConnectionPool.Builder<T> password(java.lang.String password)
public NonBlockingConnectionPool.Builder<T> properties(java.util.Properties properties)
DriverManager.getConnection(java.lang.String, java.util.Properties)
. The properties will only be
used if the url
has been set in the builder.properties
- the jdbc propertiespublic NonBlockingConnectionPool.Builder<T> property(java.lang.Object key, java.lang.Object value)
DriverManager.getConnection(java.lang.String, java.util.Properties)
. The
properties will only be used if the url
has been set in the builder.key
- property keyvalue
- property valuepublic NonBlockingConnectionPool.Builder<T> maxIdleTime(long duration, java.util.concurrent.TimeUnit unit)
Connection
can be idle (checked in to pool)
before it is released from the pool (the Connection is closed).duration
- the period before which an idle Connection is released from the
pool (closed).unit
- time unitpublic NonBlockingConnectionPool.Builder<T> idleTimeBeforeHealthCheck(long duration, java.util.concurrent.TimeUnit unit)
duration
- minimum time a connection must be idle before its validity is
checked on checkout from the poolunit
- time unitpublic NonBlockingConnectionPool.Builder<T> connectionRetryInterval(long duration, java.util.concurrent.TimeUnit unit)
Connection
for use in the pool fails.duration
- Connection creation retry intervalunit
- time unitpublic NonBlockingConnectionPool.Builder<T> healthCheck(io.reactivex.functions.Predicate<? super java.sql.Connection> healthCheck)
healthCheck
- check to run on Connection. Returns true if and only if the
Connection is valid/healthy.public NonBlockingConnectionPool.Builder<T> healthCheck(DatabaseType databaseType)
databaseType
- the check to run is chosen based on the database typepublic NonBlockingConnectionPool.Builder<T> healthCheck(java.lang.String sql)
sql
- sql to run to check the validity of the connection. If the sql is
run without error then the connection is assumed healthy.public NonBlockingConnectionPool.Builder<T> connectionListener(io.reactivex.functions.Consumer<? super java.util.Optional<java.lang.Throwable>> c)
RxJavaPlugins.onError
. This consumer should not block
otherwise it will block the connection pool itself.c
- listener for connection eventspublic NonBlockingConnectionPool.Builder<T> maxPoolSize(int maxPoolSize)
maxPoolSize
- maximum number of connections in the poolpublic NonBlockingConnectionPool.Builder<T> scheduler(io.reactivex.Scheduler scheduler)
Schedulers.from(Executors.newFixedThreadPool(maxPoolSize))
. Do not
set the scheduler to Schedulers.trampoline()
because queries will
block waiting for timeout workers. Also, do not use a single-threaded
Scheduler
because you may encounter StackOverflowError
.scheduler
- scheduler to use for emitting connections and for scheduling
timeouts and retries. Defaults to
Schedulers.from(Executors.newFixedThreadPool(maxPoolSize))
.
Do not use Schedulers.trampoline()
.java.lang.IllegalArgumentException
- if trampoline specifiedpublic T build()
Copyright © 2016–2020. All rights reserved.