Package com.atlassian.bamboo.plan.cache
Class ImmutablePlanCacheServiceImpl
java.lang.Object
com.atlassian.bamboo.plan.cache.ImmutablePlanCacheServiceImpl
- All Implemented Interfaces:
ImmutablePlanCacheService
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.atlassian.bamboo.plan.cache.ImmutablePlanCacheService
ImmutablePlanCacheService.CacheInvalidator -
Constructor Summary
ConstructorsConstructorDescriptionImmutablePlanCacheServiceImpl(@NotNull ImmutablePlanManager immutablePlanManager, @NotNull com.atlassian.config.db.HibernateConfig hibernateConfig, @NotNull CustomVariableContext customVariableContext, @NotNull BuildResultsSummaryDao buildResultsSummaryDao, @NotNull VcsRepositoryManager vcsRepositoryManager, @NotNull BambooClusterSettings bambooClusterSettings, @NotNull ChainBranchManager chainBranchManager) -
Method Summary
Modifier and TypeMethodDescriptionvoidcascadeInvalidate(@NotNull PlanKey planKey) Removes the cached reference for the passed plan and its children.voidDisable cache.voidEnable cache.voidMarks the current thread as being able to see deleted plans.<T extends ImmutableChainStage>
@NotNull List<T>filterOutDeletedIfNeeded(@NotNull List<T> stages) Returns a list with deleted stages removed.<T extends ImmutableJob>
@NotNull Set<T>filterOutDeletedIfNeeded(@NotNull Set<T> jobs) Returns a set with deleted jobs removed.getAnyPlan(Predicate<? super ImmutableChain> predicate) Returns a plan matching the supplied predicate@NotNull Stream<PlanBranchGist>getBranchGistsOfChain(@NotNull PlanKey chainKey) Returns the Gists of all cached branches associated with a master plan identified by the given key.@NotNull ImmutableCacheResults<PlanBranchGist>getBranchGistsOfChainWithConsistencyGuarantee(@NotNull PlanKey chainKey) Returns the Gists of all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.getBranchKeysOfChain(@NotNull PlanKey chainKey) Returns all cached branches associated with a master plan identified by the given key.@NotNull ImmutableCacheResults<PlanKey>getBranchKeysOfChainWithConsistencyGuarantee(@NotNull PlanKey chainKey) Returns all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.getBuildNumbersRange(PlanKey planKey) internal use only.Retrieve cache statisticsvoidgetChainsToInvalidateAndReindex(ImmutablePlanCacheService.CacheInvalidator invalidator, Set<PlanKey> chainsToInvalidate, Set<PlanKey> chainsToReindex) Internal.@Nullable ImmutableChaingetImmutableChainByKeyIfInCache(@NotNull PlanKey planKey) @Nullable ImmutableChaingetImmutableChainByKeyIfInCacheWithConsistencyGuarantee(@NotNull PlanKey planKey) @Nullable ImmutableChaingetImmutablePlanByKey(@NotNull PlanKey planKey) Returns a plan if one exists with the key.@Nullable ImmutableChaingetImmutablePlanByKeyWithConsistencyGuarantee(@NotNull PlanKey planKey) Returns a plan if one exists with the key.@NotNull Stream<ImmutableChain>getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull Collection<PlanKey> planKeys, boolean onlyLoaded) Returns a stream of found plans for requestes plan keys.@NotNull Stream<ImmutableChain>getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull Collection<PlanKey> planKeys, boolean onlyLoaded, @NotNull Collection<PlanKey> whiteListedPlans) Returns a stream of found plans for requested plan keys.@NotNull PlanCacheIndicesReturns the indices created for plan cache content.<T extends ImmutablePlan>
@NotNull Stream<PlanKey>getPlanKeysByProject(long projectId, @NotNull Class<T> planType) Returns all keys of all plans that belong to a project and have specified type.<T extends ImmutablePlan>
@NotNull Stream<T><T extends ImmutablePlan>
@NotNull Stream<T>getPlansWithConsistencyGuarantee(Class<T> planType, @NotNull Predicate<? super T> filter) voidhideDeletedPlan(PlanKey planKey) Hides the plan.voidhideDeletedStage(Long stageId) Hides the stage.voidindexPlan(@NotNull ImmutableChain plan) Updates plan indexes in cachevoidClear the cache and attempt to read all Chains from DB in order to cache them.voidinvalidate(@NotNull PlanKey planKey) Removes the cached Plan.voidInvalidates all latest result summaries currently cached.voidinvalidateBuildNumbersRange(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete) internal use only.voidinvalidateLatestResultSummary(PlanResultKey planResultKey, boolean resetAverageBuildDuration) Resets the latest build summary of a plan.voidinvalidateSpecsStateForPlan(@NotNull PlanKey planKey) Invalidate specs state for a given planKey.voidinvalidateSpecsStateForPlan(@NotNull PlanKey planKey, @Nullable ImmutableVcsBambooSpecsSource immutableVcsBambooSpecsSource) Invalidate specs state.booleanbooleanisPlanBeingDeleted(PlanKey planKey) voidMarks the current thread as no longer being able to see deleted plans.voidonStageDeleted(long stageId) voidRemoves the cached Plan and its metadata.<T> TwithHiddenPlans(Collection<PlanKey> planKeys, Supplier<T> supplier) Invokes supplier while marking the specified plan keys as unavailable.
-
Constructor Details
-
ImmutablePlanCacheServiceImpl
public ImmutablePlanCacheServiceImpl(@NotNull @NotNull ImmutablePlanManager immutablePlanManager, @NotNull @NotNull com.atlassian.config.db.HibernateConfig hibernateConfig, @NotNull @NotNull CustomVariableContext customVariableContext, @NotNull @NotNull BuildResultsSummaryDao buildResultsSummaryDao, @NotNull @NotNull VcsRepositoryManager vcsRepositoryManager, @NotNull @NotNull BambooClusterSettings bambooClusterSettings, @NotNull @NotNull ChainBranchManager chainBranchManager)
-
-
Method Details
-
getImmutablePlanByKey
Description copied from interface:ImmutablePlanCacheServiceReturns a plan if one exists with the key. Returns null if the plan doesn't exist or if the cache entry is currently inaccessible because it is locked by another caller. In clustered mode, there is NO consistency guarantee.- Specified by:
getImmutablePlanByKeyin interfaceImmutablePlanCacheService- See Also:
-
getImmutablePlanByKeyWithConsistencyGuarantee
@Nullable public @Nullable ImmutableChain getImmutablePlanByKeyWithConsistencyGuarantee(@NotNull @NotNull PlanKey planKey) Description copied from interface:ImmutablePlanCacheServiceReturns a plan if one exists with the key. Returns null if the plan doesn't exist or if the cache entry is currently inaccessible because it is locked by another caller. There is a guarantee that the data will be up-to-date.- Specified by:
getImmutablePlanByKeyWithConsistencyGuaranteein interfaceImmutablePlanCacheService
-
getImmutablePlansByKeysWithConsistencyGuarantee
@NotNull public @NotNull Stream<ImmutableChain> getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull @NotNull Collection<PlanKey> planKeys, boolean onlyLoaded) Description copied from interface:ImmutablePlanCacheServiceReturns a stream of found plans for requestes plan keys. There are no nulls in the stream. There is a guarantee that the data will be up-to-date.- Specified by:
getImmutablePlansByKeysWithConsistencyGuaranteein interfaceImmutablePlanCacheService
-
getImmutablePlansByKeysWithConsistencyGuarantee
@NotNull public @NotNull Stream<ImmutableChain> getImmutablePlansByKeysWithConsistencyGuarantee(@NotNull @NotNull Collection<PlanKey> planKeys, boolean onlyLoaded, @NotNull @NotNull Collection<PlanKey> whiteListedPlans) Description copied from interface:ImmutablePlanCacheServiceReturns a stream of found plans for requested plan keys. There are no nulls in the stream. There is a guarantee that the data will be up-to-date. IfBambooClusterSettings.isOptimisticLockingEnabled()is disabled, then no consistency is made.- Specified by:
getImmutablePlansByKeysWithConsistencyGuaranteein interfaceImmutablePlanCacheService- Parameters:
planKeys- the plan keys to retrieve data foronlyLoaded- determines if keys not found in the cache will be loaded (false) or not (true)whiteListedPlans- the plans that are already considered up-to-date, i.e., they are already highly-consistent and no check will be made if they are found in the cache.- Returns:
- the plans found in the cache and, if onlyLoaded=false, the eventual ones that were loaded.
-
getImmutableChainByKeyIfInCache
@Nullable public @Nullable ImmutableChain getImmutableChainByKeyIfInCache(@NotNull @NotNull PlanKey planKey) - Specified by:
getImmutableChainByKeyIfInCachein interfaceImmutablePlanCacheService
-
getImmutableChainByKeyIfInCacheWithConsistencyGuarantee
@Nullable public @Nullable ImmutableChain getImmutableChainByKeyIfInCacheWithConsistencyGuarantee(@NotNull @NotNull PlanKey planKey) - Specified by:
getImmutableChainByKeyIfInCacheWithConsistencyGuaranteein interfaceImmutablePlanCacheService
-
invalidate
Description copied from interface:ImmutablePlanCacheServiceRemoves the cached Plan. Retains Plan metadata.- Specified by:
invalidatein interfaceImmutablePlanCacheService- Parameters:
planKey- key of the Plan to be removed from cache
-
cascadeInvalidate
Description copied from interface:ImmutablePlanCacheServiceRemoves the cached reference for the passed plan and its children. Currently only propagates invalidation from Chain to ChainBranch- Specified by:
cascadeInvalidatein interfaceImmutablePlanCacheService- Parameters:
planKey- key of the Plan to be removed from cache
-
getChainsToInvalidateAndReindex
public void getChainsToInvalidateAndReindex(ImmutablePlanCacheService.CacheInvalidator invalidator, Set<PlanKey> chainsToInvalidate, Set<PlanKey> chainsToReindex) Description copied from interface:ImmutablePlanCacheServiceInternal.- Specified by:
getChainsToInvalidateAndReindexin interfaceImmutablePlanCacheService
-
remove
Description copied from interface:ImmutablePlanCacheServiceRemoves the cached Plan and its metadata.- Specified by:
removein interfaceImmutablePlanCacheService- Parameters:
planKey- key of the Plan to be removed from cache
-
onStageDeleted
public void onStageDeleted(long stageId) - Specified by:
onStageDeletedin interfaceImmutablePlanCacheService
-
initialiseCache
public void initialiseCache()Description copied from interface:ImmutablePlanCacheServiceClear the cache and attempt to read all Chains from DB in order to cache them. If cache was disabled it will be enabled by this method.- Specified by:
initialiseCachein interfaceImmutablePlanCacheService
-
disableCache
public void disableCache()Description copied from interface:ImmutablePlanCacheServiceDisable cache. When cache is disabled all cache requests will be logged with severity WARN until cache will be enabled again. This method will clear cache.- Specified by:
disableCachein interfaceImmutablePlanCacheService
-
enableCache
public void enableCache()Description copied from interface:ImmutablePlanCacheServiceEnable cache. This method will not load anything when it is enabled, you should consider callingImmutablePlanCacheService.initialiseCache()instead if you expect plans to be loaded.- Specified by:
enableCachein interfaceImmutablePlanCacheService
-
isCacheEnabled
public boolean isCacheEnabled()- Specified by:
isCacheEnabledin interfaceImmutablePlanCacheService- Returns:
- true if cache is enabled
-
getCacheStats
Description copied from interface:ImmutablePlanCacheServiceRetrieve cache statistics- Specified by:
getCacheStatsin interfaceImmutablePlanCacheService- Returns:
- Cache statistics
-
getIndices
Description copied from interface:ImmutablePlanCacheServiceReturns the indices created for plan cache content.- Specified by:
getIndicesin interfaceImmutablePlanCacheService
-
getPlans
@NotNull public <T extends ImmutablePlan> @NotNull Stream<T> getPlans(Class<T> planType, @NotNull @NotNull Predicate<? super T> filter) Description copied from interface:ImmutablePlanCacheServiceReturns allPlan's filtered byClass. Does not include plans marked for deletion. In clustered mode, there is NO consistency guarantee.- Specified by:
getPlansin interfaceImmutablePlanCacheService- Parameters:
planType- - the type of the plan to retrieve- Returns:
- plans sorted by
DescriptionProvider.getName()
-
getPlansWithConsistencyGuarantee
@NotNull public <T extends ImmutablePlan> @NotNull Stream<T> getPlansWithConsistencyGuarantee(Class<T> planType, @NotNull @NotNull Predicate<? super T> filter) Description copied from interface:ImmutablePlanCacheServiceReturns allPlan's filtered byClass. Does not include plans marked for deletion. There is a guarantee that the data will be up-to-date.- Specified by:
getPlansWithConsistencyGuaranteein interfaceImmutablePlanCacheService- Parameters:
planType- - the type of the plan to retrieve- Returns:
- plans sorted by
DescriptionProvider.getName()
-
getBranchKeysOfChain
Description copied from interface:ImmutablePlanCacheServiceReturns all cached branches associated with a master plan identified by the given key. For a highly-consistent implementation (with checks for eventual new branches in the database), please considerImmutablePlanCacheService.getBranchKeysOfChainWithConsistencyGuarantee(PlanKey).- Specified by:
getBranchKeysOfChainin interfaceImmutablePlanCacheService- Parameters:
chainKey- the key of the chain- Returns:
- the branches present in the cache that are associated with a master plan identified by the given key
-
getBranchKeysOfChainWithConsistencyGuarantee
@NotNull public @NotNull ImmutableCacheResults<PlanKey> getBranchKeysOfChainWithConsistencyGuarantee(@NotNull @NotNull PlanKey chainKey) Description copied from interface:ImmutablePlanCacheServiceReturns all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.- Specified by:
getBranchKeysOfChainWithConsistencyGuaranteein interfaceImmutablePlanCacheService- Parameters:
chainKey- the key of the chain- Returns:
- highly-consistent list of branches associated with a master plan identified by the given key, including cached and not-cached data.
-
getBranchGistsOfChain
@NotNull public @NotNull Stream<PlanBranchGist> getBranchGistsOfChain(@NotNull @NotNull PlanKey chainKey) Description copied from interface:ImmutablePlanCacheServiceReturns the Gists of all cached branches associated with a master plan identified by the given key. For a highly-consistent implementation (with checks for eventual new branches in the database), please considerImmutablePlanCacheService.getBranchGistsOfChainWithConsistencyGuarantee(PlanKey).- Specified by:
getBranchGistsOfChainin interfaceImmutablePlanCacheService- Parameters:
chainKey- the key of the chain- Returns:
- the branches' gists present in the cache that are associated with a master plan identified by the given key
-
getBranchGistsOfChainWithConsistencyGuarantee
@NotNull public @NotNull ImmutableCacheResults<PlanBranchGist> getBranchGistsOfChainWithConsistencyGuarantee(@NotNull @NotNull PlanKey chainKey) Description copied from interface:ImmutablePlanCacheServiceReturns the Gists of all branches associated with a master plan identified by a given plan key, with guarantee that eventual new plan branches not present in the cache will be taken in consideration.- Specified by:
getBranchGistsOfChainWithConsistencyGuaranteein interfaceImmutablePlanCacheService- Parameters:
chainKey- the key of the chain- Returns:
- highly-consistent list of branches' gists associated with a master plan identified by the given key, including cached and not-cached data.
-
getPlanKeysByProject
@NotNull public <T extends ImmutablePlan> @NotNull Stream<PlanKey> getPlanKeysByProject(long projectId, @NotNull @NotNull Class<T> planType) Description copied from interface:ImmutablePlanCacheServiceReturns all keys of all plans that belong to a project and have specified type.- Specified by:
getPlanKeysByProjectin interfaceImmutablePlanCacheService
-
withHiddenPlans
Description copied from interface:ImmutablePlanCacheServiceInvokes supplier while marking the specified plan keys as unavailable. Other callers will not be able to access the cache entries for the specified plans while the supplier is executing. The write locks will be obtained in a deterministic order to avoid deadlocks.- Specified by:
withHiddenPlansin interfaceImmutablePlanCacheService- Returns:
- the value produced by supplier.
-
getBuildNumbersRange
Description copied from interface:ImmutablePlanCacheServiceinternal use only.- Specified by:
getBuildNumbersRangein interfaceImmutablePlanCacheService
-
invalidateBuildNumbersRange
public void invalidateBuildNumbersRange(PlanKey planKey, int buildNumber, boolean trueForSaveFalseForDelete) Description copied from interface:ImmutablePlanCacheServiceinternal use only.- Specified by:
invalidateBuildNumbersRangein interfaceImmutablePlanCacheService
-
getAnyPlan
Description copied from interface:ImmutablePlanCacheServiceReturns a plan matching the supplied predicate- Specified by:
getAnyPlanin interfaceImmutablePlanCacheService
-
invalidateLatestResultSummary
public void invalidateLatestResultSummary(PlanResultKey planResultKey, boolean resetAverageBuildDuration) Description copied from interface:ImmutablePlanCacheServiceResets the latest build summary of a plan. No op if we already cache a later plan result or we don't have plan or result cached.- Specified by:
invalidateLatestResultSummaryin interfaceImmutablePlanCacheService
-
invalidateAllLatestResultSummaries
public void invalidateAllLatestResultSummaries()Description copied from interface:ImmutablePlanCacheServiceInvalidates all latest result summaries currently cached.- Specified by:
invalidateAllLatestResultSummariesin interfaceImmutablePlanCacheService
-
invalidateSpecsStateForPlan
public void invalidateSpecsStateForPlan(@NotNull @NotNull PlanKey planKey, @Nullable @Nullable ImmutableVcsBambooSpecsSource immutableVcsBambooSpecsSource) Description copied from interface:ImmutablePlanCacheServiceInvalidate specs state.- Specified by:
invalidateSpecsStateForPlanin interfaceImmutablePlanCacheService- Parameters:
planKey- plan keyimmutableVcsBambooSpecsSource- new state
-
invalidateSpecsStateForPlan
Description copied from interface:ImmutablePlanCacheServiceInvalidate specs state for a given planKey.- Specified by:
invalidateSpecsStateForPlanin interfaceImmutablePlanCacheService- Parameters:
planKey- plan key
-
indexPlan
Description copied from interface:ImmutablePlanCacheServiceUpdates plan indexes in cache- Specified by:
indexPlanin interfaceImmutablePlanCacheService
-
hideDeletedPlan
Description copied from interface:ImmutablePlanCacheServiceHides the plan. Only the deletion thread will see it.- Specified by:
hideDeletedPlanin interfaceImmutablePlanCacheService
-
hideDeletedStage
Description copied from interface:ImmutablePlanCacheServiceHides the stage. Only the deletion thread will see it.- Specified by:
hideDeletedStagein interfaceImmutablePlanCacheService
-
isPlanBeingDeleted
- Specified by:
isPlanBeingDeletedin interfaceImmutablePlanCacheService
-
enterDeletionCodeSection
public void enterDeletionCodeSection()Description copied from interface:ImmutablePlanCacheServiceMarks the current thread as being able to see deleted plans.- Specified by:
enterDeletionCodeSectionin interfaceImmutablePlanCacheService
-
leaveDeletionCodeSection
public void leaveDeletionCodeSection()Description copied from interface:ImmutablePlanCacheServiceMarks the current thread as no longer being able to see deleted plans.- Specified by:
leaveDeletionCodeSectionin interfaceImmutablePlanCacheService
-
filterOutDeletedIfNeeded
@NotNull public <T extends ImmutableJob> @NotNull Set<T> filterOutDeletedIfNeeded(@NotNull @NotNull Set<T> jobs) Description copied from interface:ImmutablePlanCacheServiceReturns a set with deleted jobs removed. When running under deletion code, returns the same set.- Specified by:
filterOutDeletedIfNeededin interfaceImmutablePlanCacheService
-
filterOutDeletedIfNeeded
@NotNull public <T extends ImmutableChainStage> @NotNull List<T> filterOutDeletedIfNeeded(@NotNull @NotNull List<T> stages) Description copied from interface:ImmutablePlanCacheServiceReturns a list with deleted stages removed. When running under deletion code, returns the same list.- Specified by:
filterOutDeletedIfNeededin interfaceImmutablePlanCacheService
-