@ThreadSafe public class PooledQldbDriver extends Object
QldbDriver
should be
the main entry points to any interaction with QLDB. getSession()
will create a PooledQldbSession
to the
specified ledger within QLDB as a communication channel. Any acquired sessions must be cleaned up with
PooledQldbSession.close()
when they are no longer needed in order to return the session to the pool. If this is not
done, this driver may become unusable if the pool limit is exceeded.
This factory pools sessions and attempts to return unused but available sessions when getting new sessions. The advantage to
using this over the non-pooling driver is that the underlying connection that sessions use to communicate with QLDB can be
recycled, minimizing resource usage by preventing unnecessary connections and reducing latency by not making unnecessary
requests to start new connections and end reusable, existing, ones.
The pool does not remove stale sessions until a new session is retrieved. The default pool size is the maximum amount of
connections the session client allows. close()
should be called when this factory is no longer needed in order to
clean up resources, ending all sessions in the pool.
This object is thread-safe.Modifier and Type | Class and Description |
---|---|
static class |
PooledQldbDriver.PooledQldbDriverBuilder
Builder object for creating a
PooledQldbSession , allowing for configuration of the parameters of construction. |
Modifier and Type | Field and Description |
---|---|
protected com.amazonaws.services.qldbsession.AmazonQLDBSession |
amazonQldbSession |
protected ExecutorService |
executorService |
protected com.amazon.ion.IonSystem |
ionSystem |
protected AtomicBoolean |
isClosed |
protected String |
ledgerName |
protected int |
readAhead |
protected int |
retryLimit |
Modifier | Constructor and Description |
---|---|
protected |
PooledQldbDriver(String ledgerName,
com.amazonaws.services.qldbsession.AmazonQLDBSession client,
int retryLimit,
int readAhead,
int poolLimit,
long timeout,
com.amazon.ion.IonSystem ionSystem,
ExecutorService executorService) |
Modifier and Type | Method and Description |
---|---|
static PooledQldbDriver.PooledQldbDriverBuilder |
builder()
Retrieve a builder object for creating a
PooledQldbDriver . |
void |
close() |
QldbSession |
getSession()
Get a
QldbSession object. |
protected final int readAhead
protected final String ledgerName
protected final int retryLimit
protected final com.amazonaws.services.qldbsession.AmazonQLDBSession amazonQldbSession
protected final com.amazon.ion.IonSystem ionSystem
protected final ExecutorService executorService
protected final AtomicBoolean isClosed
protected PooledQldbDriver(String ledgerName, com.amazonaws.services.qldbsession.AmazonQLDBSession client, int retryLimit, int readAhead, int poolLimit, long timeout, com.amazon.ion.IonSystem ionSystem, ExecutorService executorService)
public static PooledQldbDriver.PooledQldbDriverBuilder builder()
PooledQldbDriver
.PooledQldbDriver
.public void close()
close
in interface AutoCloseable
public QldbSession getSession()
QldbSession
object.
This will attempt to retrieve an active existing session, or it will start a new session with QLDB unless the number of
allocated sessions has exceeded the pool size limit. If so, then it will continue trying to retrieve an active existing
session until the timeout is reached, throwing a QldbClientException
;QldbSession
object.IllegalStateException
- if this driver has been closed.QldbClientException
- if a timeout is reached while attempting to retrieve a session.com.amazonaws.AmazonClientException
- if there is an error communicating with QLDB.