Package org.geotools.referencing.factory
Class DeferredAuthorityFactory
- Object
-
- AbstractFactory
-
- ReferencingFactory
-
- AbstractAuthorityFactory
-
- BufferedAuthorityFactory
-
- DeferredAuthorityFactory
-
- All Implemented Interfaces:
AuthorityFactory
,Factory
,BufferedFactory
,Factory
,OptionalFactory
,RegistrableFactory
- Direct Known Subclasses:
CoordinateOperationFactoryUsingWKT
,FactoryUsingWKT
,IAULongitudeFirstFactory
,LongitudeFirstEpsgDecorator
,LongitudeFirstFactory
,ThreadedEpsgFactory
public abstract class DeferredAuthorityFactory extends BufferedAuthorityFactory implements OptionalFactory
A buffered authority factory which will defer the creation of a backing store until when first needed. This approach allow to establish a connection to a database (for example) only when first needed. In addition, the backing store can be automatically disposed after a timeout and recreated when needed again.- Since:
- 2.1
- Author:
- Martin Desruisseaux (IRD)
-
-
Field Summary
-
Fields inherited from class ReferencingFactory
LOGGER
-
Fields inherited from class AbstractFactory
hints, MAXIMUM_PRIORITY, MINIMUM_PRIORITY, NORMAL_PRIORITY, priority
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
DeferredAuthorityFactory(Hints userHints, int priority)
Constructs an instance without initial backing store.protected
DeferredAuthorityFactory(Hints userHints, int priority, int maxStrongReferences)
Constructs an instance without initial backing store.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected boolean
canDisposeBackingStore(AbstractAuthorityFactory backingStore)
Returnstrue
if the backing store can be disposed now.protected abstract AbstractAuthorityFactory
createBackingStore()
Creates the backing store authority factory.void
dispose()
Releases resources immediately instead of waiting for the garbage collector.protected void
disposeBackingStore()
Disposes of the backing storestatic void
exit()
Gets rid of the timer thread at application shutdownprotected AbstractAuthorityFactory
getBackingStore()
Returns the backing store authority factory.boolean
isAvailable()
Returnstrue
if this factory is available.boolean
isConnected()
Returnstrue
if this deferred factory is connected to its backing store.void
setTimeout(long delay)
Set a timer for disposing the backing store after the specified amount of milliseconds of inactivity.-
Methods inherited from class BufferedAuthorityFactory
createCartesianCS, createCompoundCRS, createCoordinateOperation, createCoordinateReferenceSystem, createCoordinateSystem, createCoordinateSystemAxis, createCylindricalCS, createDatum, createDerivedCRS, createEllipsoid, createEllipsoidalCS, createEngineeringCRS, createEngineeringDatum, createExtent, createFromCoordinateReferenceSystemCodes, createGeocentricCRS, createGeodeticDatum, createGeographicCRS, createImageCRS, createImageDatum, createObject, createOperationMethod, createParameterDescriptor, createPolarCS, createPrimeMeridian, createProjectedCRS, createSphericalCS, createTemporalCRS, createTemporalDatum, createTimeCS, createUnit, createVerticalCRS, createVerticalCS, createVerticalDatum, getAuthority, getAuthorityCodes, getBackingStoreDescription, getDescriptionText, getIdentifiedObjectFinder, getVendor
-
Methods inherited from class AbstractAuthorityFactory
noSuchAuthorityCode, trimAuthority
-
Methods inherited from class ReferencingFactory
ensureNonNull
-
Methods inherited from class AbstractFactory
addImplementationHints, equals, getImplementationHints, getPriority, hashCode, onDeregistration, onRegistration, toString
-
Methods inherited from interface Factory
getImplementationHints
-
-
-
-
Constructor Detail
-
DeferredAuthorityFactory
protected DeferredAuthorityFactory(Hints userHints, int priority)
Constructs an instance without initial backing store. Subclasses are responsible for creating an appropriate backing store when thecreateBackingStore()
method is invoked.- Parameters:
userHints
- An optional set of hints, ornull
if none.priority
- The priority for this factory, as a number betweenMINIMUM_PRIORITY
andMAXIMUM_PRIORITY
inclusive.- Since:
- 2.2
- See Also:
createBackingStore()
-
DeferredAuthorityFactory
protected DeferredAuthorityFactory(Hints userHints, int priority, int maxStrongReferences)
Constructs an instance without initial backing store. Subclasses are responsible for creating an appropriate backing store when thecreateBackingStore()
method is invoked.- Parameters:
userHints
- An optional set of hints, ornull
if none.priority
- The priority for this factory, as a number betweenMINIMUM_PRIORITY
andMAXIMUM_PRIORITY
inclusive.maxStrongReferences
- The maximum number of objects to keep by strong reference.- Since:
- 2.2
- See Also:
createBackingStore()
-
-
Method Detail
-
isAvailable
public boolean isAvailable()
Returnstrue
if this factory is available. The default implementation returnsfalse
ifcreateBackingStore()
throws an exception.- Specified by:
isAvailable
in interfaceOptionalFactory
-
getBackingStore
protected final AbstractAuthorityFactory getBackingStore() throws FactoryException
Returns the backing store authority factory.- Returns:
- The backing store to uses in
createXXX(...)
methods. - Throws:
FactoryException
- if the creation of backing store failed.
-
createBackingStore
protected abstract AbstractAuthorityFactory createBackingStore() throws FactoryException
Creates the backing store authority factory. This method is invoked the first time acreateXXX(...)
method is invoked.- Returns:
- The backing store to uses in
createXXX(...)
methods. - Throws:
FactoryNotFoundException
- if the backing store has not been found.FactoryException
- if the creation of backing store failed for an other reason.
-
isConnected
public boolean isConnected()
-
setTimeout
public void setTimeout(long delay)
Set a timer for disposing the backing store after the specified amount of milliseconds of inactivity. ThecreateBackingStore()
method will be responsible for creating a new backing store when needed. Note that the backing store disposal can be vetoed ifcanDisposeBackingStore(org.geotools.referencing.factory.AbstractAuthorityFactory)
returnsfalse
.- Parameters:
delay
- The minimal delay before to close the backing store. This delay is very approximative. The backing store will not be closed before, but may take as much as twice that time before to be closed.
-
canDisposeBackingStore
protected boolean canDisposeBackingStore(AbstractAuthorityFactory backingStore)
Returnstrue
if the backing store can be disposed now. This method is invoked automatically after the amount of time specified bysetTimeout(long)
if the factory were not used during that time. The default implementation always returnstrue
. Subclasses should override this method and returnsfalse
if they want to prevent the backing store disposal under some circonstances.- Parameters:
backingStore
- The backing store in process of being disposed.
-
dispose
public void dispose() throws FactoryException
Releases resources immediately instead of waiting for the garbage collector. This method disposes the backing store regardeless ofcanDisposeBackingStore(org.geotools.referencing.factory.AbstractAuthorityFactory)
value.- Overrides:
dispose
in classBufferedAuthorityFactory
- Throws:
FactoryException
- if an error occured while disposing the factory.
-
exit
public static void exit()
Gets rid of the timer thread at application shutdown
-
disposeBackingStore
protected void disposeBackingStore()
Disposes of the backing store
-
-