Class RepositoryCache


  • public class RepositoryCache
    extends java.lang.Object
    Cache of active Repository instances.
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static void clear()
      Unregister all repositories from the cache.
      static void close​(Repository db)
      Remove a repository from the cache.
      static Repository open​(RepositoryCache.Key location)
      Open an existing repository, reusing a cached instance if possible.
      static Repository open​(RepositoryCache.Key location, boolean mustExist)
      Open a repository, reusing a cached instance if possible.
      static void register​(Repository db)
      Register one repository into the cache.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • open

        public static Repository open​(RepositoryCache.Key location)
                               throws java.io.IOException,
                                      RepositoryNotFoundException
        Open an existing repository, reusing a cached instance if possible.

        When done with the repository, the caller must call Repository.close() to decrement the repository's usage counter.

        Parameters:
        location - where the local repository is. Typically a RepositoryCache.FileKey.
        Returns:
        the repository instance requested; caller must close when done.
        Throws:
        java.io.IOException - the repository could not be read (likely its core.version property is not supported).
        RepositoryNotFoundException - there is no repository at the given location.
      • open

        public static Repository open​(RepositoryCache.Key location,
                                      boolean mustExist)
                               throws java.io.IOException
        Open a repository, reusing a cached instance if possible.

        When done with the repository, the caller must call Repository.close() to decrement the repository's usage counter.

        Parameters:
        location - where the local repository is. Typically a RepositoryCache.FileKey.
        mustExist - If true, and the repository is not found, throws RepositoryNotFoundException. If false, a repository instance is created and registered anyway.
        Returns:
        the repository instance requested; caller must close when done.
        Throws:
        java.io.IOException - the repository could not be read (likely its core.version property is not supported).
        RepositoryNotFoundException - There is no repository at the given location, only thrown if mustExist is true.
      • register

        public static void register​(Repository db)
        Register one repository into the cache.

        During registration the cache automatically increments the usage counter, permitting it to retain the reference. A RepositoryCache.FileKey for the repository's Repository.getDirectory() is used to index the repository in the cache.

        If another repository already is registered in the cache at this location, the other instance is closed.

        Parameters:
        db - repository to register.
      • close

        public static void close​(Repository db)
        Remove a repository from the cache.

        Removes a repository from the cache, if it is still registered here, permitting it to close.

        Parameters:
        db - repository to unregister.
      • clear

        public static void clear()
        Unregister all repositories from the cache.