Class AbstractLazyLoadRunMap<R>

  • All Implemented Interfaces:
    Map<Integer,​R>, SortedMap<Integer,​R>
    Direct Known Subclasses:
    RunMap

    public abstract class AbstractLazyLoadRunMap<R>
    extends AbstractMap<Integer,​R>
    implements SortedMap<Integer,​R>
    SortedMap that 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 SortedMap from outside, it actually doesn't have every item in the map instantiated yet. As items in the map get requested, this class retrieves them on 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 SortedMap operations 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 SortedMap operations 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 this is used to make sure mutation occurs sequentially. That is, ensure that only one thread is actually calling retrieve(File) and updating AbstractLazyLoadRunMap.Index.byNumber.

    Since:
    1.485
    Author:
    Kohsuke Kawaguchi
    • 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.
    • Constructor Detail

      • AbstractLazyLoadRunMap

        @Restricted(org.kohsuke.accmod.restrictions.NoExternalUse.class)
        protected AbstractLazyLoadRunMap​(File dir)