Class ConcurrentAuthorityFactory.Finder

java.lang.Object
org.apache.sis.referencing.factory.IdentifiedObjectFinder
org.apache.sis.referencing.factory.ConcurrentAuthorityFactory.Finder
Enclosing class:
ConcurrentAuthorityFactory<DAO extends GeodeticAuthorityFactory>

private static final class ConcurrentAuthorityFactory.Finder extends IdentifiedObjectFinder
An implementation of IdentifiedObjectFinder which delegates the work to the underlying Data Access Object and caches the result.

Synchronization note

Our public API claims that IdentifiedObjectFinders are not thread-safe. Nevertheless we synchronize this particular implementation for safety, because the consequence of misuse are more dangerous than other implementations. Furthermore, this is also a way to assert that no code path go to the ConcurrentAuthorityFactory.create(AuthorityFactoryProxy, String) method from a non-overridden public method.
Since:
0.7
Version:
1.2
  • Field Details

    • DOMAIN_COUNT

      private static final int DOMAIN_COUNT
      Number of values in the IdentifiedObjectFinder.Domain enumeration. Hard-coded for efficiency. Value is verified using reflection by the test ConcurrentAuthorityFactoryTest.verifyDomainCount().
      See Also:
    • finder

      private transient IdentifiedObjectFinder finder
      The finder on which to delegate the work. This is acquired by acquire() and must be released by call to release() once finished.
    • acquireCount

      private transient int acquireCount
      Number of time that acquire() has been invoked. When this count reaches zero, the finder is released.
  • Constructor Details

  • Method Details

    • acquire

      private void acquire() throws org.opengis.util.FactoryException
      Acquires a new finder. The release() method must be invoked in a finally block after the call to acquire. The pattern must be as below (note that the call to acquire() is inside the try block):
      Throws:
      org.opengis.util.FactoryException
    • release

      private void release()
      Releases the finder.
    • getCodeCandidates

      protected Set<String> getCodeCandidates(org.opengis.referencing.IdentifiedObject object) throws org.opengis.util.FactoryException
      Returns a set of authority codes that may identify the same object than the specified one. This method delegates to the data access object.
      Overrides:
      getCodeCandidates in class IdentifiedObjectFinder
      Parameters:
      object - the object looked up.
      Returns:
      a set of code candidates.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while fetching the set of code candidates.
    • getFromCache

      final Set<org.opengis.referencing.IdentifiedObject> getFromCache(org.opengis.referencing.IdentifiedObject object)
      Returns the cached value for the given object, or null if none. The returned set (if non-null) is unmodifiable.
      Overrides:
      getFromCache in class IdentifiedObjectFinder
    • cache

      final Set<org.opengis.referencing.IdentifiedObject> cache(org.opengis.referencing.IdentifiedObject object, Set<org.opengis.referencing.IdentifiedObject> result)
      Stores the given result in the cache. This method wraps or copies the given set in an unmodifiable set and returns the result.
      Overrides:
      cache in class IdentifiedObjectFinder
      Parameters:
      result - the search result as a modifiable set.
      Returns:
      a set with the same content than result.
    • createCacheEntry

      private static Set<org.opengis.referencing.IdentifiedObject>[] createCacheEntry(org.opengis.referencing.IdentifiedObject object)
      Creates an initially empty cache entry for the given object.
    • index

      private static int index(IdentifiedObjectFinder finder)
      Returns the index in the cached Set<IdentifiedObject>[] array for a result using the given finder.
    • find

      public Set<org.opengis.referencing.IdentifiedObject> find(org.opengis.referencing.IdentifiedObject object) throws org.opengis.util.FactoryException
      Looks up an object from this authority factory which is approximately equal to the specified object. The default implementation performs the same lookup than the Data Access Object and caches the result.
      Overrides:
      find in class IdentifiedObjectFinder
      Parameters:
      object - the object looked up.
      Returns:
      the identified objects, or an empty set if not found.
      Throws:
      org.opengis.util.FactoryException - if an error occurred while creating an object.