- 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.int
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.
-
-
-
Constructor Detail
-
Client
public Client(int clusterID, String[] replicaAddresses, int maxConcurrency)
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
-maxConcurrency
-- Throws:
InitializationException
- if an error occurred initializing this client. SeeInitializationStatus
for more details.IllegalArgumentException
- ifclusterID
is negative.IllegalArgumentException
- ifreplicaAddresses
is empty or presented in incorrect format.NullPointerException
- ifreplicaAddresses
is null or any element in the array is null.IllegalArgumentException
- ifmaxConcurrency
is zero or negative.
-
Client
public Client(int 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.IllegalArgumentException
- ifclusterID
is negative.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 int getClusterID()
Gets the cluster ID- Returns:
- clusterID
-
createAccounts
public CreateAccountResultBatch createAccounts(AccountBatch batch) throws RequestException
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) throws RequestException
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) throws RequestException
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) throws RequestException
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)
-
close
public void close() throws Exception
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
- Throws:
Exception
- See Also:
AutoCloseable.close()
-
-