Class HadoopAtlasFileCache
- java.lang.Object
-
- org.openstreetmap.atlas.utilities.caching.ConcurrentResourceCache
-
- org.openstreetmap.atlas.generator.tools.caching.HadoopAtlasFileCache
-
- All Implemented Interfaces:
org.openstreetmap.atlas.utilities.caching.ResourceCache
public class HadoopAtlasFileCache extends org.openstreetmap.atlas.utilities.caching.ConcurrentResourceCacheCache an atlas file stored in the standard way (parentpath/COUNTRY/COUNTRY_z-x-y.atlas) to a system temporary location. This cache is designed to be used with atlases that can be fetched from a hadoop file system. This cache is threadsafe. You can optionally associate a namespace with aHadoopAtlasFileCacheat creation time. This will create a unique container per-namespace for cached content.For example, consider the following code:
ResourceCache cache1 = new HadoopAtlasFileCache(parentPath, "namespace1", config);
ResourceCache cache2 = new HadoopAtlasFileCache(parentPath, "namespace2", config);
// We will be fetching resource behind URI "parentPath/AAA/AAA_1-1-1.atlas"
Resource r1 = cache1.get("AAA", new SlippyTile(1, 1, 1)).get();
// Assume some event changes the contents behind the URI between get() calls
Resource r2 = cache1.get("AAA", new SlippyTile(1, 1, 1)).get();
// This fails since the caches have different namespaces and the resource contents changed
Assert.assertEquals(r1.all(), r2.all());
// Now we invalidate cache1's copy of the resource
cache1.invalidate(getURIForResource(r1));
// This call to cache1.get() will re-fetch since we invalidated
r1 = cache1.get("AAA", new SlippyTile(1, 1, 1)).get();
// Now this passes since cache1 was refreshed
Assert.assertEquals(r1.all(), r2.all());
The key takeaway here is that
r1andr2are not guaranteed to have the same contents, even though their URIs are the same. Since the two cache instances have different namespaces, their underlying stores do not intersect. It is also worth noting that theHadoopAtlasFileCachecannot detect if the resource behind a URI has changed. You must callConcurrentResourceCache.invalidate()orConcurrentResourceCache.invalidate(URI)to force an update.
-
-
Constructor Summary
Constructors Constructor Description HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.lang.String namespace, SlippyTilePersistenceScheme atlasScheme, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.lang.String namespace, SlippyTilePersistenceScheme atlasScheme, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.HadoopAtlasFileCache(java.lang.String parentAtlasPath, SlippyTilePersistenceScheme atlasScheme, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.HadoopAtlasFileCache(java.lang.String parentAtlasPath, SlippyTilePersistenceScheme atlasScheme, org.openstreetmap.atlas.utilities.caching.strategies.CachingStrategy cachingStrategy, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.HadoopAtlasFileCache(java.lang.String parentAtlasPath, org.openstreetmap.atlas.utilities.caching.strategies.CachingStrategy cachingStrategy, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>get(java.lang.String country, org.openstreetmap.atlas.geography.sharding.Shard shard)Get anOptionalof an atlas resource specified by the given parameters.voidinvalidate(java.lang.String country, org.openstreetmap.atlas.geography.sharding.Shard shard)Invalidate a given shard for a given country.-
Methods inherited from class org.openstreetmap.atlas.utilities.caching.ConcurrentResourceCache
get, getCacheID, getStrategyName, invalidate, invalidate
-
-
-
-
Constructor Detail
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filesconfiguration- The configuration map
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filesfetcher- Function to fetch an atlas resource in case of cache miss
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, org.openstreetmap.atlas.utilities.caching.strategies.CachingStrategy cachingStrategy, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filescachingStrategy- Strategy to cache an atlas resourcefetcher- Function to fetch an atlas resource in case of cache miss
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, SlippyTilePersistenceScheme atlasScheme, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filesatlasScheme- The scheme used to locate atlas files based on slippy tilesconfiguration- The configuration map
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.lang.String namespace, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filesnamespace- The namespace for this cache's resourcesconfiguration- The configuration map
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.lang.String namespace, SlippyTilePersistenceScheme atlasScheme, java.util.Map<java.lang.String,java.lang.String> configuration)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filesnamespace- The namespace for this cache's resouresatlasScheme- The scheme used to locate atlas files based on slippy tilesconfiguration- The configuration map
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, java.lang.String namespace, SlippyTilePersistenceScheme atlasScheme, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filesnamespace- The namespace for this cache's resouresatlasScheme- The scheme used to locate atlas files based on slippy tilesfetcher- Function to fetch an atlas resource in case of cache miss
-
HadoopAtlasFileCache
public HadoopAtlasFileCache(java.lang.String parentAtlasPath, SlippyTilePersistenceScheme atlasScheme, org.openstreetmap.atlas.utilities.caching.strategies.CachingStrategy cachingStrategy, java.util.function.Function<java.net.URI,java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource>> fetcher)Create a new cache.- Parameters:
parentAtlasPath- The parent path to the atlas files. This might look like hdfs://some/path/to/filesatlasScheme- The scheme used to locate atlas files based on slippy tilescachingStrategy- Strategy to cache an atlas resourcefetcher- Function to fetch an atlas resource in case of cache miss
-
-
Method Detail
-
get
public java.util.Optional<org.openstreetmap.atlas.streaming.resource.Resource> get(java.lang.String country, org.openstreetmap.atlas.geography.sharding.Shard shard)Get anOptionalof an atlas resource specified by the given parameters.- Parameters:
country- The ISO country code of the desired shardshard- TheShardobject representing the shard- Returns:
- an
Optionalwrapping the shard
-
invalidate
public void invalidate(java.lang.String country, org.openstreetmap.atlas.geography.sharding.Shard shard)Invalidate a given shard for a given country. It is highly recommended to use this implementation overConcurrentResourceCache.invalidate(URI).- Parameters:
country- the countryshard- the shard to invalidate
-
-