Class TLfnCachingTileStore
- All Implemented Interfaces:
ILfnResourceMetadataResolver
,Closeable
,AutoCloseable
All write operations (ALfnTileStoreWrapper.deleteResource(java.lang.String)
, ALfnTileStoreWrapper.putResourceMetadata(T)
etc.) work on the remote Tile Store.
These operations propagate failures of the remote Tile Store onto the handlers.
The query(com.luciad.fusion.tilestore.ILfnQueryHandler, com.luciad.fusion.tilestore.TLfnQuery)
operation first tries the remote Tile Store, and only falls back to the tile cache in case of a failure.
The ALfnCoverage.getTile(com.luciad.fusion.core.TLfnTileCoordinates, long, java.nio.channels.WritableByteChannel, java.nio.ByteBuffer, com.luciad.fusion.tilestore.ILfnReadCallback)
operation tries the tile cache first, and only falls back to the remote Tile Store in case of a cache miss.
This may return stale tiles: when tiles are deleted or updated on the remote Tile Store, a stale cached version may still be returned.
The staleness of cached tiles can be controlled with the expiration duration, but is ignored if the remote Tile Store is offline.
A low expiration duration yields tiles that are less state, at the expense of bandwidth.
Caching and expiration of tiles works according to the following rules:
- If a tile is not found in cache and is found on the remote Tile Store, the result is the new tile.
- If a tile is not found in cache and is not found on the remote Tile Store, the result is "tile not found".
- If a tile is found in cache and not expired, the result is the cached tile.
- If a tile is found in cache and expired and found on the remote Tile Store, the result is the new tile. The cached tile is updated and its expiration duration is reset.
- If a tile is found in cache and expired and not found on the remote Tile Store, the result is "tile not found". The cached tile is deleted.
- If the remote Tile Store is offline and a tile is not found in cache, the result is "tile not found".
- If the remote Tile Store is offline and a tile is found in cache, the result is the cached tile, regardless of whether it is expired or not.
- Failures meaning "remote Tile Store offline" are never propagated onto the user's handler.
The user can check if the remote Tile Store is online with the method
isOnline()
. - Failures other than "remote Tile Store offline" are always propagated onto the user's handler.
Read operations query(com.luciad.fusion.tilestore.ILfnQueryHandler, com.luciad.fusion.tilestore.TLfnQuery) and ALfnCoverage.getTile(com.luciad.fusion.core.TLfnTileCoordinates, long, java.nio.channels.WritableByteChannel, java.nio.ByteBuffer, com.luciad.fusion.tilestore.ILfnReadCallback)
never propagate failures of the remote Tile Store onto the handlers.
This allows users to continue working offline.
The remote Tile Store instance is owned (created and maintained) by an instance of this class. Closing an instance
also closes the Tile Store it owns. Remote Tile Store instances are created through the ALfnTileStoreProvider
.
When the remote Tile Store is offline, an instance of this class will regularly attempt to reconnect by recreating a new remote Tile Store instance.
The tile cache instance is never owned by an instance of this class. This means that the tile cache instance is
not closed when the caching instance is closed. Tile stores that are retrieved from an ALfnTileStoreProvider
must be closed by destroying the tile store provider instance.
In either case, the tile cache must not be in use by other clients.
It is a known limitation of this implementation that it ignores the modification time of a 'getTile' request. As a result, the implementation never returns "not modified", but always transfers the whole data, even if it has a modification time less than or equal to a modification time. In other words, the benefit of "conditional" 'getTile' requests is lost.
- Since:
- 2013.0
-
Nested Class Summary
Nested classes/interfaces inherited from class com.luciad.fusion.tilestore.ALfnTileStore
ALfnTileStore.CommitPolicy, ALfnTileStore.ReadResult, ALfnTileStore.Result, ALfnTileStore.WriteResult
-
Field Summary
Fields inherited from class com.luciad.fusion.tilestore.ALfnTileStoreWrapper
fDelegate
-
Constructor Summary
ConstructorDescriptionTLfnCachingTileStore
(ALfnTileStoreProvider aTileStoreProvider, URI aTileStoreUri, ALfnTileStore aTileCache, long aLowMark, long aHighMark, long aExpirationDuration) Constructs an instance of this class, using a local Tile Store owned by the caller as tile cache.TLfnCachingTileStore
(ALfnTileStoreProvider aTileStoreProvider, URI aTileStoreUri, URI aTileCacheUri, long aLowMark, long aHighMark, long aExpirationDuration) Constructs an instance of this class, using a tile cache owned by the instance. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this Tile Store instance.Gets the capabilities offered by the Tile Store.getCoverage
(String aID) Gets a coverage from the Tile Store.<T extends ALfnResourceMetadata>
TGets the metadata of a resource.boolean
isOnline()
Checks if this caching Tile Store is working in online or offline mode.Future
<?> query
(ILfnQueryHandler aHandler, TLfnQuery aQuery) Queries the Tile Store for resources' metadata.toString()
Returns the URI as a string representation of this Tile Store.Methods inherited from class com.luciad.fusion.tilestore.ALfnTileStoreWrapper
deleteResource, deleteUserData, getAsset, getCoverageIds, getMetadata, getRasterAssetMetadata, getRasterCoverageMetadata, getTheme, getThemeMetadata, getURI, getUserData, getVectorAssetMetadata, getVectorCoverageMetadata, putMetadata, putRasterAssetMetadata, putRasterCoverageMetadata, putResourceMetadata, putThemeMetadata, putUserData, putVectorAssetMetadata, putVectorCoverageMetadata, query
-
Constructor Details
-
TLfnCachingTileStore
public TLfnCachingTileStore(ALfnTileStoreProvider aTileStoreProvider, URI aTileStoreUri, ALfnTileStore aTileCache, long aLowMark, long aHighMark, long aExpirationDuration) throws TLfnServiceException, IOException Constructs an instance of this class, using a local Tile Store owned by the caller as tile cache.Closing this instance will close the remote Tile Store but not the tile cache, since it is owned by the caller.
The tile cache
(aTileCache)
must not be in use by other clients.- Parameters:
aTileStoreProvider
- the Tile Store provider which will be used to (re)create the Tile Store(s) from URIaTileStoreUri
- the URI of the backing Tile StoreaTileCache
- the tile cache, which must be aTLfnFileSystemTileStore
or a wrapper thereof. The tile cache instance will not be closed when this object is closed, it is the responsibility of the caller to close it. Must not be in use by other clients.aLowMark
- the cache size's low mark, in bytes, which must be positive and strictly smaller than the high mark. This is the size the cache will be reduced to when the cache is swept. This is not a strict guarantee, it is more a guideline. Setting the low mark to a significantly smaller value than the high mark will result in less frequent sweeps, at the cost of falling back to nearly no cached tiles. A good trade-off typically involves a low mark that is at 75 % of the high mark. It makes no sense to set the low mark higher than 95 % of the high mark, because that would result in too frequent sweeps with little benefit. The system will guard itself against this by keeping at least a 5 % distance between the low and high mark.When using a high mark of Long.MAX_VALUE, the low mark is irrelevant and can be set to
0
.aHighMark
- the cache size's high mark, in bytes, which must be positive. When the cache size grows larger than the high mark, the oldest tiles will automatically be swept in an attempt to keep its size between the high and low mark. Because this sweeping is an asynchronous background process, there is no guarantee that the cache size will be between the low and high mark at all times. The marks are more guidelines than strict guarantees.For maximum flexibility when working offline, use
Long.MAX_VALUE
as high mark (when disk space is no issue).aExpirationDuration
- the expiration duration of cached tiles in milliseconds. A low value yields cached tiles which are more up-to-date, at the expense of bandwidth: expired tiles will need to be reloaded from the remote Tile Store more often. Use a high value of one hour or more if you don't require up-to-date tiles. Use a low value of a couple of minutes or less if you require up-to-date tiles. For a Tile Store containing truly static tiles, you can even useLong.MAX_VALUE
.- Throws:
TLfnServiceException
IOException
-
TLfnCachingTileStore
public TLfnCachingTileStore(ALfnTileStoreProvider aTileStoreProvider, URI aTileStoreUri, URI aTileCacheUri, long aLowMark, long aHighMark, long aExpirationDuration) throws IOException, TLfnServiceException Constructs an instance of this class, using a tile cache owned by the instance.Closing this instance will close both the remote Tile Store and the tile cache.
The tile cache
(aTileCacheUri)
must not be in use by other clients.- Parameters:
aTileStoreProvider
- a Tile Store provider from which both Tile Store and tile cache will be created. It must not benull
.aTileStoreUri
- the URI of the remote Tile Store, which must not benull
aTileCacheUri
- the URI of the tile cache, which must not benull
. Must not be in use by other clients.aLowMark
- the low markaHighMark
- the high markaExpirationDuration
- the expiration duration in milliseconds since epoch- Throws:
IOException
- if creation of the tile cache or remote Tile Store failedTLfnServiceException
- if creation of the tile cache or remote Tile Store failed- See Also:
-
-
Method Details
-
query
Description copied from class:ALfnTileStore
Queries the Tile Store for resources' metadata. The query returns the metadata of resources that match a given filter and type. Even though the API is asynchronous, implementations may be synchronous or asynchronous. The default implementations are in fact synchronous, but that is an implementation detail which may change at any time.- Overrides:
query
in classALfnTileStoreWrapper
- Parameters:
aHandler
- the handler for the resultsaQuery
- the query to be performed- Returns:
- the future of the request, which could be asynchronous
-
getCapabilities
Description copied from class:ALfnTileStore
Gets the capabilities offered by the Tile Store.The capabilities provide the Tile Store metadata and the supported operations. The operations are defined as constants on this class.
- Overrides:
getCapabilities
in classALfnTileStoreWrapper
- Returns:
- the Tile Store capabilities
- Throws:
IOException
- in case of an I/O failureTLfnServiceException
- in case of a service processing failure
-
getCoverage
Description copied from class:ALfnTileStore
Gets a coverage from the Tile Store. Coverage IDs can be found using either:ALfnTileStore.getCoverageIds()
ALfnTileStore.query(ILfnQueryHandler, TLfnQuery)
and get the ID from the metadata
- Overrides:
getCoverage
in classALfnTileStoreWrapper
- Parameters:
aID
- the ID of the desired coverage- Returns:
- the coverage or
null
if it does not exist - Throws:
IOException
- in case of an I/O failureTLfnServiceException
- in case of a service processing failure- See Also:
-
getResourceMetadata
public <T extends ALfnResourceMetadata> T getResourceMetadata(String aID) throws IOException, TLfnServiceException Description copied from class:ALfnTileStore
Gets the metadata of a resource.This implementation throws
UnsupportedOperationException
. Subclasses should override it to do something useful.- Specified by:
getResourceMetadata
in interfaceILfnResourceMetadataResolver
- Overrides:
getResourceMetadata
in classALfnTileStoreWrapper
- Parameters:
aID
- the ID of the desired resource- Returns:
- the resource corresponding to the given ID, or
null
if it does not exist - Throws:
IOException
- in case of an I/O failureTLfnServiceException
- in case of a service processing failure
-
isOnline
public boolean isOnline()Checks if this caching Tile Store is working in online or offline mode. When in offline mode, only cached tiles will be used to satisfy read operations. When cached tiles are not available, "not found" will be returned rather than failing the operation. Write operations will fail in offline mode.- Returns:
true
if this cache is online,false
if is working in offline mode
-
close
Description copied from class:ALfnTileStore
Closes this Tile Store instance. This method does nothing, but subclasses may override it to do something useful.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classALfnTileStoreWrapper
- Throws:
IOException
- in case of an I/O failure
-
toString
Description copied from class:ALfnTileStore
Returns the URI as a string representation of this Tile Store.- Overrides:
toString
in classALfnTileStoreWrapper
- Returns:
- the URI as a string representation of this Tile Store
-