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
Fields Modifier and Type Field Description static intDEFAULT_TXN_TIMEOUTThe default transaction timeout (5 minutes).
-
Constructor Summary
Constructors Constructor Description LocalTransactionContext(LocalTransactionProvider provider)Construct a new instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description LocalTransactionbeginTransaction(int timeout)Begin a new, local transaction on behalf of a local peer.LocalTransactionbeginTransaction(int timeout, boolean failOnSuspend)Begin a new, local transaction on behalf of a local or remote peer.ImportResult<LocalTransaction>findOrImportTransaction(Xid xid, int timeout)Attempt to import a transaction, which subsequently may be controlled by its XID or by the returned handle.ImportResult<LocalTransaction>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>getContextManager()Get the context manager.static LocalTransactionContextgetCurrent()Get the current local transaction context.org.wildfly.common.context.ContextManager<LocalTransactionContext>getInstanceContextManager()Get the context manager; delegates togetContextManager().XARecoverablegetRecoveryInterface()Get the recovery interface for this context.javax.resource.spi.XATerminatorgetXATerminator()booleanimportProviderTransaction()Attempt 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.voidresumeRequests()Cause requests to create new transactions to be allowed after a previous call tosuspendRequests().voidsuspendRequests()Cause requests to create new transactions to be refused.StringtoString()-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods 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 Detail
-
DEFAULT_TXN_TIMEOUT
public static final int DEFAULT_TXN_TIMEOUT
The default transaction timeout (5 minutes).- See Also:
- Constant Field Values
-
-
Constructor Detail
-
LocalTransactionContext
public LocalTransactionContext(LocalTransactionProvider provider)
Construct a new instance. The given provider will be used to manage local transactions.- Parameters:
provider- the local transaction provider
-
-
Method Detail
-
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
@NotNull public static LocalTransactionContext 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
public void registerCreationListener(CreationListener creationListener)
Register a transaction creation listener.- Parameters:
creationListener- the creation listener (must not benull)
-
removeCreationListener
public void removeCreationListener(CreationListener creationListener)
Remove a transaction creation listener.- Parameters:
creationListener- the creation listener (must not benull)
-
beginTransaction
@NotNull public LocalTransaction beginTransaction(int timeout) throws 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:
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 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:
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 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:
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
@NotNull public XARecoverable 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 javax.resource.spi.XATerminator getXATerminator()
-
suspendRequests
public void suspendRequests() throws SecurityExceptionCause requests to create new transactions to be refused.- Throws:
SecurityException- if a security manager is present and the caller does not have thesuspendRequestsTransactionPermission
-
resumeRequests
public void resumeRequests() throws SecurityExceptionCause 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
-
-