Package com.apple.foundationdb
Interface Tenant
-
- All Superinterfaces:
java.lang.AutoCloseable,ReadTransactionContext,TransactionContext
public interface Tenant extends java.lang.AutoCloseable, TransactionContext
A tenant represents a named key-space within a database that can be interacted with transactionally.
The simplest correct programs using tenants will make use of the methods defined in theTransactionContextinterface. When used on aTenantthese methods will callTransaction#commit()after user code has been executed. These methods will not return successfully untilcommit()has returned successfully.
Note:Tenantobjects must beclosedwhen no longer in use in order to free any associated resources.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description voidclose()Close theTenantobject and release any associated resources.default TransactioncreateTransaction()Creates aTransactionthat operates on thisTenant.
Note: Java transactions automatically set theTransactionOptions.setUsedDuringCommitProtectionDisable()option.TransactioncreateTransaction(java.util.concurrent.Executor e)Creates aTransactionthat operates on thisTenantwith the givenExecutorfor asynchronous callbacks.TransactioncreateTransaction(java.util.concurrent.Executor e, EventKeeper eventKeeper)Creates aTransactionthat operates on thisTenantwith the givenExecutorfor asynchronous callbacks.default java.util.concurrent.CompletableFuture<java.lang.Long>getId()RunsgetId()on the default executor.java.util.concurrent.CompletableFuture<java.lang.Long>getId(java.util.concurrent.Executor e)Returns the tenant ID of this tenant.byte[]getName()Returns the name of thisTenant.default <T> Tread(java.util.function.Function<? super ReadTransaction,T> retryable)Runs a read-only transactional function against thisTenantwith retry logic.<T> Tread(java.util.function.Function<? super ReadTransaction,T> retryable, java.util.concurrent.Executor e)Runs a read-only transactional function against thisTenantwith retry logic.default <T> java.util.concurrent.CompletableFuture<T>readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)Runs a read-only transactional function against thisTenantwith retry logic.<T> java.util.concurrent.CompletableFuture<T>readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable, java.util.concurrent.Executor e)Runs a read-only transactional function against thisTenantwith retry logic.default <T> Trun(java.util.function.Function<? super Transaction,T> retryable)Runs a transactional function against thisTenantwith retry logic.<T> Trun(java.util.function.Function<? super Transaction,T> retryable, java.util.concurrent.Executor e)Runs a transactional function against thisTenantwith retry logic.default <T> java.util.concurrent.CompletableFuture<T>runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)Runs a transactional function against thisTenantwith retry logic.<T> java.util.concurrent.CompletableFuture<T>runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable, java.util.concurrent.Executor e)Runs a transactional function against thisTenantwith retry logic.-
Methods inherited from interface com.apple.foundationdb.ReadTransactionContext
getExecutor
-
-
-
-
Method Detail
-
createTransaction
default Transaction createTransaction()
Creates aTransactionthat operates on thisTenant.
Note: Java transactions automatically set theTransactionOptions.setUsedDuringCommitProtectionDisable()option. This is because the Java bindings disallow use ofTransactionobjects afterTransaction.onError(java.lang.Throwable)is called.- Returns:
- a newly created
Transactionthat reads from and writes to thisTenant.
-
createTransaction
Transaction createTransaction(java.util.concurrent.Executor e)
Creates aTransactionthat operates on thisTenantwith the givenExecutorfor asynchronous callbacks.- Parameters:
e- theExecutorto use when executing asynchronous callbacks.- Returns:
- a newly created
Transactionthat reads from and writes to thisTenant.
-
createTransaction
Transaction createTransaction(java.util.concurrent.Executor e, EventKeeper eventKeeper)
Creates aTransactionthat operates on thisTenantwith the givenExecutorfor asynchronous callbacks.- Parameters:
e- theExecutorto use when executing asynchronous callbacks.eventKeeper- theEventKeeperto use when tracking instrumented calls for the transaction.- Returns:
- a newly created
Transactionthat reads from and writes to thisTenant.
-
getName
byte[] getName()
Returns the name of thisTenant.- Returns:
- the name of this
Tenantas a byte string.
-
read
default <T> T read(java.util.function.Function<? super ReadTransaction,T> retryable)
Runs a read-only transactional function against thisTenantwith retry logic.apply(ReadTransaction)will be called on the suppliedFunctionuntil a non-retryable FDBException (or anyThrowableother than anFDBException) is thrown. This call is blocking -- this method will not return until theFunctionhas been called and completed without error.- Specified by:
readin interfaceReadTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this tenant- Returns:
- the result of the last run of
retryable
-
read
<T> T read(java.util.function.Function<? super ReadTransaction,T> retryable, java.util.concurrent.Executor e)
Runs a read-only transactional function against thisTenantwith retry logic. Use this formulation ofread(Function)if one wants to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this tenante- theExecutorto use for asynchronous callbacks- Returns:
- the result of the last run of
retryable - See Also:
read(Function)
-
readAsync
default <T> java.util.concurrent.CompletableFuture<T> readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)
Runs a read-only transactional function against thisTenantwith retry logic.apply(ReadTransaction)will be called on the suppliedFunctionuntil a non-retryable FDBException (or anyThrowableother than anFDBException) is thrown. This call is non-blocking -- this method will return immediately and with aCompletableFuturethat will be set when theFunctionhas been called and completed without error.
Any errors encountered executingretryable, or received from the database, will be set on the returnedCompletableFuture.- Specified by:
readAsyncin interfaceReadTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aReadTransactionagainst this tenant- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable
-
readAsync
<T> java.util.concurrent.CompletableFuture<T> readAsync(java.util.function.Function<? super ReadTransaction,? extends java.util.concurrent.CompletableFuture<T>> retryable, java.util.concurrent.Executor e)
Runs a read-only transactional function against thisTenantwith retry logic. Use this version ofreadAsync(Function)if one wants to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aReadTransactionagainst this tenante- theExecutorto use for asynchronous callbacks- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable - See Also:
readAsync(Function)
-
run
default <T> T run(java.util.function.Function<? super Transaction,T> retryable)
Runs a transactional function against thisTenantwith retry logic.apply(Transaction)will be called on the suppliedFunctionuntil a non-retryable FDBException (or anyThrowableother than anFDBException) is thrown orcommit(), when called afterapply(), returns success. This call is blocking -- this method will not return untilcommit()has been called and returned success.
As with other client/server databases, in some failure scenarios a client may be unable to determine whether a transaction succeeded. In these cases, your transaction may be executed twice. For more information about how to reason about these situations see the FounationDB Developer Guide- Specified by:
runin interfaceTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this tenant- Returns:
- the result of the last run of
retryable
-
run
<T> T run(java.util.function.Function<? super Transaction,T> retryable, java.util.concurrent.Executor e)
Runs a transactional function against thisTenantwith retry logic. Use this formulation ofrun(Function)if one would like to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this tenante- theExecutorto use for asynchronous callbacks- Returns:
- the result of the last run of
retryable
-
runAsync
default <T> java.util.concurrent.CompletableFuture<T> runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable)
Runs a transactional function against thisTenantwith retry logic.apply(Transaction)will be called on the suppliedFunctionuntil a non-retryable FDBException (or anyThrowableother than anFDBException) is thrown orcommit(), when called afterapply(), returns success. This call is non-blocking -- this method will return immediately and with aCompletableFuturethat will be set whencommit()has been called and returned success.
As with other client/server databases, in some failure scenarios a client may be unable to determine whether a transaction succeeded. In these cases, your transaction may be executed twice. For more information about how to reason about these situations see the FounationDB Developer Guide
Any errors encountered executingretryable, or received from the database, will be set on the returnedCompletableFuture.- Specified by:
runAsyncin interfaceTransactionContext- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this tenant- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable
-
runAsync
<T> java.util.concurrent.CompletableFuture<T> runAsync(java.util.function.Function<? super Transaction,? extends java.util.concurrent.CompletableFuture<T>> retryable, java.util.concurrent.Executor e)
Runs a transactional function against thisTenantwith retry logic. Use this formulation of the non-blockingrunAsync(Function)if one wants to set a customExecutorfor the transaction when run.- Type Parameters:
T- the return type ofretryable- Parameters:
retryable- the block of logic to execute in aTransactionagainst this tenante- theExecutorto use for asynchronous callbacks- Returns:
- a
CompletableFuturethat will be set to the value returned by the last call toretryable - See Also:
run(Function)
-
getId
default java.util.concurrent.CompletableFuture<java.lang.Long> getId()
RunsgetId()on the default executor.- Returns:
- a future with the tenant ID
-
getId
java.util.concurrent.CompletableFuture<java.lang.Long> getId(java.util.concurrent.Executor e)
Returns the tenant ID of this tenant.- Parameters:
e- theExecutorto use for asynchronous callbacks- Returns:
- a future with the tenant ID
-
close
void close()
Close theTenantobject and release any associated resources. This must be called at least once after theTenantobject is no longer in use. This can be called multiple times, but care should be taken that it is not in use in another thread at the time of the call.- Specified by:
closein interfacejava.lang.AutoCloseable
-
-