Class MongoConcurrentUtils

java.lang.Object
dev.getelements.elements.dao.mongo.MongoConcurrentUtils

@Singleton public class MongoConcurrentUtils extends Object
A class that helps reduce the boilerplate code when atomic operations are necessary. Created by patricktwohig on 3/29/15.
  • Field Details

    • OPTIMISTIC_RETRY_COUNT

      public static final String OPTIMISTIC_RETRY_COUNT
      See Also:
    • FALLOFF_TIME_MIN_MS

      public static final String FALLOFF_TIME_MIN_MS
      Defines the minimum time an optimistic operation will wait before retrying.
      See Also:
    • FALLOFF_TIME_MAX_MS

      public static final String FALLOFF_TIME_MAX_MS
      Defines the maximum time an optimistic operation will wait before retrying.
      See Also:
  • Constructor Details

    • MongoConcurrentUtils

      public MongoConcurrentUtils()
  • Method Details

    • performOptimistic

      public <ReturnT> ReturnT performOptimistic(MongoConcurrentUtils.CriticalOperation<ReturnT> criticalOperation) throws MongoConcurrentUtils.ConflictException
      Attempts to complete the given criticalOperation and, in the event of a failure, attempts to retry the criticalOperation several times until giving up.
      Type Parameters:
      ReturnT - the type to return
      Parameters:
      criticalOperation - the criticalOperation to attempt
      Returns:
      the return fields from the HttpOperation
      Throws:
      MongoConcurrentUtils.ConflictException
    • performOptimistic

      public <ReturnT, ExceptionT extends Throwable> ReturnT performOptimistic(MongoConcurrentUtils.CriticalOperation<ReturnT> criticalOperation, Supplier<ExceptionT> exceptionTSupplier) throws ExceptionT
      Attempts to complete the given criticalOperation and, in the event of a failure, attempts to retry the criticalOperation several times until giving up.
      Type Parameters:
      ReturnT - the type to return
      Parameters:
      criticalOperation - the criticalOperation to attempt
      Returns:
      the return fields from the HttpOperation
      Throws:
      ExceptionT