- java.lang.Object
-
- com.tigerbeetle.Client
-
- All Implemented Interfaces:
AutoCloseable
public final class Client extends Object implements AutoCloseable
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Closes the client, freeing all resources.CreateAccountResultBatch
createAccounts(AccountBatch batch)
Submits a batch of new accounts to be created.CompletableFuture<CreateAccountResultBatch>
createAccountsAsync(AccountBatch batch)
Submits a batch of new accounts to be created asynchronously.CreateTransferResultBatch
createTransfers(TransferBatch batch)
Submits a batch of new transfers to be created.CompletableFuture<CreateTransferResultBatch>
createTransfersAsync(TransferBatch batch)
Submits a batch of new transfers to be created asynchronously.AccountBalanceBatch
getAccountBalances(AccountFilter filter)
Fetch the balance history from a given account.CompletableFuture<AccountBalanceBatch>
getAccountBalancesAsync(AccountFilter filter)
Fetch the balance history from a given account asynchronously.TransferBatch
getAccountTransfers(AccountFilter filter)
Fetch transfers from a given account.CompletableFuture<TransferBatch>
getAccountTransfersAsync(AccountFilter filter)
Fetch transfers from a given account asynchronously.byte[]
getClusterID()
Gets the cluster IDAccountBatch
lookupAccounts(IdBatch batch)
Looks up a batch of accounts.CompletableFuture<AccountBatch>
lookupAccountsAsync(IdBatch batch)
Looks up a batch of accounts asynchronously.TransferBatch
lookupTransfers(IdBatch batch)
Looks up a batch of transfers.CompletableFuture<TransferBatch>
lookupTransfersAsync(IdBatch batch)
Looks up a batch of transfers asynchronously.AccountBatch
queryAccounts(QueryFilter filter)
Query accounts.CompletableFuture<AccountBatch>
queryAccountsAsync(QueryFilter filter)
Query accounts asynchronously.TransferBatch
queryTransfers(QueryFilter filter)
Query transfers.CompletableFuture<TransferBatch>
queryTransfersAsync(QueryFilter filter)
Query transfers asynchronously.
-
-
-
Constructor Detail
-
Client
public Client(byte[] clusterID, String[] replicaAddresses)
Initializes an instance of TigerBeetle client. This class is thread-safe and for optimal performance, a single instance should be shared between multiple concurrent tasks.Multiple clients can be instantiated in case of connecting to more than one TigerBeetle cluster.
- Parameters:
clusterID
-replicaAddresses
-- Throws:
InitializationException
- if an error occurred initializing this client. SeeInitializationStatus
for more details.NullPointerException
- ifclusterID
is null.IllegalArgumentException
- ifclusterID
is not a UInt128.IllegalArgumentException
- ifreplicaAddresses
is empty or presented in incorrect format.NullPointerException
- ifreplicaAddresses
is null or any element in the array is null.
-
-
Method Detail
-
getClusterID
public byte[] getClusterID()
Gets the cluster ID- Returns:
- clusterID
-
createAccounts
public CreateAccountResultBatch createAccounts(AccountBatch batch)
Submits a batch of new accounts to be created.- Parameters:
batch
- abatch
containing all accounts to be created.- Returns:
- a read-only
batch
describing the result. - Throws:
RequestException
- refer toPacketStatus
for more details.IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.
-
createAccountsAsync
public CompletableFuture<CreateAccountResultBatch> createAccountsAsync(AccountBatch batch)
Submits a batch of new accounts to be created asynchronously.- Parameters:
batch
- abatch
containing all accounts to be created.- Returns:
- a
CompletableFuture
to be completed. - Throws:
IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.- See Also:
createAccounts(AccountBatch)
-
lookupAccounts
public AccountBatch lookupAccounts(IdBatch batch)
Looks up a batch of accounts.- Parameters:
batch
- anbatch
containing all account ids.- Returns:
- a read-only
batch
containing all accounts found. - Throws:
RequestException
- refer toPacketStatus
for more details.IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.
-
lookupAccountsAsync
public CompletableFuture<AccountBatch> lookupAccountsAsync(IdBatch batch)
Looks up a batch of accounts asynchronously.- Parameters:
batch
- abatch
containing all account ids.- Returns:
- a
CompletableFuture
to be completed. - Throws:
IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.- See Also:
lookupAccounts(com.tigerbeetle.IdBatch)
-
createTransfers
public CreateTransferResultBatch createTransfers(TransferBatch batch)
Submits a batch of new transfers to be created.- Parameters:
batch
- abatch
containing all transfers to be created.- Returns:
- a read-only
batch
describing the result. - Throws:
RequestException
- refer toPacketStatus
for more details.IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.
-
createTransfersAsync
public CompletableFuture<CreateTransferResultBatch> createTransfersAsync(TransferBatch batch)
Submits a batch of new transfers to be created asynchronously.- Parameters:
batch
- abatch
containing all transfers to be created.- Returns:
- a
CompletableFuture
to be completed. - Throws:
IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.
-
lookupTransfers
public TransferBatch lookupTransfers(IdBatch batch)
Looks up a batch of transfers.- Parameters:
batch
- abatch
containing all transfer ids.- Returns:
- a read-only
batch
containing all transfers found. - Throws:
RequestException
- refer toPacketStatus
for more details.IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.
-
lookupTransfersAsync
public CompletableFuture<TransferBatch> lookupTransfersAsync(IdBatch batch)
Looks up a batch of transfers asynchronously.- Parameters:
batch
- abatch
containing all transfer ids.- Returns:
- a
CompletableFuture
to be completed. - Throws:
IllegalArgumentException
- ifbatch
is empty.NullPointerException
- ifbatch
is null.IllegalStateException
- if this client is closed.- See Also:
lookupTransfers(IdBatch)
-
getAccountTransfers
public TransferBatch getAccountTransfers(AccountFilter filter)
Fetch transfers from a given account.- Parameters:
filter
- aAccountFilter
containing all query parameters.- Returns:
- a read-only
batch
containing all transfers that match the query parameters. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.- See Also:
getAccountTransfers(AccountFilter)
-
getAccountTransfersAsync
public CompletableFuture<TransferBatch> getAccountTransfersAsync(AccountFilter filter)
Fetch transfers from a given account asynchronously.- Parameters:
filter
- aAccountFilter
containing all query parameters.- Returns:
- a
CompletableFuture
to be completed. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.- See Also:
getAccountTransfers(AccountFilter)
-
getAccountBalances
public AccountBalanceBatch getAccountBalances(AccountFilter filter)
Fetch the balance history from a given account.- Parameters:
filter
- aAccountFilter
containing all query parameters.- Returns:
- a read-only
batch
containing all balances that match the query parameters. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.- See Also:
getAccountBalances(AccountFilter)
-
getAccountBalancesAsync
public CompletableFuture<AccountBalanceBatch> getAccountBalancesAsync(AccountFilter filter)
Fetch the balance history from a given account asynchronously.- Parameters:
filter
- aAccountFilter
containing all query parameters.- Returns:
- a
CompletableFuture
to be completed. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.- See Also:
getAccountBalances(AccountFilter)
-
queryAccounts
public AccountBatch queryAccounts(QueryFilter filter)
Query accounts.- Parameters:
filter
- aQueryFilter
containing all query parameters.- Returns:
- a read-only
batch
containing all accounts that match the query parameters. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.
-
queryAccountsAsync
public CompletableFuture<AccountBatch> queryAccountsAsync(QueryFilter filter)
Query accounts asynchronously.- Parameters:
filter
- aQueryFilter
containing all query parameters.- Returns:
- a
CompletableFuture
to be completed. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.- See Also:
queryAccounts(QueryFilter)
-
queryTransfers
public TransferBatch queryTransfers(QueryFilter filter)
Query transfers.- Parameters:
filter
- aQueryFilter
containing all query parameters.- Returns:
- a read-only
batch
containing all transfers that match the query parameters. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.
-
queryTransfersAsync
public CompletableFuture<TransferBatch> queryTransfersAsync(QueryFilter filter)
Query transfers asynchronously.- Parameters:
filter
- aQueryFilter
containing all query parameters.- Returns:
- a
CompletableFuture
to be completed. - Throws:
NullPointerException
- iffilter
is null.IllegalStateException
- if this client is closed.- See Also:
queryTransfers(QueryFilter)
-
close
public void close()
Closes the client, freeing all resources.This method causes the current thread to wait for all ongoing requests to finish.
- Specified by:
close
in interfaceAutoCloseable
- See Also:
AutoCloseable.close()
-
-