Class AbstractLazyLoadRunMap<R>
- java.lang.Object
 - 
- java.util.AbstractMap<Integer,R>
 - 
- jenkins.model.lazy.AbstractLazyLoadRunMap<R>
 
 
 
- 
- Direct Known Subclasses:
 RunMap
public abstract class AbstractLazyLoadRunMap<R> extends AbstractMap<Integer,R> implements SortedMap<Integer,R>
SortedMapthat keeps build records by their build numbers, in the descending order (newer ones first.)The main thing about this class is that it encapsulates the lazy loading logic. That is, while this class looks and feels like a normal
SortedMapfrom outside, it actually doesn't have every item in the map instantiated yet. As items in the map get requested, this classretrieves themon demand, one by one.The lookup is done by using the build number as the key (hence the key type is
Integer).This class makes the following assumption about the on-disk layout of the data:
- Every build is stored in a directory, named after its number.
 
Some of the
SortedMapoperations are weakly implemented. For example,AbstractMap.size()may be inaccurate because we only count the number of directories that look like build records, without checking if they are loadable. But these weaknesses aren't distinguishable from concurrent modifications, where another thread deletes a build while one thread iterates them.Some of the
SortedMapoperations are inefficiently implemented, by loading all the build records eagerly. We hope to replace these implementations by more efficient lazy-loading ones as we go.Object lock of
thisis used to make sure mutation occurs sequentially. That is, ensure that only one thread is actually callingretrieve(File)and updatingAbstractLazyLoadRunMap.Index.byNumber.- Since:
 - 1.485
 - Author:
 - Kohsuke Kawaguchi
 
 
- 
- 
Nested Class Summary
Nested Classes Modifier and Type Class Description static classAbstractLazyLoadRunMap.Direction- 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object,V extends Object> 
 - 
 
- 
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractLazyLoadRunMap() 
- 
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected R_put(R value)protected booleanallowLoad(int buildNumber)booleanbaseDirInitialized()Comparator<? super Integer>comparator()protected BuildReference<R>createReference(R r)Allow subtype to capture a reference.Set<Map.Entry<Integer,R>>entrySet()booleanequals(Object o)IntegerfirstKey()Rget(int n)Rget(Object key)RgetById(String id)RgetByNumber(int n)protected StringgetIdOf(R r)Subtype to provideRun.getId()so that this class doesn't have to depend on it.SortedMap<Integer,R>getLoadedBuilds()Returns a read-only view of records that has already been loaded.protected abstract intgetNumberOf(R r)Subtype to provideRun.getNumber()so that this class doesn't have to depend on it.inthashCode()SortedMap<Integer,R>headMap(Integer toKey)protected voidinitBaseDir(File dir)booleanisEmpty()Set<Integer>keySet()IntegerlastKey()intmaxNumberOnDisk()RnewestBuild()RoldestBuild()protected voidproposeNewNumber(int number)voidpurgeCache()Let go of all the loaded references.Rput(Integer key, R r)Rput(R value)voidputAll(Map<? extends Integer,? extends R> rhs)voidrecognizeNumber(int buildNumber)Permits a previous blocked build number to be eligible for loading.booleanremoveValue(R run)voidreset(TreeMap<Integer,R> builds)Replaces all the current loaded Rs with the given ones.protected abstract Rretrieve(File dir)ParsesRinstance from data in the specified directory.booleanrunExists(int number)Checks if the specified build exists.Rsearch(int n, AbstractLazyLoadRunMap.Direction d)Finds the build #M where M is nearby the given 'n'.SortedMap<Integer,R>subMap(Integer fromKey, Integer toKey)SortedMap<Integer,R>tailMap(Integer fromKey)voidupdateBaseDir(File dir)Updates base directory location after directory changes.Collection<R>values()- 
Methods inherited from class java.util.AbstractMap
clear, clone, containsKey, containsValue, remove, size, toString 
- 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait 
- 
Methods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, forEach, getOrDefault, merge, putIfAbsent, remove, remove, replace, replace, replaceAll, size 
 - 
 
 - 
 
