Package org.wildfly.transaction.client
Class LocalTransactionContext
java.lang.Object
org.wildfly.transaction.client.LocalTransactionContext
- All Implemented Interfaces:
org.wildfly.common.context.Contextual<LocalTransactionContext>
public final class LocalTransactionContext
extends Object
implements org.wildfly.common.context.Contextual<LocalTransactionContext>
The local transaction context, which manages the creation and usage of local transactions.
- Author:
- David M. Lloyd
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intThe default transaction timeout (5 minutes). -
Constructor Summary
ConstructorsConstructorDescriptionConstruct a new instance. -
Method Summary
Modifier and TypeMethodDescriptionbeginTransaction(int timeout) Begin a new, local transaction on behalf of a local peer.beginTransaction(int timeout, boolean failOnSuspend) Begin a new, local transaction on behalf of a local or remote peer.findOrImportTransaction(Xid xid, int timeout) Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle.findOrImportTransaction(Xid xid, int timeout, boolean doNotImport) Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle.static org.wildfly.common.context.ContextManager<LocalTransactionContext>Get the context manager.static LocalTransactionContextGet the current local transaction context.org.wildfly.common.context.ContextManager<LocalTransactionContext>Get the context manager; delegates togetContextManager().Get the recovery interface for this context.jakarta.resource.spi.XATerminatorbooleanAttempt to import a provider's current transaction as a local transaction.voidregisterCreationListener(CreationListener creationListener) Register a transaction creation listener.voidremoveCreationListener(CreationListener creationListener) Remove a transaction creation listener.voidCause requests to create new transactions to be allowed after a previous call tosuspendRequests().voidCause requests to create new transactions to be refused.toString()Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.wildfly.common.context.Contextual
run, runAction, runBiConsumer, runBiFunction, runBiPredicate, runCallable, runConsumer, runExBiConsumer, runExBiFunction, runExBiPredicate, runExceptionAction, runExConsumer, runExFunction, runExIntFunction, runExLongFunction, runExPredicate, runFunction, runIntFunction, runLongFunction, runPredicate
-
Field Details
-
DEFAULT_TXN_TIMEOUT
public static final int DEFAULT_TXN_TIMEOUTThe default transaction timeout (5 minutes).- See Also:
-
-
Constructor Details
-
LocalTransactionContext
Construct a new instance. The given provider will be used to manage local transactions.- Parameters:
provider- the local transaction provider
-
-
Method Details
-
getContextManager
@NotNull public static org.wildfly.common.context.ContextManager<LocalTransactionContext> getContextManager()Get the context manager.- Returns:
- the context manager (not
null)
-
getInstanceContextManager
@NotNull public org.wildfly.common.context.ContextManager<LocalTransactionContext> getInstanceContextManager()Get the context manager; delegates togetContextManager().- Specified by:
getInstanceContextManagerin interfaceorg.wildfly.common.context.Contextual<LocalTransactionContext>- Returns:
- the context manager (not
null)
-
getCurrent
Get the current local transaction context. The default context does not support initiating new transactions.- Returns:
- the current local transaction context (not
null)
-
registerCreationListener
Register a transaction creation listener.- Parameters:
creationListener- the creation listener (must not benull)
-
removeCreationListener
Remove a transaction creation listener.- Parameters:
creationListener- the creation listener (must not benull)
-
beginTransaction
@NotNull public LocalTransaction beginTransaction(int timeout) throws jakarta.transaction.SystemException, SecurityException Begin a new, local transaction on behalf of a local peer.- Parameters:
timeout- the transaction timeout to use for this transaction- Returns:
- the local transaction (not
null) - Throws:
jakarta.transaction.SystemException- if the transaction creation failed for some reason, one of the possible reasons being suspended serverSecurityException- if the caller is not authorized to create a local transaction in this context
-
beginTransaction
@NotNull public LocalTransaction beginTransaction(int timeout, boolean failOnSuspend) throws jakarta.transaction.SystemException, SecurityException Begin a new, local transaction on behalf of a local or remote peer.- Parameters:
timeout- the transaction timeout to use for this transactionfailOnSuspend-trueto fail if the server is suspended,falseto begin the transaction even if the server is suspended- Returns:
- the local transaction (not
null) - Throws:
jakarta.transaction.SystemException- if the transaction creation failed for some reason, one of the possible reasons being suspended serverSecurityException- if the caller is not authorized to create a local transaction in this context
-
findOrImportTransaction
public ImportResult<LocalTransaction> findOrImportTransaction(Xid xid, int timeout, boolean doNotImport) throws XAException Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle.- Parameters:
xid- the XID of the transaction to import (must not benull)timeout- the transaction timeout to use, if newdoNotImport-trueto indicate that a non-existing transaction should not be imported,falseotherwise- Returns:
- the transaction import result, or
nullif (and only if)doNotImportistrueand the transaction didn't exist locally - Throws:
XAException- if a problem occurred while importing the transaction
-
findOrImportTransaction
@NotNull public ImportResult<LocalTransaction> findOrImportTransaction(Xid xid, int timeout) throws XAException Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle.- Parameters:
xid- the XID of the transaction to import (must not benull)timeout- the transaction timeout to use, if new- Returns:
- the transaction import result (not
null) - Throws:
XAException- if a problem occurred while importing the transaction
-
importProviderTransaction
public boolean importProviderTransaction() throws jakarta.transaction.SystemExceptionAttempt to import a provider's current transaction as a local transaction.- Returns:
trueif the transaction was associated,falseif the provider had no current transaction- Throws:
jakarta.transaction.SystemException- if an error occurred acquiring the current transaction from the providerIllegalStateException- if the thread is associated with a transaction that isn't equal to the provider's transaction
-
getRecoveryInterface
Get the recovery interface for this context. The recovery interface can be used to recover transactions which were imported into this context viafindOrImportTransaction(Xid, int).- Returns:
- the recovery interface for this context (not
null)
-
getXATerminator
@NotNull public jakarta.resource.spi.XATerminator getXATerminator() -
suspendRequests
Cause requests to create new transactions to be refused.- Throws:
SecurityException- if a security manager is present and the caller does not have thesuspendRequestsTransactionPermission
-
resumeRequests
Cause requests to create new transactions to be allowed after a previous call tosuspendRequests().- Throws:
SecurityException- if a security manager is present and the caller does not have theresumeRequestsTransactionPermission
-
toString
-