Package com.tuladb
Class SmartLedgerClient
java.lang.Object
com.tuladb.SmartLedgerClient
- All Implemented Interfaces:
Closeable,AutoCloseable
Leader-aware Ledger client.
Accepts a cluster connection string such as:
ledger://127.0.0.1:7701,127.0.0.1:7702,127.0.0.1:7703
It probes MSG_CLUSTER_STATUS on all endpoints, chooses the endpoint whose
self_id == leader_id, sends writes to that leader, and on a failure that is
not final (transport, leader movement, a non-final server status such as
ERR_CAPACITY) refreshes and retries up to
retryAttempts times with
jittered exponential backoff (see SmartLedgerClient.RetryPolicy).-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordstatic final recordstatic final recordBackoff between retries of one operation, "full jitter":delay(n)is uniform in[0, min(maxDelayMs, initialDelayMs * 2^n)], where n counts the backed-off retries (0 for the first; the one immediate transport / not-leader retry is not counted).static enumHow an operation picks its node. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intRetries after the first attempt (contracts/status-codes.env RETRY_ATTEMPTS).static final longBackoff defaults, from contracts/status-codes.env (RETRY_*_MS).static final longstatic final long -
Constructor Summary
ConstructorsConstructorDescriptionSmartLedgerClient(String connectionString, int timeoutMs) SmartLedgerClient(String connectionString, int timeoutMs, boolean useIso20022RefSize) SmartLedgerClient(String connectionString, int timeoutMs, boolean useIso20022RefSize, int retryAttempts) SmartLedgerClient(String connectionString, int timeoutMs, LedgerClient.TlsOptions tlsOptions) SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs) SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize) SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize, int retryAttempts) SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions) SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode) Full constructor, including the routing override.SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, LedgerClient.TlsOptions tlsOptions) SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode) Full constructor with separate connect / read / write timeouts (seeLedgerClient.Timeouts); null means the defaults (30 s each).SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, Auth auth) As above, authenticating every node connection with MSG_AUTH (Auth; null = anonymous). -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()commitBatch(List<String> transferIds) commitBatch(List<String> transferIds, int depth) As commitBatch, keepingdepthbatch frames in flight on the routed connection.commitByKey(long sourceId, int ledgerId, int currency, String txnId) voidcreateAccount(Models.AccountCreate account) createCurrency(Models.CurrencyInstance request) createLedger(Models.LedgerInstance request) createSource(Models.SourceInstance request) getAccountHistory(Models.AccountKey key, long afterTimestamp, int limit) getBalance(Models.AccountKey key, long minBatchSeq) getCurrency(int numeric) shortInspect the current session-wide default frame flags.getHistory(Models.AccountKey key, long afterSeq, int limit) getHistory(Models.AccountKey key, long afterSeq, int afterIndex, int limit) Paged account history resuming after the composite cursor (afterSeq, afterIndex).getLedger(int ledgerId) getSource(int numeric) getTransaction(String transferId) getTransactionByKey(long sourceId, int ledgerId, int currency, String txnId) getTransactionByTransferId(byte[] transferId) R2-H4: probe the connected daemon's build identity over the wire.voidledgerAddSource(int ledgerId, int sourceNumeric) ledgerListSources(int ledgerId) voidledgerRemoveSource(int ledgerId, int sourceNumeric) listAccountBalances(int ledgerId, long accountHi, long accountLo) listAccounts(int offset, int limit) listPending(long afterSeq, int limit) listRejected(long afterSeq, int limit) listTransfers(long afterSeq, int limit) listTransfersExtended(int maxRecords, int pageLimit, boolean includePending) listWrappedTransactions(int maxRecords, int pageLimit, boolean includePending) nodes()static List<SmartLedgerClient.NodeEndpoint> parseClusterNodes(String connectionString) voidping()intintpromoteStandby(String group) Promote the best caught-up standby learner ingroupto voter, routed to the leader; returns the promoted node id.voidreconfig(byte[] configPayload) Submit a serialised ClusterConfig (Raft ยง4 reconfig), routed to the leader.voidreject(Models.RejectCreate reject) rejectByKey(long sourceId, int currency, String txnId) rejectByKey(long sourceId, int currency, String txnId, long amount) rejectByKey(long sourceId, int currency, String txnId, long amount, int ledgerId, int reasonCode, Object custom) rejectByKey(long sourceId, int currency, String txnId, long amount, int ledgerId, long debitHi, long debitLo, long creditHi, long creditLo, int reasonCode, Object custom) reserve(Models.TransferCreate transfer) reserveBatch(List<Models.TransferCreate> transfers) reserveBatch(List<Models.TransferCreate> transfers, int depth) As reserveBatch, keepingdepthbatch frames in flight on the routed connection.introllbackBatch(List<String> transferIds) rollbackBatch(List<String> transferIds, int depth) As rollbackBatch, keepingdepthbatch frames in flight on the routed connection.rollbackByKey(long sourceId, int ledgerId, int currency, String txnId) The node operations are currently routed to, if one is known.searchTransactions(Models.TxnSearch search) voidsetAccountActive(Models.AccountKey key, boolean active) setCurrencyActive(int numeric, boolean active) voidsetDefaultFlags(short flags) R2-H2: set session-wide default frame flags.voidsetPipelineDepth(int depth) Default batch frames in flight per connection; replayed onto each routed client.voidBackoff between retries (seeSmartLedgerClient.RetryPolicy); null restores the defaults.setSourceActive(int numeric, boolean active) tieredCommit(String transferId) tieredCommitBatch(List<String> transferIds) tieredCommitBatch(List<String> transferIds, int depth) As tieredCommitBatch, keepingdepthbatch frames in flight on the routed connection.tieredCommitByKey(long sourceId, int ledgerId, int currency, String txnId) tieredReserve(Models.TieredTransferCreate transfer) tieredReserveBatch(List<Models.TieredTransferCreate> transfers) tieredReserveBatch(List<Models.TieredTransferCreate> transfers, int depth) As tieredReserveBatch, keepingdepthbatch frames in flight on the routed connection.tieredRollback(String transferId) tieredRollbackBatch(List<String> transferIds) tieredRollbackBatch(List<String> transferIds, int depth) As tieredRollbackBatch, keepingdepthbatch frames in flight on the routed connection.tieredRollbackByKey(long sourceId, int ledgerId, int currency, String txnId) tieredTransfer(Models.TieredTransferCreate transfer) tieredTransferBatch(List<Models.TieredTransferCreate> transfers) tieredTransferBatch(List<Models.TieredTransferCreate> transfers, int depth) As tieredTransferBatch, keepingdepthbatch frames in flight on the routed connection.transfer(Models.TransferCreate transfer) transferBatch(List<Models.TransferCreate> transfers) transferBatch(List<Models.TransferCreate> transfers, int depth) As transferBatch, keepingdepthbatch frames in flight on the routed connection.voidtransferLeadership(int targetNodeId) Gracefully transfer leadership totargetNodeId(Raft ยง3.10), routed to the current leader.voidupdateAccountLimitHigh(Models.AccountKey key, long limitHigh) voidupdateAccountLimitLow(Models.AccountKey key, long limitLow) booleanWhether transfer ids use the ISO 20022 reference size (ids derived by key follow it).
-
Field Details
-
DEFAULT_RETRY_ATTEMPTS
public static final int DEFAULT_RETRY_ATTEMPTSRetries after the first attempt (contracts/status-codes.env RETRY_ATTEMPTS).- See Also:
-
DEFAULT_RETRY_INITIAL_DELAY_MS
public static final long DEFAULT_RETRY_INITIAL_DELAY_MSBackoff defaults, from contracts/status-codes.env (RETRY_*_MS).- See Also:
-
DEFAULT_RETRY_MAX_DELAY_MS
public static final long DEFAULT_RETRY_MAX_DELAY_MS- See Also:
-
DEFAULT_RETRY_MAX_ELAPSED_MS
public static final long DEFAULT_RETRY_MAX_ELAPSED_MS- See Also:
-
-
Constructor Details
-
SmartLedgerClient
- Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(String connectionString, int timeoutMs, boolean useIso20022RefSize) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(String connectionString, int timeoutMs, boolean useIso20022RefSize, int retryAttempts) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize, int retryAttempts) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(String connectionString, int timeoutMs, LedgerClient.TlsOptions tlsOptions) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, LedgerClient.TlsOptions tlsOptions) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions) throws IOException - Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, int timeoutMs, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode) throws IOException Full constructor, including the routing override.- Parameters:
routePolicy- null resolves fromTULADB_ROUTE_POLICY, then defaults toSmartLedgerClient.RoutePolicy.LEADER(orSmartLedgerClient.RoutePolicy.PINNEDwhen a pin is given)pinnedNode- null resolves fromTULADB_PIN_NODE- Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode) throws IOException Full constructor with separate connect / read / write timeouts (seeLedgerClient.Timeouts); null means the defaults (30 s each).- Throws:
IOException
-
SmartLedgerClient
public SmartLedgerClient(List<SmartLedgerClient.NodeEndpoint> nodes, LedgerClient.Timeouts timeouts, boolean useIso20022RefSize, int retryAttempts, LedgerClient.TlsOptions tlsOptions, SmartLedgerClient.RoutePolicy routePolicy, SmartLedgerClient.NodeEndpoint pinnedNode, Auth auth) throws IOException As above, authenticating every node connection with MSG_AUTH (Auth; null = anonymous). Each connection the client opens -- the topology probe included -- sends it first; a refused credential is never retried (LedgerClient.LedgerAuthExceptionis final). The credential is copied; each node connection holds its own copy, zeroed when that connection is discarded (a refresh, a failed route,close()).- Throws:
IOException
-
-
Method Details
-
useIso20022RefSize
public boolean useIso20022RefSize()Whether transfer ids use the ISO 20022 reference size (ids derived by key follow it). -
routePolicy
-
pinnedNode
-
routeEndpoint
The node operations are currently routed to, if one is known. -
pipelineDepth
public int pipelineDepth() -
setPipelineDepth
public void setPipelineDepth(int depth) Default batch frames in flight per connection; replayed onto each routed client. -
parseClusterNodes
-
leaderEndpoint
-
leaderStatus
-
nodes
-
retryAttempts
public int retryAttempts() -
retryPolicy
-
setRetryPolicy
Backoff between retries (seeSmartLedgerClient.RetryPolicy); null restores the defaults. -
endpointStatuses
-
healthyEndpoints
-
refreshLeader
- Throws:
IOException
-
createAccount
- Throws:
IOException
-
transferLeadership
Gracefully transfer leadership totargetNodeId(Raft ยง3.10), routed to the current leader.- Throws:
IOException
-
reconfig
Submit a serialised ClusterConfig (Raft ยง4 reconfig), routed to the leader.- Throws:
IOException
-
promoteStandby
Promote the best caught-up standby learner ingroupto voter, routed to the leader; returns the promoted node id.- Throws:
IOException
-
updateAccountLimitLow
- Throws:
IOException
-
updateAccountLimitHigh
- Throws:
IOException
-
setAccountActive
- Throws:
IOException
-
transfer
- 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) throws IOException As transferBatch, keepingdepthbatch frames in flight on the routed connection.- 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) throws IOException As reserveBatch, keepingdepthbatch frames in flight on the routed connection.- Throws:
IOException
-
reserve
- Throws:
IOException
-
reject
- Throws:
IOException
-
rejectByKey
public Models.TransferResult rejectByKey(long sourceId, int currency, String txnId) throws IOException - Throws:
IOException
-
rejectByKey
public Models.TransferResult rejectByKey(long sourceId, int currency, String txnId, long amount) throws IOException - Throws:
IOException
-
rejectByKey
public Models.TransferResult rejectByKey(long sourceId, int currency, String txnId, long amount, int ledgerId, int reasonCode, Object custom) throws IOException - Throws:
IOException
-
rejectByKey
public Models.TransferResult rejectByKey(long sourceId, int currency, String txnId, long amount, int ledgerId, long debitHi, long debitLo, long creditHi, long creditLo, int reasonCode, Object custom) throws IOException - Throws:
IOException
-
commit
- Throws:
IOException
-
rollback
- Throws:
IOException
-
commitBatch
- Throws:
IOException
-
commitBatch
public List<Models.TransferResult> commitBatch(List<String> transferIds, int depth) throws IOException As commitBatch, keepingdepthbatch frames in flight on the routed connection.- Throws:
IOException
-
rollbackBatch
- Throws:
IOException
-
rollbackBatch
public List<Models.TransferResult> rollbackBatch(List<String> transferIds, int depth) throws IOException As rollbackBatch, keepingdepthbatch frames in flight on the routed connection.- Throws:
IOException
-
commitByKey
public Models.TransferResult commitByKey(long sourceId, int ledgerId, int currency, String txnId) throws IOException - Throws:
IOException
-
rollbackByKey
public Models.TransferResult rollbackByKey(long sourceId, int ledgerId, int currency, String txnId) throws IOException - Throws:
IOException
-
tieredTransfer
public Models.TieredTransferResult tieredTransfer(Models.TieredTransferCreate transfer) throws IOException - Throws:
IOException
-
tieredReserve
public Models.TieredTransferResult tieredReserve(Models.TieredTransferCreate transfer) 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) throws IOException As tieredTransferBatch, keepingdepthbatch frames in flight on the routed connection.- 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) throws IOException As tieredReserveBatch, keepingdepthbatch frames in flight on the routed connection.- Throws:
IOException
-
tieredCommit
- Throws:
IOException
-
tieredRollback
- 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) throws IOException As tieredCommitBatch, keepingdepthbatch frames in flight on the routed connection.- 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) throws IOException As tieredRollbackBatch, keepingdepthbatch frames in flight on the routed connection.- Throws:
IOException
-
tieredCommitByKey
public Models.TieredTransferResult tieredCommitByKey(long sourceId, int ledgerId, int currency, String txnId) throws IOException - Throws:
IOException
-
tieredRollbackByKey
public Models.TieredTransferResult tieredRollbackByKey(long sourceId, int ledgerId, int currency, String txnId) throws IOException - Throws:
IOException
-
getBalance
- Throws:
IOException
-
getBalance
- Throws:
IOException
-
listAccountBalances
public List<Models.AccountBalance> listAccountBalances(int ledgerId, long accountHi, long accountLo) throws IOException - Throws:
IOException
-
getTransaction
- Throws:
IOException
-
getTransactionByTransferId
- Throws:
IOException
-
getTransactionByKey
public Models.TxnRecord getTransactionByKey(long sourceId, int ledgerId, int currency, String txnId) throws IOException - Throws:
IOException
-
getHistory
public List<Models.TxnRecord> getHistory(Models.AccountKey key, long afterSeq, int limit) throws IOException - Throws:
IOException
-
getHistory
public List<Models.TxnRecord> getHistory(Models.AccountKey key, long afterSeq, int afterIndex, int limit) throws IOException Paged account history resuming after the composite cursor (afterSeq, afterIndex).- Throws:
IOException
-
getAccountHistory
public List<Models.AccountMetadataEvent> getAccountHistory(Models.AccountKey key, long afterTimestamp, int limit) throws IOException - Throws:
IOException
-
listAccounts
- Throws:
IOException
-
listTransfers
- Throws:
IOException
-
listPending
- Throws:
IOException
-
listRejected
- Throws:
IOException
-
searchTransactions
- Throws:
IOException
-
listTransfersExtended
public List<Models.TxnRecord> listTransfersExtended(int maxRecords, int pageLimit, boolean includePending) throws IOException - Throws:
IOException
-
listWrappedTransactions
public List<LedgerClient.WrappedTxn> listWrappedTransactions(int maxRecords, int pageLimit, boolean includePending) throws IOException - Throws:
IOException
-
createLedger
- Throws:
IOException
-
getLedger
- Throws:
IOException
-
listLedgers
- Throws:
IOException
-
ledgerAddSource
- Throws:
IOException
-
ledgerRemoveSource
- Throws:
IOException
-
ledgerListSources
- Throws:
IOException
-
createSource
- Throws:
IOException
-
getSource
- Throws:
IOException
-
listSources
- Throws:
IOException
-
setSourceActive
- Throws:
IOException
-
createCurrency
- Throws:
IOException
-
getCurrency
- Throws:
IOException
-
listCurrencies
- Throws:
IOException
-
setCurrencyActive
- Throws:
IOException
-
ping
- Throws:
IOException
-
getVersion
R2-H4: probe the connected daemon's build identity over the wire. Returns the same stringtuladbd --versionprints. Allowed under any non-denied auth role; safe to call against followers (the probe is read-only and leaks no ledger state).- Throws:
IOException
-
setDefaultFlags
public void setDefaultFlags(short flags) R2-H2: set session-wide default frame flags. Applied to the underlying leader connection and re-applied automatically when the SmartLedgerClient reconnects after a leader change, so a caller can setclient.setDefaultFlags(Protocol.WIRE_FLAG_ALLOW_FOLLOWER_READ)once and forget it. Writes ignore the flag server-side. -
getDefaultFlags
public short getDefaultFlags()Inspect the current session-wide default frame flags. -
getClusterStatus
- Throws:
IOException
-
close
public void close()- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable
-