- 
- 
Field Detail
- 
dir
protected File dir
Base directory for data. In effect this is treated as a final field, but can't mark it final because the compatibility requires that we make it settable in the first call after the constructor. 
 - 
 
- 
Method Detail
- 
values
public Collection<R> values()
 
- 
initBaseDir
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) protected void initBaseDir(File dir)
 
- 
baseDirInitialized
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public final boolean baseDirInitialized()
- Returns:
 - true if 
AbstractLazyLoadRunMap()was called with a non-null param, orRunMap.load(Job, RunMap.Constructor)was called 
 
- 
updateBaseDir
public final void updateBaseDir(File dir)
Updates base directory location after directory changes. This method should be used on jobs renaming, etc.- Parameters:
 dir- Directory location- Since:
 - 1.546
 
 
- 
purgeCache
public void purgeCache()
Let go of all the loaded references. This is a bit more sophisticated version of forcing GC. Primarily for debugging and testing lazy loading behaviour.- Since:
 - 1.507
 
 
- 
allowLoad
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) protected boolean allowLoad(int buildNumber)
 
- 
recognizeNumber
@Restricted(org.kohsuke.accmod.restrictions.Beta.class) public final void recognizeNumber(int buildNumber)
Permits a previous blocked build number to be eligible for loading.- Parameters:
 buildNumber- a build number- See Also:
 RunListener.allowLoad(hudson.model.Job<?, ?>, int)
 
- 
comparator
public Comparator<? super Integer> comparator()
- Specified by:
 comparatorin interfaceSortedMap<Integer,R>
 
- 
isEmpty
public boolean isEmpty()
 
- 
getLoadedBuilds
public SortedMap<Integer,R> getLoadedBuilds()
Returns a read-only view of records that has already been loaded. 
- 
newestBuild
public R newestBuild()
 
- 
oldestBuild
public R oldestBuild()
 
- 
get
public R get(int n)
 
- 
runExists
public boolean runExists(int number)
Checks if the specified build exists.- Parameters:
 number- the build number to probe.- Returns:
 trueif there is an run for the corresponding number, note that this does not mean that the corresponding record will load.- Since:
 - 2.14
 
 
- 
search
@CheckForNull public R search(int n, AbstractLazyLoadRunMap.Direction d)
Finds the build #M where M is nearby the given 'n'.- Parameters:
 n- the index to start the search fromd- defines what we mean by "nearby" above. If EXACT, find #N or return null. If ASC, finds the closest #M that satisfies M ≥ N. If DESC, finds the closest #M that satisfies M ≤ N.
 
- 
getByNumber
public R getByNumber(int n)
 
- 
maxNumberOnDisk
@Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class) public int maxNumberOnDisk()
- Returns:
 - the highest recorded build number, or 0 if there are none
 
 
- 
proposeNewNumber
protected final void proposeNewNumber(int number) throws IllegalStateException- Throws:
 IllegalStateException
 
- 
getNumberOf
protected abstract int getNumberOf(R r)
Subtype to provideRun.getNumber()so that this class doesn't have to depend on it. 
- 
getIdOf
protected String getIdOf(R r)
Subtype to provideRun.getId()so that this class doesn't have to depend on it. 
- 
createReference
protected BuildReference<R> createReference(R r)
Allow subtype to capture a reference. 
- 
retrieve
protected abstract R retrieve(File dir) throws IOException
ParsesRinstance from data in the specified directory.- Returns:
 - null if the parsing failed.
 - Throws:
 IOException- if the parsing failed. This is just like returning null except the caller will catch the exception and report it.
 
- 
removeValue
public boolean removeValue(R run)
 
- 
reset
public void reset(TreeMap<Integer,R> builds)
Replaces all the current loaded Rs with the given ones. 
- 
hashCode
public int hashCode()
 
 - 
 
 -