Class OptimisticLockRetryInterceptor

All Implemented Interfaces:
ChainableRunner, InternalLocalRunner, CommandExecutor, ExecutableRunner<RequestContext>

public class OptimisticLockRetryInterceptor extends AbstractInterceptor
ExecutableInterceptor that is capable of retrying command execution. It is intended to retry only if right exception has been thrown. By default it will look for org.hibernate.StaleObjectStateException and only then attempt to retry. Since this is Hibernate specific class another can be given as system property to override default. Name of the system property org.kie.optlock.exclass and its value should be fully qualified class name of the exception that indicates OptimisticLocking. By default it will:
  • Retry 3 times
  • First retry will be attempted after 50 milliseconds
  • next retries will be calculated as last sleep time multiplied by a factor (default factor is 4)
In case all retries failed origin exception will be thrown.
  • Field Details

    • targetExceptionClass

      protected Class<?> targetExceptionClass
    • targetConstraintViolationExceptionClass

      protected Class<?> targetConstraintViolationExceptionClass
  • Constructor Details

    • OptimisticLockRetryInterceptor

      public OptimisticLockRetryInterceptor()
  • Method Details

    • execute

      public final RequestContext execute(Executable executable, RequestContext ctx)
      Specified by:
      execute in interface ExecutableRunner<RequestContext>
      Overrides:
      execute in class PseudoClockRunner
    • internalExecute

      protected RequestContext internalExecute(Executable executable, RequestContext ctx)
    • isCausedByOptimisticLockingFailure

      protected boolean isCausedByOptimisticLockingFailure(Throwable throwable)
    • isCausedByConstraintViolationFailure

      protected boolean isCausedByConstraintViolationFailure(Throwable throwable)
    • getRetries

      public int getRetries()
    • setRetries

      public void setRetries(int retries)
    • getDelay

      public long getDelay()
    • setDelay

      public void setDelay(long delay)
    • getDelayFactor

      public long getDelayFactor()
    • setDelayFactor

      public void setDelayFactor(long delayFactor)
    • getTargetExceptionClass

      public Class<?> getTargetExceptionClass()
    • setTargetExceptionClass

      public void setTargetExceptionClass(Class<?> targetExceptionClass)
    • hasInterceptorInStack

      protected boolean hasInterceptorInStack()