Class LedgerClientPool
- All Implemented Interfaces:
Closeable,AutoCloseable
One LedgerClient owns one socket and serialises a complete
request/response exchange on it (the wire has no correlation id, so it must).
Concurrency therefore comes from connections, not threads: eight threads
sharing one client take turns; eight threads over a pool of eight do not.
Members are leader-aware SmartLedgerClient instances and honour the
same routing override, so a pool can be pinned to one node exactly like a
single client.
Operations this class does not define are reached with withClient(com.tuladb.LedgerClientPool.ClientCall<T>):
try (LedgerClientPool pool = new LedgerClientPool("ledger://n1:7700,n2:7700", 16, 30_000)) {
Balance b = pool.withClient(c -> c.getBalance(AccountKey.of(1, 840, accountId)));
List<TransferResult> r = pool.transferBatch(transfers); // sharded across members
}
-
Nested Class Summary
Nested Classes -
Constructor Summary
ConstructorsConstructorDescriptionLedgerClientPool(String connectionString, int size, int timeoutMs) LedgerClientPool(List<SmartLedgerClient.NodeEndpoint> nodes, int size, int timeoutMs, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, int pipelineDepth, long acquireTimeoutMs) LedgerClientPool(List<SmartLedgerClient.NodeEndpoint> nodes, int size, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, int pipelineDepth, long acquireTimeoutMs) As above, with separate connect / read / write timeouts (null = defaults).LedgerClientPool(List<SmartLedgerClient.NodeEndpoint> nodes, int size, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, int pipelineDepth, long acquireTimeoutMs, Auth auth) As above, authenticating every member connection with MSG_AUTH (Auth; null = anonymous). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()commitBatch(List<String> transferIds) commitBatch(List<String> transferIds, int depth, int workers) members()intreserveBatch(List<Models.TransferCreate> transfers) reserveBatch(List<Models.TransferCreate> transfers, int depth, int workers) rollbackBatch(List<String> transferIds) rollbackBatch(List<String> transferIds, int depth, int workers) voidsetDefaultFlags(short flags) voidBackoff between a member's retries; seeSmartLedgerClient.setRetryPolicy(com.tuladb.SmartLedgerClient.RetryPolicy).intsize()tieredCommitBatch(List<String> transferIds) tieredCommitBatch(List<String> transferIds, int depth, int workers) tieredReserveBatch(List<Models.TieredTransferCreate> transfers) tieredReserveBatch(List<Models.TieredTransferCreate> transfers, int depth, int workers) tieredRollbackBatch(List<String> transferIds) tieredRollbackBatch(List<String> transferIds, int depth, int workers) tieredTransferBatch(List<Models.TieredTransferCreate> transfers) tieredTransferBatch(List<Models.TieredTransferCreate> transfers, int depth, int workers) transferBatch(List<Models.TransferCreate> transfers) transferBatch(List<Models.TransferCreate> transfers, int depth, int workers) booleanThe id-size rule every connection in this pool uses.<T> TwithClient(LedgerClientPool.ClientCall<T> call) Borrow one member for the duration ofcall.
-
Constructor Details
-
LedgerClientPool
- Throws:
IOException
-
LedgerClientPool
public LedgerClientPool(List<SmartLedgerClient.NodeEndpoint> nodes, int size, int timeoutMs, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, int pipelineDepth, long acquireTimeoutMs) throws IOException - Throws:
IOException
-
LedgerClientPool
public LedgerClientPool(List<SmartLedgerClient.NodeEndpoint> nodes, int size, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, int pipelineDepth, long acquireTimeoutMs) throws IOException As above, with separate connect / read / write timeouts (null = defaults).- Throws:
IOException
-
LedgerClientPool
public LedgerClientPool(List<SmartLedgerClient.NodeEndpoint> nodes, int size, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, int pipelineDepth, long acquireTimeoutMs, Auth auth) throws IOException As above, authenticating every member connection with MSG_AUTH (Auth; null = anonymous).- Throws:
IOException
-
-
Method Details
-
size
public int size() -
pipelineDepth
public int pipelineDepth() -
members
-
setDefaultFlags
public void setDefaultFlags(short flags) -
setRetryPolicy
Backoff between a member's retries; seeSmartLedgerClient.setRetryPolicy(com.tuladb.SmartLedgerClient.RetryPolicy). -
withClient
Borrow one member for the duration ofcall.Exclusive: a pipelined window must own its connection from the first frame to the last response, and a borrowed member cannot be handed to another caller mid-window.
Do not call this pool's sharded batch methods from inside
call: the shards need connections this caller is already holding one of, and with no acquire timeout configured the shard would wait for it forever.- Throws:
IOException
-
transferBatch
public List<Models.TransferResult> transferBatch(List<Models.TransferCreate> transfers) throws IOException - Throws:
IOException
-
transferBatch
public List<Models.TransferResult> transferBatch(List<Models.TransferCreate> transfers, int depth, int workers) throws IOException - Throws:
IOException
-
reserveBatch
public List<Models.TransferResult> reserveBatch(List<Models.TransferCreate> transfers) throws IOException - Throws:
IOException
-
reserveBatch
public List<Models.TransferResult> reserveBatch(List<Models.TransferCreate> transfers, int depth, int workers) throws IOException - Throws:
IOException
-
commitBatch
- Throws:
IOException
-
commitBatch
public List<Models.TransferResult> commitBatch(List<String> transferIds, int depth, int workers) throws IOException - Throws:
IOException
-
rollbackBatch
- Throws:
IOException
-
rollbackBatch
public List<Models.TransferResult> rollbackBatch(List<String> transferIds, int depth, int workers) throws IOException - Throws:
IOException
-
tieredTransferBatch
public List<Models.TieredTransferResult> tieredTransferBatch(List<Models.TieredTransferCreate> transfers) throws IOException - Throws:
IOException
-
tieredTransferBatch
public List<Models.TieredTransferResult> tieredTransferBatch(List<Models.TieredTransferCreate> transfers, int depth, int workers) throws IOException - Throws:
IOException
-
tieredReserveBatch
public List<Models.TieredTransferResult> tieredReserveBatch(List<Models.TieredTransferCreate> transfers) throws IOException - Throws:
IOException
-
tieredReserveBatch
public List<Models.TieredTransferResult> tieredReserveBatch(List<Models.TieredTransferCreate> transfers, int depth, int workers) throws IOException - Throws:
IOException
-
tieredCommitBatch
public List<Models.TieredTransferResult> tieredCommitBatch(List<String> transferIds) throws IOException - Throws:
IOException
-
tieredCommitBatch
public List<Models.TieredTransferResult> tieredCommitBatch(List<String> transferIds, int depth, int workers) throws IOException - Throws:
IOException
-
tieredRollbackBatch
public List<Models.TieredTransferResult> tieredRollbackBatch(List<String> transferIds) throws IOException - Throws:
IOException
-
tieredRollbackBatch
public List<Models.TieredTransferResult> tieredRollbackBatch(List<String> transferIds, int depth, int workers) throws IOException - Throws:
IOException
-
useIso20022RefSize
public boolean useIso20022RefSize()The id-size rule every connection in this pool uses. -
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-