Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

org.alfresco.repo.transaction
Class RetryingTransactionHelper
java.lang.Object
  org.alfresco.repo.transaction.RetryingTransactionHelper

@org.alfresco.api.AlfrescoPublicApi
public class RetryingTransactionHelper
extends Object
A helper that runs a unit of work inside a UserTransaction, transparently retrying the unit of work if the cause of failure is an optimistic locking or deadlock condition.

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

Author:
Derek Hulley

Nested Class Summary
static interface
RetryingTransactionHelper.RetryingTransactionCallback<Result>
          Callback interface
Field Summary
static Class[]
RETRY_EXCEPTIONS
          Exceptions that trigger retries.
Constructor Summary
RetryingTransactionHelper()
          Default constructor.
Method Summary
<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.
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(org.alfresco.service.transaction.TransactionService service)
          Set the TransactionService.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Field Detail
RETRY_EXCEPTIONS
public static final Class[] RETRY_EXCEPTIONS
Exceptions that trigger retries.
Constructor Detail
RetryingTransactionHelper
public RetryingTransactionHelper()
Default constructor.
Method Detail
setTransactionService
public void setTransactionService(org.alfresco.service.transaction.TransactionService service)
Set the TransactionService.

setMaxRetries
public void setMaxRetries(int maxRetries)
Set the maximimum number of retries. -1 for infinity.

setMinRetryWaitMs
public void setMinRetryWaitMs(int minRetryWaitMs)

setMaxRetryWaitMs
public void setMaxRetryWaitMs(int maxRetryWaitMs)

setRetryWaitIncrementMs
public void setRetryWaitIncrementMs(int retryWaitIncrementMs)

setMaxExecutionMs
public void setMaxExecutionMs(long maxExecutionMs)

setReadOnly
public void setReadOnly(boolean readOnly)
Set whether this helper only supports read transactions.

setForceWritable
public void setForceWritable(boolean forceWritable)
Override to allow the transactions to be writable regardless of the system read-only mode.

NOTE: This method may not be used to circumvent the Alfresco License policy.

Parameters:
forceWritable - true to force transactions to be writable regardless of system read-only mode

setExtraExceptions
public void setExtraExceptions(List<Class<?>> extraExceptions)
Set the list of extra exceptions that should be retried

doInTransaction
public <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.

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.

Parameters:
cb - The callback containing the unit of work.
Returns:
Returns the result of the unit of work.
Throws:
RuntimeException - all checked exceptions are converted

doInTransaction
public <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.

If there is already an active transaction, then the callback is merely executed and any retry logic is left to the caller.

Parameters:
cb - The callback containing the unit of work.
readOnly - Whether this is a read only transaction.
Returns:
Returns the result of the unit of work.
Throws:
RuntimeException - all checked exceptions are converted

doInTransaction
public <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.

It is possible to force a new transaction to be created or to partake in any existing transaction.

Parameters:
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.
Returns:
Returns the result of the unit of work.
Throws:
RuntimeException - all checked exceptions are converted

extractRetryCause
public static Throwable extractRetryCause(Throwable cause)
Sometimes, the exception means retry and sometimes not. The stack of exceptions is also checked for any occurence of DoNotRetryException and, if found, nothing is returned.
Parameters:
cause - the cause to examine
Returns:
Returns the original cause if it is a valid retry cause, otherwise null

getActiveUserTransaction
public static UserTransaction getActiveUserTransaction()
Utility method to get the active transaction. The transaction status can be queried and marked for rollback.

NOTE: Any attempt to actually commit or rollback the transaction will cause failures.

Returns:
Returns the currently active user transaction or null if there isn't one.

Overview  Package   Class  Use  Tree  Deprecated  Index  Help 
PREV CLASS   NEXT CLASS FRAMES    NO FRAMES    All Classes
SUMMARY: NESTED | FIELD | CONSTR | METHOD DETAIL: FIELD | CONSTR | METHOD

Copyright © 2005–2018 Alfresco Software. All rights reserved.

Java API documentation generated with DocFlex/Javadoc 1.6.1 using JavadocPro template set.