Class ConcurrentAuthorityFactory<DAO extends GeodeticAuthorityFactory>

Object
AbstractFactory
GeodeticAuthorityFactory
ConcurrentAuthorityFactory<DAO>
Type Parameters:
DAO - the type of factory used as Data Access Object (DAO).
All Implemented Interfaces:
Auto­Closeable, Authority­Factory, Factory
Direct Known Subclasses:
EPSGFactory

public abstract class ConcurrentAuthorityFactory<DAO extends GeodeticAuthorityFactory> extends GeodeticAuthorityFactory implements AutoCloseable
A concurrent authority factory that caches all objects created by another factory. All create­Foo(String) methods first check if a previously created object exists for the given code. If such object exists, it is returned. Otherwise, the object creation is delegated to another factory given by new­Data­Access() and the result is cached in this factory.

Concurrent­Authority­Factory delays the call to new­Data­Access() until first needed, and closes the factory used as a Data Access Object (DAO) after some timeout. This approach allows to establish a connection to a database (for example) and keep it only for a relatively short amount of time.

Caching strategy

Objects are cached by strong references, up to the amount of objects specified at construction time. If a greater amount of objects are cached, then the oldest ones will be retained through a weak reference instead of a strong one. This means that this caching factory will continue to return those objects as long as they are in use somewhere else in the Java virtual machine, but will be discarded (and recreated on the fly if needed) otherwise.

Multi-threading

The cache managed by this class is concurrent. However, the Data Access Objects (DAO) are assumed non-concurrent. If two or more threads are accessing this factory at the same time, then two or more Data Access Object instances may be created. The maximal amount of instances to create is specified at Concurrent­Authority­Factory construction time. If more Data Access Object instances are needed, some of the threads will block until an instance become available.

Note for subclasses

This abstract class does not implement any of the Datum­Authority­Factory, CSAuthority­Factory, CRSAuthority­Factory and Coordinate­Operation­Authority­Factory interfaces. Subclasses should select the interfaces that they choose to implement.
Since:
0.7