Package com.atlassian.bamboo.core
Class ScopedExclusionServiceImpl
- java.lang.Object
-
- com.atlassian.bamboo.core.ScopedExclusionServiceImpl
-
- All Implemented Interfaces:
ScopedExclusionService
public class ScopedExclusionServiceImpl extends Object implements ScopedExclusionService
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.atlassian.bamboo.core.ScopedExclusionService
ScopedExclusionService.ExclusionScopeType, ScopedExclusionService.ExclusiveFunction<F,V,E extends Throwable>, ScopedExclusionService.GeneratorCallable<V,E extends Throwable>
-
-
Constructor Summary
Constructors Constructor Description ScopedExclusionServiceImpl()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description <S,V,E extends Throwable>
io.atlassian.fugue.Either<Boolean,Optional<V>>tryWithLock(@NotNull Enum<?> scopeType, S objectToLock, @NotNull ScopedExclusionService.ExclusiveFunction<S,V,E> function)
Executes function with lock taken in a given scope and object name or returns immediately if lock is already taken.static <T> com.google.common.cache.LoadingCache<T,ReadWriteLock>
weakReadWriteLockFactory()
<S,V,E extends Throwable>
VwithLock(@NotNull Enum<?> scopeType, S objectToLock, @NotNull ScopedExclusionService.ExclusiveFunction<S,V,E> function)
Executes function with lock taken in a given scope and object name.<S,V,E extends Throwable,F extends Throwable>
VwithNewLockedObject(@NotNull Enum<?> generationScopeType, S objectToLockDuringGeneration, @Nullable Enum<?> generatedObjectScope, @NotNull ScopedExclusionService.GeneratorCallable<S,F> objectGenerator, @NotNull ScopedExclusionService.ExclusiveFunction<S,V,E> function)
Executes code with a new, unique name generated within given exclusion scope and locked for exclusive use.
-
-
-
Method Detail
-
weakReadWriteLockFactory
public static <T> com.google.common.cache.LoadingCache<T,ReadWriteLock> weakReadWriteLockFactory()
-
withNewLockedObject
public <S,V,E extends Throwable,F extends Throwable> V withNewLockedObject(@NotNull @NotNull Enum<?> generationScopeType, @Nullable S objectToLockDuringGeneration, @Nullable @Nullable Enum<?> generatedObjectScope, @NotNull @NotNull ScopedExclusionService.GeneratorCallable<S,F> objectGenerator, @NotNull @NotNull ScopedExclusionService.ExclusiveFunction<S,V,E> function) throws E extends Throwable, F extends Throwable
Description copied from interface:ScopedExclusionService
Executes code with a new, unique name generated within given exclusion scope and locked for exclusive use. Objects to lock are generated by objectGenerator. If the generated object is already locked, the generator will be asked for a new object. The whole generation (including all unsuccesful lock attempts) will be run with an exclusive lock held on objectToLockDuringGeneration within generationScope. As soon as a valid object, locked within generatedObjectScope is generated: - other generations within the same scope may continue and - the function will be called. - the generation lock is dropped- Specified by:
withNewLockedObject
in interfaceScopedExclusionService
- Throws:
E extends Throwable
-
withLock
public <S,V,E extends Throwable> V withLock(@NotNull @NotNull Enum<?> scopeType, @NotNull S objectToLock, @NotNull @NotNull ScopedExclusionService.ExclusiveFunction<S,V,E> function) throws E extends Throwable
Description copied from interface:ScopedExclusionService
Executes function with lock taken in a given scope and object name.- Specified by:
withLock
in interfaceScopedExclusionService
- Parameters:
scopeType
- type of scope (if we wanted to lock a Job, this would be JOB_KEY - jobs are locked by key)objectToLock
- object to lock within scope (if we wanted to lock a Job, this would be job key)function
- the function to call- Returns:
- the result of function
- Throws:
E
- exception thrown from functionE extends Throwable
-
tryWithLock
public <S,V,E extends Throwable> io.atlassian.fugue.Either<Boolean,Optional<V>> tryWithLock(@NotNull @NotNull Enum<?> scopeType, @NotNull S objectToLock, @NotNull @NotNull ScopedExclusionService.ExclusiveFunction<S,V,E> function) throws E extends Throwable
Description copied from interface:ScopedExclusionService
Executes function with lock taken in a given scope and object name or returns immediately if lock is already taken.- Specified by:
tryWithLock
in interfaceScopedExclusionService
- Parameters:
scopeType
- type of scope (if we wanted to lock a Job, this would be JOB_KEY - jobs are locked by key)objectToLock
- object to lock within scope (if we wanted to lock a Job, this would be job key)function
- the function to call- Returns:
- either the result of function or false if the lock could not be acquired
- Throws:
E
- exception thrown from functionE extends Throwable
-
-