public class BuildCache extends Object
Modifier and Type | Class and Description |
---|---|
static class |
BuildCache.BuildComparator
Allows returned downstreamBuild Sets to be sorted first by project name and then by number.
|
static class |
BuildCache.QueueTaskComparator |
Constructor and Description |
---|
BuildCache() |
Modifier and Type | Method and Description |
---|---|
void |
doGarbageCollect() |
static BuildCache |
getCache()
Returns the instance of this class.
|
Set<hudson.model.Run> |
getDownstreamBuilds(hudson.model.Run run)
Returns all downstream builds triggered by the upstream builds.
|
Set<hudson.model.Run> |
getDownstreamBuildsByProject(hudson.model.Run upstreamBuild,
hudson.model.Job downstreamProject)
Fetches all downstream builds belonging to the specified project.
|
static Set<hudson.model.Queue.Item> |
getDownstreamQueueItems(hudson.model.Queue.Item[] items,
hudson.model.Run run)
Helper method to find downstream Queue.Items triggered by Run.
|
static Set<hudson.model.Queue.Item> |
getDownstreamQueueItems(hudson.model.Run run)
Helper method to find downstream Queue.Items triggered by Run.
|
String |
getStatistics()
Builds a summary report of the cache
|
static void |
initCache()
Initialize the cache after all jobs are loaded.
|
boolean |
isCacheRefreshing()
Indicates whether the cache is still building.
|
protected void |
removeFromCache(hudson.model.Run run)
Remove a run from the cache.
|
void |
scheduleReloadCache(boolean waitForCompletion) |
void |
setupGarbageCollector() |
void |
setupWorkerThread() |
static void |
stop() |
void |
stopGarbageCollector() |
void |
stopWorkerThread()
The using awaitTermination() is necessary, because if we allow Jenkins to continue shutting
down while still refreshing the cache, the Jenkins.getInstance() will start returning null, all
while we still try to examine builds.
|
protected void |
updateCache(hudson.model.Run downstreamRun)
Parses upstream causes in a downstream build and updates the cache.
|
public static BuildCache getCache()
@Initializer(after=JOB_LOADED) public static void initCache()
public static Set<hudson.model.Queue.Item> getDownstreamQueueItems(hudson.model.Run run)
run
- The upstream buildpublic static Set<hudson.model.Queue.Item> getDownstreamQueueItems(hudson.model.Queue.Item[] items, hudson.model.Run run)
Since Queue.getItems() is validating readability permissions on every queue item, this method allows for providing a cached version of the Queue.Items. This is helpful if many Queue downstream look-ups are needed within a very short span of time.
items
- The cached version of Queue.getItems()run
- The upstream buildpublic boolean isCacheRefreshing()
public void scheduleReloadCache(boolean waitForCompletion)
protected void updateCache(hudson.model.Run downstreamRun)
downstreamRun
- Downstream build to update the cache withpublic void doGarbageCollect()
public void setupGarbageCollector()
public void stopGarbageCollector()
public void setupWorkerThread()
public void stopWorkerThread()
We also avoid @see ExecutorService.shutdownNow(), since the InterruptedException will most likely be silenced by Jenkins in RunMap.retrieve(), where much time is spent when refreshing the cache.
public Set<hudson.model.Run> getDownstreamBuilds(hudson.model.Run run)
run
- The upstream buildpublic String getStatistics()
protected void removeFromCache(hudson.model.Run run)
run
- The run to remove from the cache.public Set<hudson.model.Run> getDownstreamBuildsByProject(hudson.model.Run upstreamBuild, hudson.model.Job downstreamProject)
upstreamBuild
- The upstream builddownstreamProject
- The downstream projectCopyright © 2016–2021. All rights reserved.