Package com.github.jsonldjava.utils
Class JarCacheStorage
java.lang.Object
com.github.jsonldjava.utils.JarCacheStorage
- All Implemented Interfaces:
org.apache.http.client.cache.HttpCacheStorage
public class JarCacheStorage
extends Object
implements org.apache.http.client.cache.HttpCacheStorage
Implementation of the Apache HttpClient
HttpCacheStorage
interface
using jarcache.json
files on the classpath to identify static JSON-LD
resources on the classpath, to avoid retrieving them.-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final org.apache.http.impl.client.cache.CacheConfig
private static final ConcurrentMap
<Object, List<URL>> Cached URLs from the given ClassLoader to identified locations of jarcache.json resources on the classpath Uses a Guava concurrent weak reference key map to avoid holding onto ClassLoader instances after they are otherwise unavailable.private ClassLoader
The classloader to use, defaults to null which will use the thread context classloader.private final org.apache.http.client.cache.HttpCacheStorage
All live caching that is not found locally is delegated to this implementation.private static final String
The classpath location that is searched inside of the classloader set for this cache.private final com.google.common.cache.LoadingCache
<URL, com.fasterxml.jackson.databind.JsonNode> Map from uri of jarcache.json (e.g.private final org.slf4j.Logger
private final com.fasterxml.jackson.databind.ObjectMapper
private static final Object
A holder for the case where the System class loader needs to be used, but cannot be directly identified in another way. -
Constructor Summary
ConstructorsConstructorDescriptionJarCacheStorage
(ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig) JarCacheStorage
(ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig, org.apache.http.client.cache.HttpCacheStorage delegate) -
Method Summary
Modifier and TypeMethodDescriptionprotected org.apache.http.client.cache.HttpCacheEntry
cacheEntry
(URI requestedUri, URL baseURL, com.fasterxml.jackson.databind.JsonNode cacheNode) org.apache.http.impl.client.cache.CacheConfig
org.apache.http.client.cache.HttpCacheEntry
protected com.fasterxml.jackson.databind.JsonNode
getJarCache
(URL url) Get all of thejarcache.json
resources that exist on the classpathvoid
void
removeEntry
(String key) void
setClassLoader
(ClassLoader classLoader) Sets the ClassLoader used internally to a new value, or null to useThread.currentThread()
andThread.getContextClassLoader()
for each access.void
updateEntry
(String key, org.apache.http.client.cache.HttpCacheUpdateCallback callback)
-
Field Details
-
JARCACHE_JSON
The classpath location that is searched inside of the classloader set for this cache. Note this search is also done on the Thread contextClassLoader if none is explicitly set, and the System classloader if there is no contextClassLoader.- See Also:
-
log
private final org.slf4j.Logger log -
cacheConfig
private final org.apache.http.impl.client.cache.CacheConfig cacheConfig -
classLoader
The classloader to use, defaults to null which will use the thread context classloader. -
NULL_CLASS_LOADER
A holder for the case where the System class loader needs to be used, but cannot be directly identified in another way. Used as a key in cachedResourceList. -
delegate
private final org.apache.http.client.cache.HttpCacheStorage delegateAll live caching that is not found locally is delegated to this implementation. -
mapper
private final com.fasterxml.jackson.databind.ObjectMapper mapper -
jarCaches
private final com.google.common.cache.LoadingCache<URL,com.fasterxml.jackson.databind.JsonNode> jarCachesMap from uri of jarcache.json (e.g. jar://blab.jar!jarcache.json) to a SoftReference to its parsed content as JsonNode.- See Also:
-
cachedResourceList
Cached URLs from the given ClassLoader to identified locations of jarcache.json resources on the classpath Uses a Guava concurrent weak reference key map to avoid holding onto ClassLoader instances after they are otherwise unavailable.
-
-
Constructor Details
-
JarCacheStorage
public JarCacheStorage(ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig) -
JarCacheStorage
public JarCacheStorage(ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig, org.apache.http.client.cache.HttpCacheStorage delegate)
-
-
Method Details
-
getClassLoader
-
setClassLoader
Sets the ClassLoader used internally to a new value, or null to useThread.currentThread()
andThread.getContextClassLoader()
for each access.- Parameters:
classLoader
- The classloader to use, or null to use the thread context classloader
-
putEntry
public void putEntry(String key, org.apache.http.client.cache.HttpCacheEntry entry) throws IOException - Specified by:
putEntry
in interfaceorg.apache.http.client.cache.HttpCacheStorage
- Throws:
IOException
-
getEntry
- Specified by:
getEntry
in interfaceorg.apache.http.client.cache.HttpCacheStorage
- Throws:
IOException
-
getResources
Get all of thejarcache.json
resources that exist on the classpath- Returns:
- A cached list of jarcache.json classpath resources as
URL
s - Throws:
IOException
- If there was an IO error while scanning the classpath
-
getJarCache
- Throws:
IOException
-
cacheEntry
protected org.apache.http.client.cache.HttpCacheEntry cacheEntry(URI requestedUri, URL baseURL, com.fasterxml.jackson.databind.JsonNode cacheNode) throws MalformedURLException, IOException - Throws:
MalformedURLException
IOException
-
removeEntry
- Specified by:
removeEntry
in interfaceorg.apache.http.client.cache.HttpCacheStorage
- Throws:
IOException
-
updateEntry
public void updateEntry(String key, org.apache.http.client.cache.HttpCacheUpdateCallback callback) throws IOException, org.apache.http.client.cache.HttpCacheUpdateException - Specified by:
updateEntry
in interfaceorg.apache.http.client.cache.HttpCacheStorage
- Throws:
IOException
org.apache.http.client.cache.HttpCacheUpdateException
-
getCacheConfig
public org.apache.http.impl.client.cache.CacheConfig getCacheConfig()
-