K
- cache entry key typeV
- cache value typepublic abstract class JCSCachedTileLoaderJob<K,V extends CacheEntry> extends java.lang.Object implements ICachedLoaderJob<K>
Modifier and Type | Field and Description |
---|---|
protected static long |
ABSOLUTE_EXPIRE_TIME_LIMIT |
protected CacheEntryAttributes |
attributes |
private org.apache.commons.jcs.access.behavior.ICacheAccess<K,V> |
cache |
protected V |
cacheData |
private org.apache.commons.jcs.engine.behavior.ICacheElement<K,V> |
cacheElement |
private int |
connectTimeout |
private static java.util.concurrent.ThreadPoolExecutor |
DEFAULT_DOWNLOAD_JOB_DISPATCHER |
protected static long |
DEFAULT_EXPIRE_TIME |
private java.util.concurrent.ThreadPoolExecutor |
downloadJobExecutor |
protected static long |
EXPIRE_TIME_SERVER_LIMIT |
private java.lang.Runnable |
finishTask |
private boolean |
force |
private java.util.Map<java.lang.String,java.lang.String> |
headers |
private static java.util.concurrent.ConcurrentMap<java.lang.String,java.util.Set<ICachedLoaderListener>> |
inProgress |
private long |
minimumExpiryTime |
protected long |
now |
private int |
readTimeout |
static IntegerProperty |
THREAD_LIMIT
maximum download threads that will be started
|
private static java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Boolean> |
useHead |
Constructor and Description |
---|
JCSCachedTileLoaderJob(org.apache.commons.jcs.access.behavior.ICacheAccess<K,V> cache,
TileJobOptions options) |
JCSCachedTileLoaderJob(org.apache.commons.jcs.access.behavior.ICacheAccess<K,V> cache,
TileJobOptions options,
java.util.concurrent.ThreadPoolExecutor downloadJobExecutor) |
Modifier and Type | Method and Description |
---|---|
protected boolean |
cacheAsEmpty()
Simple implementation.
|
void |
cancelOutstandingTasks()
TODO: move to JobFactory
cancels all outstanding tasks in the queue.
|
protected abstract V |
createCacheEntry(byte[] content) |
java.lang.String |
detectErrorMessage(java.lang.String data)
Tries do detect an error message from given string.
|
private void |
ensureCacheElement() |
protected void |
executionFinished()
This method is run when job has finished
|
private void |
finishLoading(ICachedLoaderListener.LoadResult result) |
V |
get()
fetches object from cache, or returns null when object is not found
|
private HttpClient |
getRequest(java.lang.String requestMethod,
boolean noCache) |
protected java.lang.String |
getServerKey() |
private java.net.URL |
getUrlNoException() |
void |
handleJobCancellation()
Marks this job as canceled
|
protected boolean |
isCacheElementValid() |
private boolean |
isCacheValidUsingHead() |
protected boolean |
isObjectLoadable() |
protected boolean |
isResponseLoadable(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerFields,
int responseCode,
byte[] raw)
Check if the object is loadable.
|
private boolean |
loadObject() |
protected CacheEntryAttributes |
parseHeaders(HttpClient.Response urlConn) |
void |
run() |
void |
setFinishedTask(java.lang.Runnable runnable)
Sets a job, that will be run, when job will finish execution
|
void |
submit(ICachedLoaderListener listener,
boolean force)
Submit job for background fetch, and listener will be fed with value object
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getCacheKey, getUrl
protected static final long DEFAULT_EXPIRE_TIME
protected static final long EXPIRE_TIME_SERVER_LIMIT
protected static final long ABSOLUTE_EXPIRE_TIME_LIMIT
public static final IntegerProperty THREAD_LIMIT
private static final java.util.concurrent.ThreadPoolExecutor DEFAULT_DOWNLOAD_JOB_DISPATCHER
private static final java.util.concurrent.ConcurrentMap<java.lang.String,java.util.Set<ICachedLoaderListener>> inProgress
private static final java.util.concurrent.ConcurrentMap<java.lang.String,java.lang.Boolean> useHead
protected final long now
private final org.apache.commons.jcs.access.behavior.ICacheAccess<K,V extends CacheEntry> cache
private org.apache.commons.jcs.engine.behavior.ICacheElement<K,V extends CacheEntry> cacheElement
protected V extends CacheEntry cacheData
protected CacheEntryAttributes attributes
private final int connectTimeout
private final int readTimeout
private final java.util.Map<java.lang.String,java.lang.String> headers
private final java.util.concurrent.ThreadPoolExecutor downloadJobExecutor
private java.lang.Runnable finishTask
private boolean force
private long minimumExpiryTime
public JCSCachedTileLoaderJob(org.apache.commons.jcs.access.behavior.ICacheAccess<K,V> cache, TileJobOptions options, java.util.concurrent.ThreadPoolExecutor downloadJobExecutor)
cache
- cache instance that we will work onoptions
- options of the requestdownloadJobExecutor
- that will be executing the jobspublic JCSCachedTileLoaderJob(org.apache.commons.jcs.access.behavior.ICacheAccess<K,V> cache, TileJobOptions options)
cache
- cache instance that we will work onoptions
- of the requestprivate void ensureCacheElement()
public V get()
ICachedLoaderJob
get
in interface ICachedLoaderJob<K>
public void submit(ICachedLoaderListener listener, boolean force) throws java.io.IOException
ICachedLoaderJob
submit
in interface ICachedLoaderJob<K>
listener
- cache loader listenerforce
- true if the load should skip all the caches (local & remote)java.io.IOException
- on failure from getUrl() callprotected void executionFinished()
protected boolean isObjectLoadable()
protected boolean cacheAsEmpty()
protected java.lang.String getServerKey()
public void run()
run
in interface java.lang.Runnable
private void finishLoading(ICachedLoaderListener.LoadResult result)
protected boolean isCacheElementValid()
private boolean loadObject()
public java.lang.String detectErrorMessage(java.lang.String data)
data
- string to analyzeprotected boolean isResponseLoadable(java.util.Map<java.lang.String,java.util.List<java.lang.String>> headerFields, int responseCode, byte[] raw)
headerFields
- headers sent by serverresponseCode
- http status coderaw
- data read from serverprotected abstract V createCacheEntry(byte[] content)
protected CacheEntryAttributes parseHeaders(HttpClient.Response urlConn)
private HttpClient getRequest(java.lang.String requestMethod, boolean noCache) throws java.io.IOException
java.io.IOException
private boolean isCacheValidUsingHead() throws java.io.IOException
java.io.IOException
public void cancelOutstandingTasks()
public void setFinishedTask(java.lang.Runnable runnable)
runnable
- that will be executedpublic void handleJobCancellation()
private java.net.URL getUrlNoException()