@AlfrescoPublicApi public class RetryingTransactionHelper extends Object
Defaults:
To get details of 'why' transactions are retried use the following log level:
Summary: log4j.logger.org.alfresco.repo.transaction.RetryingTransactionHelper=INFO
Details: log4j.logger.org.alfresco.repo.transaction.RetryingTransactionHelper=DEBUG
Modifier and Type | Class and Description |
---|---|
static interface |
RetryingTransactionHelper.RetryingTransactionCallback<Result>
Callback interface
|
Modifier and Type | Field and Description |
---|---|
static Class[] |
RETRY_EXCEPTIONS
Exceptions that trigger retries.
|
Constructor and Description |
---|
RetryingTransactionHelper()
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
<R> R |
doInTransaction(RetryingTransactionHelper.RetryingTransactionCallback<R> cb)
Execute a callback in a transaction until it succeeds, fails
because of an error not the result of an optimistic locking failure,
or a deadlock loser failure, or until a maximum number of retries have
been attempted.
|
<R> R |
doInTransaction(RetryingTransactionHelper.RetryingTransactionCallback<R> cb,
boolean readOnly)
Execute a callback in a transaction until it succeeds, fails
because of an error not the result of an optimistic locking failure,
or a deadlock loser failure, or until a maximum number of retries have
been attempted.
|
<R> R |
doInTransaction(RetryingTransactionHelper.RetryingTransactionCallback<R> cb,
boolean readOnly,
boolean requiresNew)
Execute a callback in a transaction until it succeeds, fails
because of an error not the result of an optimistic locking failure,
or a deadlock loser failure, or until a maximum number of retries have
been attempted.
|
static Throwable |
extractRetryCause(Throwable cause)
Sometimes, the exception means retry and sometimes not.
|
static UserTransaction |
getActiveUserTransaction()
Utility method to get the active transaction.
|
void |
setExtraExceptions(List<Class<?>> extraExceptions)
Set the list of extra exceptions that should be retried
|
void |
setForceWritable(boolean forceWritable)
Override to allow the transactions to be writable regardless of the system read-only mode.
|
void |
setMaxExecutionMs(long maxExecutionMs) |
void |
setMaxRetries(int maxRetries)
Set the maximimum number of retries.
|
void |
setMaxRetryWaitMs(int maxRetryWaitMs) |
void |
setMinRetryWaitMs(int minRetryWaitMs) |
void |
setReadOnly(boolean readOnly)
Set whether this helper only supports read transactions.
|
void |
setRetryWaitIncrementMs(int retryWaitIncrementMs) |
void |
setTransactionService(TransactionService service)
Set the TransactionService.
|
public static final Class[] RETRY_EXCEPTIONS
public RetryingTransactionHelper()
public void setTransactionService(TransactionService service)
public void setMaxRetries(int maxRetries)
public void setMinRetryWaitMs(int minRetryWaitMs)
public void setMaxRetryWaitMs(int maxRetryWaitMs)
public void setRetryWaitIncrementMs(int retryWaitIncrementMs)
public void setMaxExecutionMs(long maxExecutionMs)
public void setReadOnly(boolean readOnly)
public void setForceWritable(boolean forceWritable)
forceWritable
- true to force transactions to be writable
regardless of system read-only modepublic void setExtraExceptions(List<Class<?>> extraExceptions)
public <R> R doInTransaction(RetryingTransactionHelper.RetryingTransactionCallback<R> cb)
If there is already an active transaction, then the callback is merely executed and any retry logic is left to the caller. The transaction will attempt to be read-write.
cb
- The callback containing the unit of work.RuntimeException
- all checked exceptions are convertedpublic <R> R doInTransaction(RetryingTransactionHelper.RetryingTransactionCallback<R> cb, boolean readOnly)
If there is already an active transaction, then the callback is merely executed and any retry logic is left to the caller.
cb
- The callback containing the unit of work.readOnly
- Whether this is a read only transaction.RuntimeException
- all checked exceptions are convertedpublic <R> R doInTransaction(RetryingTransactionHelper.RetryingTransactionCallback<R> cb, boolean readOnly, boolean requiresNew)
It is possible to force a new transaction to be created or to partake in any existing transaction.
cb
- The callback containing the unit of work.readOnly
- Whether this is a read only transaction.requiresNew
- true to force a new transaction or
false to partake in any existing transaction.RuntimeException
- all checked exceptions are convertedpublic static Throwable extractRetryCause(Throwable cause)
DoNotRetryException
and, if found, nothing is returned.cause
- the cause to examinepublic static UserTransaction getActiveUserTransaction()
NOTE: Any attempt to actually commit or rollback the transaction will cause failures.
Copyright © 2005–2017 Alfresco Software. All rights reserved.