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 java.lang.Object implements org.apache.http.client.cache.HttpCacheStorageImplementation of the Apache HttpClientHttpCacheStorageinterface usingjarcache.jsonfiles on the classpath to identify static JSON-LD resources on the classpath, to avoid retrieving them.
-
-
Field Summary
Fields Modifier and Type Field Description private org.apache.http.impl.client.cache.CacheConfigcacheConfigprivate static java.util.concurrent.ConcurrentMap<java.lang.Object,java.util.List<java.net.URL>>cachedResourceListCached 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 java.lang.ClassLoaderclassLoaderThe classloader to use, defaults to null which will use the thread context classloader.private org.apache.http.client.cache.HttpCacheStoragedelegateAll live caching that is not found locally is delegated to this implementation.private static java.lang.StringJARCACHE_JSONThe classpath location that is searched inside of the classloader set for this cache.private com.google.common.cache.LoadingCache<java.net.URL,com.fasterxml.jackson.databind.JsonNode>jarCachesMap from uri of jarcache.json (e.g.private org.slf4j.Loggerlogprivate com.fasterxml.jackson.databind.ObjectMappermapperprivate static java.lang.ObjectNULL_CLASS_LOADERA holder for the case where the System class loader needs to be used, but cannot be directly identified in another way.
-
Constructor Summary
Constructors Constructor Description JarCacheStorage(java.lang.ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig)JarCacheStorage(java.lang.ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig, org.apache.http.client.cache.HttpCacheStorage delegate)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected org.apache.http.client.cache.HttpCacheEntrycacheEntry(java.net.URI requestedUri, java.net.URL baseURL, com.fasterxml.jackson.databind.JsonNode cacheNode)org.apache.http.impl.client.cache.CacheConfiggetCacheConfig()java.lang.ClassLoadergetClassLoader()org.apache.http.client.cache.HttpCacheEntrygetEntry(java.lang.String key)protected com.fasterxml.jackson.databind.JsonNodegetJarCache(java.net.URL url)private java.util.List<java.net.URL>getResources()Get all of thejarcache.jsonresources that exist on the classpathvoidputEntry(java.lang.String key, org.apache.http.client.cache.HttpCacheEntry entry)voidremoveEntry(java.lang.String key)voidsetClassLoader(java.lang.ClassLoader classLoader)Sets the ClassLoader used internally to a new value, or null to useThread.currentThread()andThread.getContextClassLoader()for each access.voidupdateEntry(java.lang.String key, org.apache.http.client.cache.HttpCacheUpdateCallback callback)
-
-
-
Field Detail
-
JARCACHE_JSON
private static final java.lang.String 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:
- Constant Field Values
-
log
private final org.slf4j.Logger log
-
cacheConfig
private final org.apache.http.impl.client.cache.CacheConfig cacheConfig
-
classLoader
private java.lang.ClassLoader classLoader
The classloader to use, defaults to null which will use the thread context classloader.
-
NULL_CLASS_LOADER
private static final java.lang.Object 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 delegate
All 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<java.net.URL,com.fasterxml.jackson.databind.JsonNode> jarCaches
Map from uri of jarcache.json (e.g. jar://blab.jar!jarcache.json) to a SoftReference to its parsed content as JsonNode.- See Also:
getJarCache(URL)
-
cachedResourceList
private static final java.util.concurrent.ConcurrentMap<java.lang.Object,java.util.List<java.net.URL>> 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 Detail
-
JarCacheStorage
public JarCacheStorage(java.lang.ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig)
-
JarCacheStorage
public JarCacheStorage(java.lang.ClassLoader classLoader, org.apache.http.impl.client.cache.CacheConfig cacheConfig, org.apache.http.client.cache.HttpCacheStorage delegate)
-
-
Method Detail
-
getClassLoader
public java.lang.ClassLoader getClassLoader()
-
setClassLoader
public void setClassLoader(java.lang.ClassLoader classLoader)
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(java.lang.String key, org.apache.http.client.cache.HttpCacheEntry entry) throws java.io.IOException- Specified by:
putEntryin interfaceorg.apache.http.client.cache.HttpCacheStorage- Throws:
java.io.IOException
-
getEntry
public org.apache.http.client.cache.HttpCacheEntry getEntry(java.lang.String key) throws java.io.IOException- Specified by:
getEntryin interfaceorg.apache.http.client.cache.HttpCacheStorage- Throws:
java.io.IOException
-
getResources
private java.util.List<java.net.URL> getResources() throws java.io.IOExceptionGet all of thejarcache.jsonresources that exist on the classpath- Returns:
- A cached list of jarcache.json classpath resources as
URLs - Throws:
java.io.IOException- If there was an IO error while scanning the classpath
-
getJarCache
protected com.fasterxml.jackson.databind.JsonNode getJarCache(java.net.URL url) throws java.io.IOException- Throws:
java.io.IOException
-
cacheEntry
protected org.apache.http.client.cache.HttpCacheEntry cacheEntry(java.net.URI requestedUri, java.net.URL baseURL, com.fasterxml.jackson.databind.JsonNode cacheNode) throws java.net.MalformedURLException, java.io.IOException- Throws:
java.net.MalformedURLExceptionjava.io.IOException
-
removeEntry
public void removeEntry(java.lang.String key) throws java.io.IOException- Specified by:
removeEntryin interfaceorg.apache.http.client.cache.HttpCacheStorage- Throws:
java.io.IOException
-
updateEntry
public void updateEntry(java.lang.String key, org.apache.http.client.cache.HttpCacheUpdateCallback callback) throws java.io.IOException, org.apache.http.client.cache.HttpCacheUpdateException- Specified by:
updateEntryin interfaceorg.apache.http.client.cache.HttpCacheStorage- Throws:
java.io.IOExceptionorg.apache.http.client.cache.HttpCacheUpdateException
-
getCacheConfig
public org.apache.http.impl.client.cache.CacheConfig getCacheConfig()
-
-