Class MongoConcurrentUtils
java.lang.Object
dev.getelements.elements.dao.mongo.MongoConcurrentUtils
A class that helps reduce the boilerplate code when atomic operations are necessary.
Created by patricktwohig on 3/29/15.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
Thrown when there is too much contention over a particular resource.static class
Thrown when the operation fails.static interface
A basic a atomic operation.static class
General exception type for a failure of an Optimistic operation. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<ReturnT> ReturnT
performOptimistic
(MongoConcurrentUtils.CriticalOperation<ReturnT> criticalOperation) Attempts to complete the given criticalOperation and, in the event of a failure, attempts to retry the criticalOperation several times until giving up.<ReturnT,
ExceptionT extends Throwable>
ReturnTperformOptimistic
(MongoConcurrentUtils.CriticalOperation<ReturnT> criticalOperation, Supplier<ExceptionT> exceptionTSupplier) Attempts to complete the given criticalOperation and, in the event of a failure, attempts to retry the criticalOperation several times until giving up.
-
Field Details
-
OPTIMISTIC_RETRY_COUNT
- See Also:
-
FALLOFF_TIME_MIN_MS
Defines the minimum time an optimistic operation will wait before retrying.- See Also:
-
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
-