code
stringlengths 23
201k
| docstring
stringlengths 17
96.2k
| func_name
stringlengths 0
235
| language
stringclasses 1
value | repo
stringlengths 8
72
| path
stringlengths 11
317
| url
stringlengths 57
377
| license
stringclasses 7
values |
|---|---|---|---|---|---|---|---|
protected final String fromKey(String cacheKey) {
if (isUsingKeySanitizer()) {
try {
return (String) keySanitizer.desanitizeKey(cacheKey);
} catch (KeySanitationExcepion e) {
Ln.e(e, "Key could not be desanitized, falling back on original key.");
return cacheKey;
}
} else {
return cacheKey;
}
}
|
Get a cache key that may be de-sanitized if a {@link KeySanitizer} is
used.
@param cacheKey
a possibly sanitized cacheKey.
@return a key that will be de-sanitized if a {@link KeySanitizer} is
used.
|
fromKey
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
Apache-2.0
|
protected final String getCachePrefix() {
return factoryCachePrefix + getClass().getSimpleName() + CACHE_PREFIX_END + getHandledClass().getSimpleName() + CACHE_PREFIX_END;
}
|
Get a cache key that may be de-sanitized if a {@link KeySanitizer} is
used.
@param cacheKey
a possibly sanitized cacheKey.
@return a key that will be de-sanitized if a {@link KeySanitizer} is
used.
|
getCachePrefix
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
Apache-2.0
|
protected boolean isCachedAndNotExpired(Object cacheKey, long maxTimeInCacheBeforeExpiry) {
File cacheFile = getCacheFile(cacheKey);
return isCachedAndNotExpired(cacheFile, maxTimeInCacheBeforeExpiry);
}
|
Get a cache key that may be de-sanitized if a {@link KeySanitizer} is
used.
@param cacheKey
a possibly sanitized cacheKey.
@return a key that will be de-sanitized if a {@link KeySanitizer} is
used.
|
isCachedAndNotExpired
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
Apache-2.0
|
protected boolean isCachedAndNotExpired(File cacheFile, long maxTimeInCacheBeforeExpiry) {
if (cacheFile.exists()) {
long timeInCache = System.currentTimeMillis() - cacheFile.lastModified();
if (maxTimeInCacheBeforeExpiry == DurationInMillis.ALWAYS_RETURNED || timeInCache <= maxTimeInCacheBeforeExpiry) {
return true;
}
}
return false;
}
|
Get a cache key that may be de-sanitized if a {@link KeySanitizer} is
used.
@param cacheKey
a possibly sanitized cacheKey.
@return a key that will be de-sanitized if a {@link KeySanitizer} is
used.
|
isCachedAndNotExpired
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersister.java
|
Apache-2.0
|
public void setCacheFolder(File cacheFolder) throws CacheCreationException {
if (cacheFolder == null) {
cacheFolder = new File(getApplication().getCacheDir(), InFileObjectPersister.DEFAULT_ROOT_CACHE_DIR);
}
this.cacheFolder = cacheFolder;
if (!cacheFolder.exists() && !cacheFolder.mkdirs()) {
throw new CacheCreationException("The cache folder " + cacheFolder.getAbsolutePath() + " could not be created.");
}
}
|
Sets the folder used by object persisters of this factory.
@param cacheFolder
the new cache folder of this factory (and persisters it will
create). Ca be null, it will then default to the sub folder
{@link InFileObjectPersister#DEFAULT_ROOT_CACHE_DIR} in side
the application cache folder. Will be created if doesn't exist
yet.
@throws CacheCreationException
|
setCacheFolder
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
public void setCachePrefix(String cachePrefix) {
this.cachePrefix = cachePrefix;
}
|
Sets the cachePrefix used by object persisters of this factory.
@param cachePrefix
the new cache cachePrefix of this factory (and persisters it
will create). Defaults to "className".
|
setCachePrefix
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
public File getCacheFolder() {
return cacheFolder;
}
|
Sets the cachePrefix used by object persisters of this factory.
@param cachePrefix
the new cache cachePrefix of this factory (and persisters it
will create). Defaults to "className".
|
getCacheFolder
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
public String getCachePrefix() {
return cachePrefix;
}
|
Sets the cachePrefix used by object persisters of this factory.
@param cachePrefix
the new cache cachePrefix of this factory (and persisters it
will create). Defaults to "className".
|
getCachePrefix
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
public KeySanitizer getKeySanitizer() {
return keySanitizer;
}
|
Sets the cachePrefix used by object persisters of this factory.
@param cachePrefix
the new cache cachePrefix of this factory (and persisters it
will create). Defaults to "className".
|
getKeySanitizer
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
public void setKeySanitizer(KeySanitizer keySanitizer) {
this.keySanitizer = keySanitizer;
}
|
@param keySanitizer
the new key sanitizer to be used by this
{@link InFileObjectPersisterFactory} and persisters. May be
null, in that case no key sanitation will be used. This is the
default.
|
setKeySanitizer
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
@Override
public final <T> InFileObjectPersister<T> createObjectPersister(Class<T> clazz) {
InFileObjectPersister<T> inFileObjectPersister;
try {
inFileObjectPersister = createInFileObjectPersister(clazz, cacheFolder);
inFileObjectPersister.setFactoryCachePrefix(cachePrefix);
inFileObjectPersister.setKeySanitizer(keySanitizer);
return inFileObjectPersister;
} catch (CacheCreationException e) {
throw new RuntimeException("Could not create cache folder of factory.", e);
}
}
|
@param keySanitizer
the new key sanitizer to be used by this
{@link InFileObjectPersisterFactory} and persisters. May be
null, in that case no key sanitation will be used. This is the
default.
|
createObjectPersister
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
@Override
public void removeAllDataFromCache() {
File cacheFolder = getCacheFolder();
File[] cacheFileList = cacheFolder.listFiles(new FileFilter() {
@Override
public boolean accept(File file) {
return file.getName().startsWith(getCachePrefix());
}
});
boolean allDeleted = true;
if (cacheFileList == null || cacheFileList.length == 0) {
return;
}
for (File cacheFile : cacheFileList) {
allDeleted = cacheFile.delete() && allDeleted;
}
if (allDeleted || cacheFileList.length == 0) {
Ln.d("Some file could not be deleted from cache.");
}
}
|
@param keySanitizer
the new key sanitizer to be used by this
{@link InFileObjectPersisterFactory} and persisters. May be
null, in that case no key sanitation will be used. This is the
default.
|
removeAllDataFromCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
@Override
public boolean accept(File file) {
return file.getName().startsWith(getCachePrefix());
}
|
@param keySanitizer
the new key sanitizer to be used by this
{@link InFileObjectPersisterFactory} and persisters. May be
null, in that case no key sanitation will be used. This is the
default.
|
accept
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/file/InFileObjectPersisterFactory.java
|
Apache-2.0
|
@Override
public Object sanitizeKey(Object cacheKey) throws KeySanitationExcepion {
if (!(cacheKey instanceof String)) {
throw new KeySanitationExcepion(DefaultKeySanitizer.class.getSimpleName() + " can only be used with Strings cache keys.");
}
try {
return Base64.encodeToString(((String) cacheKey).getBytes(UTF8_CHARSET_NAME), BASE64_FLAGS);
} catch (UnsupportedEncodingException e) {
throw new KeySanitationExcepion(e);
}
}
|
Uses base 64 to sanitize/de-sanitize keys. Only applies to cache keys that
are strings. Keys sanitized by this class can be safely used to create file
names (and urls).
@author SNI
|
sanitizeKey
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/keysanitation/DefaultKeySanitizer.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/keysanitation/DefaultKeySanitizer.java
|
Apache-2.0
|
@Override
public Object desanitizeKey(Object sanitzedCacheKey) throws KeySanitationExcepion {
if (!(sanitzedCacheKey instanceof String)) {
throw new KeySanitationExcepion(DefaultKeySanitizer.class.getSimpleName() + " can only be used with Strings cache keys.");
}
try {
return new String(Base64.decode((String) sanitzedCacheKey, BASE64_FLAGS), UTF8_CHARSET_NAME);
} catch (UnsupportedEncodingException e) {
throw new KeySanitationExcepion(e);
}
}
|
Uses base 64 to sanitize/de-sanitize keys. Only applies to cache keys that
are strings. Keys sanitized by this class can be safely used to create file
names (and urls).
@author SNI
|
desanitizeKey
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/keysanitation/DefaultKeySanitizer.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/keysanitation/DefaultKeySanitizer.java
|
Apache-2.0
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
protected int sizeOf(Object key, CacheItem<Bitmap> value) {
Bitmap data = value.getData();
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB_MR1) {
return data.getRowBytes() * data.getHeight();
} else {
return data.getByteCount();
}
}
|
{@link LruCache} for {@link Bitmap}s.
@author David Stemmer
@author Mike Jancola
@author SNI
|
sizeOf
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/BitmapLruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/BitmapLruCache.java
|
Apache-2.0
|
public long getCreationDate() {
return creationDate;
}
|
The CacheItem class represents a cached object, consisting of a piece of data
and a time stamp marking when the data was added to the cache.
@param <T>
the type of object that will be stored in the cache.
|
getCreationDate
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/CacheItem.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/CacheItem.java
|
Apache-2.0
|
public T getData() {
return data;
}
|
The CacheItem class represents a cached object, consisting of a piece of data
and a time stamp marking when the data was added to the cache.
@param <T>
the type of object that will be stored in the cache.
|
getData
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/CacheItem.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/CacheItem.java
|
Apache-2.0
|
public final V get(K key) {
if (key == null) {
throw new NullPointerException("key == null");
}
V mapValue;
synchronized (this) {
mapValue = map.get(key);
if (mapValue != null) {
hitCount++;
return mapValue;
}
missCount++;
}
/*
* Attempt to create a value. This may take a long time, and the map may
* be different when create() returns. If a conflicting value was added
* to the map while create() was working, we leave that value in the map
* and release the created value.
*/
V createdValue = create(key);
if (createdValue == null) {
return null;
}
synchronized (this) {
createCount++;
mapValue = map.put(key, createdValue);
if (mapValue != null) {
// There was a conflict so undo that last put
map.put(key, mapValue);
} else {
size += safeSizeOf(key, createdValue);
}
}
if (mapValue != null) {
entryRemoved(false, key, createdValue, mapValue);
return mapValue;
} else {
trimToSize(maxSize);
return createdValue;
}
}
|
Returns the value for {@code key} if it exists in the cache or can be
created by {@code #create}. If a value was returned, it is moved to the
head of the queue. This returns null if a value is not cached and cannot
be created.
|
get
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final V put(K key, V value) {
if (key == null || value == null) {
throw new NullPointerException("key == null || value == null");
}
V previous;
synchronized (this) {
putCount++;
size += safeSizeOf(key, value);
previous = map.put(key, value);
if (previous != null) {
size -= safeSizeOf(key, previous);
}
}
if (previous != null) {
entryRemoved(false, key, previous, value);
}
trimToSize(maxSize);
return previous;
}
|
Caches {@code value} for {@code key}. The value is moved to the head of
the queue.
@return the previous value mapped by {@code key}.
|
put
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public void trimToSize(int maxSize) {
while (true) {
K key;
V value;
synchronized (this) {
if (size < 0 || map.isEmpty() && size != 0) {
throw new IllegalStateException(getClass().getName() + ".sizeOf() is reporting inconsistent results!");
}
if (size <= maxSize || map.isEmpty()) {
break;
}
Map.Entry<K, V> toEvict = map.entrySet().iterator().next();
key = toEvict.getKey();
value = toEvict.getValue();
map.remove(key);
size -= safeSizeOf(key, value);
evictionCount++;
}
entryRemoved(true, key, value, null);
}
}
|
Remove the eldest entries until the total of remaining entries is at or
below the requested size.
@param maxSize
the maximum size of the cache before returning. May be -1 to
evict even 0-sized elements.
|
trimToSize
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final V remove(K key) {
if (key == null) {
throw new NullPointerException("key == null");
}
V previous;
synchronized (this) {
previous = map.remove(key);
if (previous != null) {
size -= safeSizeOf(key, previous);
}
}
if (previous != null) {
entryRemoved(false, key, previous, null);
}
return previous;
}
|
Removes the entry for {@code key} if it exists.
@return the previous value mapped by {@code key}.
|
remove
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
protected V create(K key) {
return null;
}
|
Called after a cache miss to compute a value for the corresponding key.
Returns the computed value or null if no value can be computed. The
default implementation returns null.
<p>
The method is called without synchronization: other threads may access
the cache while this method is executing.
<p>
If a value for {@code key} exists in the cache when this method returns,
the created value will be released with {@link #entryRemoved} and
discarded. This can occur when multiple threads request the same key at
the same time (causing multiple values to be created), or when one thread
calls {@link #put} while another is creating a value for the same key.
|
create
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
private int safeSizeOf(K key, V value) {
int result = sizeOf(key, value);
if (result < 0) {
throw new IllegalStateException("Negative size: " + key + "=" + value);
}
return result;
}
|
Called after a cache miss to compute a value for the corresponding key.
Returns the computed value or null if no value can be computed. The
default implementation returns null.
<p>
The method is called without synchronization: other threads may access
the cache while this method is executing.
<p>
If a value for {@code key} exists in the cache when this method returns,
the created value will be released with {@link #entryRemoved} and
discarded. This can occur when multiple threads request the same key at
the same time (causing multiple values to be created), or when one thread
calls {@link #put} while another is creating a value for the same key.
|
safeSizeOf
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
protected int sizeOf(K key, V value) {
return 1;
}
|
Returns the size of the entry for {@code key} and {@code value} in
user-defined units. The default implementation returns 1 so that size is
the number of entries and max size is the maximum number of entries.
<p>
An entry's size must not change while it is in the cache.
|
sizeOf
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final void evictAll() {
trimToSize(-1); // -1 will evict 0-sized elements
}
|
Clear the cache, calling {@link #entryRemoved} on each removed entry.
|
evictAll
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized int size() {
return size;
}
|
For caches that do not override {@link #sizeOf}, this returns the number
of entries in the cache. For all other caches, this returns the sum of
the sizes of the entries in this cache.
|
size
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized int maxSize() {
return maxSize;
}
|
For caches that do not override {@link #sizeOf}, this returns the maximum
number of entries in the cache. For all other caches, this returns the
maximum sum of the sizes of the entries in this cache.
|
maxSize
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized int hitCount() {
return hitCount;
}
|
Returns the number of times {@link #get} returned a value.
|
hitCount
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized int missCount() {
return missCount;
}
|
Returns the number of times {@link #get} returned null or required a new
value to be created.
|
missCount
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized int createCount() {
return createCount;
}
|
Returns the number of times {@link #create(Object)} returned a value.
|
createCount
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized int putCount() {
return putCount;
}
|
Returns the number of times {@link #put} was called.
|
putCount
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized int evictionCount() {
return evictionCount;
}
|
Returns the number of values that have been evicted.
|
evictionCount
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public final synchronized Map<K, V> snapshot() {
return new LinkedHashMap<K, V>(map);
}
|
Returns a copy of the current contents of the cache, ordered from least
recently accessed to most recently accessed.
|
snapshot
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
@Override
public final synchronized String toString() {
int accesses = hitCount + missCount;
int hitPercent = accesses != 0 ? MAX_PERCENT * hitCount / accesses : 0;
return String.format("LruCache[maxSize=%d,hits=%d,misses=%d,hitRate=%d%%]", maxSize, hitCount, missCount, hitPercent);
}
|
Returns a copy of the current contents of the cache, ordered from least
recently accessed to most recently accessed.
|
toString
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCache.java
|
Apache-2.0
|
public ObjectPersister<T> getDecoratedPersister() {
return decoratedPersister;
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
getDecoratedPersister
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
public LruCache<Object, CacheItem<T>> getLruCache() {
return lruCache;
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
getLruCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public T loadDataFromCache(Object cacheKey, long maxTimeInCacheBeforeExpiry) throws CacheLoadingException {
CacheItem<T> cacheItem = lruCache.get(cacheKey);
if (cacheItem == null) {
Ln.d("Miss from lru cache for %s", cacheKey);
if (decoratedPersister != null) {
T data = decoratedPersister.loadDataFromCache(cacheKey, maxTimeInCacheBeforeExpiry);
if (data == null) {
return null;
}
CacheItem<T> item = new CacheItem<T>(decoratedPersister.getCreationDateInCache(cacheKey), data);
Ln.d("Put in lru cache after miss");
lruCache.put(cacheKey, item);
return data;
}
return null;
} else {
Ln.d("Hit from lru cache for %s", cacheKey);
boolean dataCanExpire = maxTimeInCacheBeforeExpiry != DurationInMillis.ALWAYS_RETURNED;
boolean dataIsNotExpired = System.currentTimeMillis() - cacheItem.getCreationDate() <= maxTimeInCacheBeforeExpiry;
if (!dataCanExpire || dataIsNotExpired) {
return cacheItem.getData();
}
return null;
}
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
loadDataFromCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public T saveDataToCacheAndReturnData(T data, Object cacheKey) throws CacheSavingException {
CacheItem<T> itemToCache = new CacheItem<T>(data);
lruCache.put(cacheKey, itemToCache);
Ln.d("Put in lru cache for %s", cacheKey);
if (decoratedPersister != null) {
decoratedPersister.saveDataToCacheAndReturnData(data, cacheKey);
}
return data;
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
saveDataToCacheAndReturnData
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public boolean isDataInCache(Object cacheKey, long maxTimeInCacheBeforeExpiry) {
CacheItem<T> cacheItem = lruCache.get(cacheKey);
if (cacheItem == null) {
if (decoratedPersister != null) {
return decoratedPersister.isDataInCache(cacheKey, maxTimeInCacheBeforeExpiry);
}
return false;
} else {
boolean dataCanExpire = maxTimeInCacheBeforeExpiry != DurationInMillis.ALWAYS_RETURNED;
boolean dataIsNotExpired = System.currentTimeMillis() - cacheItem.getCreationDate() <= maxTimeInCacheBeforeExpiry;
return !dataCanExpire || dataIsNotExpired;
}
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
isDataInCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public long getCreationDateInCache(Object cacheKey) throws CacheLoadingException {
CacheItem<T> cacheItem = lruCache.get(cacheKey);
if (cacheItem != null) {
return cacheItem.getCreationDate();
} else {
if (decoratedPersister != null) {
return decoratedPersister.getCreationDateInCache(cacheKey);
}
}
throw new CacheLoadingException("Data could not be found in cache for cacheKey=" + cacheKey);
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
getCreationDateInCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public List<T> loadAllDataFromCache() throws CacheLoadingException {
if (decoratedPersister != null) {
return decoratedPersister.loadAllDataFromCache();
} else {
Map<Object, CacheItem<T>> cacheMap = lruCache.snapshot();
List<T> allData = new ArrayList<T>();
for (CacheItem<T> item : cacheMap.values()) {
allData.add(item.getData());
}
return allData;
}
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
loadAllDataFromCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public List<Object> getAllCacheKeys() {
if (decoratedPersister != null) {
return decoratedPersister.getAllCacheKeys();
} else {
return new ArrayList<Object>(lruCache.snapshot().keySet());
}
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
getAllCacheKeys
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public boolean removeDataFromCache(Object cacheKey) {
boolean result = false;
if (decoratedPersister != null) {
result = decoratedPersister.removeDataFromCache(cacheKey);
}
return result || lruCache.remove(cacheKey) != null;
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
removeDataFromCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@Override
public void removeAllDataFromCache() {
lruCache.evictAll();
if (decoratedPersister != null) {
decoratedPersister.removeAllDataFromCache();
}
}
|
Abstract in-memory object persister, based on the Android LRUCache.
@author David Stemmer
@author Mike Jancola
|
removeAllDataFromCache
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/LruCacheObjectPersister.java
|
Apache-2.0
|
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR1)
@Override
protected int sizeOf(Object key, CacheItem<String> value) {
String data = value.getData();
return data.length();
}
|
{@link LruCache} for {@link String}.
@author David Stemmer
@author Mike Jancola
@author SNI
|
sizeOf
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/StringLruCache.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/com/octo/android/robospice/persistence/memory/StringLruCache.java
|
Apache-2.0
|
public static int v(Throwable t) {
return CONFIG.minimumLogLevel <= Log.VERBOSE ? print.println(Log.VERBOSE, Log.getStackTraceString(t)) : 0;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
v
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int v(Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.VERBOSE) {
return 0;
}
final String s = Strings.toString(s1);
final String message = args.length > 0 ? String.format(s, args) : s;
return print.println(Log.VERBOSE, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
v
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int v(Throwable throwable, Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.VERBOSE) {
return 0;
}
final String s = Strings.toString(s1);
final String message = (args.length > 0 ? String.format(s, args) : s) + '\n' + Log.getStackTraceString(throwable);
return print.println(Log.VERBOSE, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
v
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int d(Throwable t) {
return CONFIG.minimumLogLevel <= Log.DEBUG ? print.println(Log.DEBUG, Log.getStackTraceString(t)) : 0;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
d
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int d(Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.DEBUG) {
return 0;
}
final String s = Strings.toString(s1);
final String message = args.length > 0 ? String.format(s, args) : s;
return print.println(Log.DEBUG, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
d
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int d(Throwable throwable, Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.DEBUG) {
return 0;
}
final String s = Strings.toString(s1);
final String message = (args.length > 0 ? String.format(s, args) : s) + '\n' + Log.getStackTraceString(throwable);
return print.println(Log.DEBUG, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
d
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int i(Throwable t) {
return CONFIG.minimumLogLevel <= Log.INFO ? print.println(Log.INFO, Log.getStackTraceString(t)) : 0;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
i
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int i(Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.INFO) {
return 0;
}
final String s = Strings.toString(s1);
final String message = args.length > 0 ? String.format(s, args) : s;
return print.println(Log.INFO, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
i
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int i(Throwable throwable, Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.INFO) {
return 0;
}
final String s = Strings.toString(s1);
final String message = (args.length > 0 ? String.format(s, args) : s) + '\n' + Log.getStackTraceString(throwable);
return print.println(Log.INFO, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
i
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int w(Throwable t) {
return CONFIG.minimumLogLevel <= Log.WARN ? print.println(Log.WARN, Log.getStackTraceString(t)) : 0;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
w
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int w(Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.WARN) {
return 0;
}
final String s = Strings.toString(s1);
final String message = args.length > 0 ? String.format(s, args) : s;
return print.println(Log.WARN, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
w
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int w(Throwable throwable, Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.WARN) {
return 0;
}
final String s = Strings.toString(s1);
final String message = (args.length > 0 ? String.format(s, args) : s) + '\n' + Log.getStackTraceString(throwable);
return print.println(Log.WARN, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
w
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int e(Throwable t) {
return CONFIG.minimumLogLevel <= Log.ERROR ? print.println(Log.ERROR, Log.getStackTraceString(t)) : 0;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
e
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int e(Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.ERROR) {
return 0;
}
final String s = Strings.toString(s1);
final String message = args.length > 0 ? String.format(s, args) : s;
return print.println(Log.ERROR, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
e
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static int e(Throwable throwable, Object s1, Object... args) {
if (CONFIG.minimumLogLevel > Log.ERROR) {
return 0;
}
final String s = Strings.toString(s1);
final String message = (args.length > 0 ? String.format(s, args) : s) + '\n' + Log.getStackTraceString(throwable);
return print.println(Log.ERROR, message);
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
e
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static boolean isDebugEnabled() {
return CONFIG.minimumLogLevel <= Log.DEBUG;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
isDebugEnabled
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static boolean isVerboseEnabled() {
return CONFIG.minimumLogLevel <= Log.VERBOSE;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
isVerboseEnabled
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static Config getConfig() {
return CONFIG;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
getConfig
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
@Override
public int getLoggingLevel() {
return minimumLogLevel;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
getLoggingLevel
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
@Override
public void setLoggingLevel(int level) {
minimumLogLevel = level;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
setLoggingLevel
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static String logLevelToString(int loglevel) {
switch (loglevel) {
case Log.VERBOSE:
return "VERBOSE";
case Log.DEBUG:
return "DEBUG";
case Log.INFO:
return "INFO";
case Log.WARN:
return "WARN";
case Log.ERROR:
return "ERROR";
case Log.ASSERT:
return "ASSERT";
default:
return "UNKNOWN";
}
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
logLevelToString
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public static void setPrint(Print print) {
Ln.print = print;
}
|
print is initially set to Print(), then replaced by guice during static
injection pass. This allows overriding where the log message is delivered
to.
|
setPrint
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
public int println(int priority, String msg) {
return Log.println(priority, getScope(), processMessage(msg));
}
|
Default implementation logs to android.util.Log
|
println
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
protected String processMessage(String msg) {
if (CONFIG.minimumLogLevel <= Log.DEBUG) {
msg = String.format("%s %s %s", new SimpleDateFormat("HH:mm:ss.SSS").format(System.currentTimeMillis()), Thread.currentThread().getName(), msg);
}
return msg;
}
|
Default implementation logs to android.util.Log
|
processMessage
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
protected static String getScope() {
if (CONFIG.minimumLogLevel <= Log.DEBUG) {
final StackTraceElement trace = Thread.currentThread().getStackTrace()[DEFAULT_STACK_TRACE_LINE_COUNT];
return CONFIG.scope + "/" + trace.getFileName() + ":" + trace.getLineNumber();
}
return CONFIG.scope;
}
|
Default implementation logs to android.util.Log
|
getScope
|
java
|
stephanenicolas/robospice
|
robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-cache-parent/robospice-cache/src/main/java/roboguice/util/temp/Ln.java
|
Apache-2.0
|
@Override
protected void onStart() {
spiceManager.start(this);
super.onStart();
}
|
This class is more a sample than a real ready-to-use class. It shows how you
can build your base Activity class in your own project. Whatever super class
you use (sherlock, fragmentactivity, guice, etc.) you can just copy past the
methods below to enable all your activities to use the framework. The binding
can take place, at best during <a href=
"http://stackoverflow.com/questions/2304086/binding-to-service-in-oncreate-or-in-onresume"
>certain lifecycle operations </a>: {@link #onStart()} and {@link #onStop()}.
@author sni
|
onStart
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceActivity.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceActivity.java
|
Apache-2.0
|
@Override
protected void onStop() {
spiceManager.shouldStop();
super.onStop();
}
|
This class is more a sample than a real ready-to-use class. It shows how you
can build your base Activity class in your own project. Whatever super class
you use (sherlock, fragmentactivity, guice, etc.) you can just copy past the
methods below to enable all your activities to use the framework. The binding
can take place, at best during <a href=
"http://stackoverflow.com/questions/2304086/binding-to-service-in-oncreate-or-in-onresume"
>certain lifecycle operations </a>: {@link #onStart()} and {@link #onStop()}.
@author sni
|
onStop
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceActivity.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceActivity.java
|
Apache-2.0
|
public SpiceManager getSpiceManager() {
return spiceManager;
}
|
This class is more a sample than a real ready-to-use class. It shows how you
can build your base Activity class in your own project. Whatever super class
you use (sherlock, fragmentactivity, guice, etc.) you can just copy past the
methods below to enable all your activities to use the framework. The binding
can take place, at best during <a href=
"http://stackoverflow.com/questions/2304086/binding-to-service-in-oncreate-or-in-onresume"
>certain lifecycle operations </a>: {@link #onStart()} and {@link #onStop()}.
@author sni
|
getSpiceManager
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceActivity.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceActivity.java
|
Apache-2.0
|
protected int getThreadCount() {
return DEFAULT_THREAD_COUNT;
}
|
Number of threads used internally by this spice manager to communicate
commands to the SpiceService it is bound to
@return the thread count. Defaults to {@link #DEFAULT_THREAD_COUNT}.
|
getThreadCount
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public synchronized void start(final Context context) {
this.contextWeakReference = new WeakReference<Context>(context);
if (isStarted()) {
throw new IllegalStateException("Already started.");
} else {
executorService = Executors.newFixedThreadPool(getThreadCount(), new MinPriorityThreadFactory());
// start the binding to the service
runner = new Thread(this, SPICE_MANAGER_THREAD_NAME_PREFIX + spiceManagerThreadIndex++);
runner.setPriority(Thread.MIN_PRIORITY);
isStopped = false;
runner.start();
Ln.d("SpiceManager started.");
}
}
|
Start the {@link SpiceManager}. It will bind asynchronously to the
{@link SpiceService}.
@param context
a context that will be used to bind to the service. Typically,
the Activity or Fragment that needs to interact with the
{@link SpiceService}.
|
start
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public synchronized boolean isStarted() {
return !isStopped;
}
|
Method is synchronized with {@link #start(Context)}.
@return whether or not the {@link SpiceManager} is started.
|
isStarted
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public int getRequestToLaunchCount() {
return mapRequestToLaunchToRequestListener.size();
}
|
@return the number of current requests that should be launched ASAP (when
the spice service is bound).
|
getRequestToLaunchCount
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public int getPendingRequestCount() {
return mapPendingRequestToRequestListener.size();
}
|
@return the number of current request that are currently pending and
being processed by the spice service.
|
getPendingRequestCount
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
private Context getContextReference() {
return contextWeakReference.get();
}
|
@return the number of current request that are currently pending and
being processed by the spice service.
|
getContextReference
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
@Override
public void run() {
if (!tryToStartService()) {
Ln.d("Service was not started as Activity died prematurely");
isStopped = true;
return;
}
bindToService();
try {
waitForServiceToBeBound();
if (spiceService == null) {
Ln.d("No spice service bound.");
return;
}
while (!requestQueue.isEmpty() || !isStopped && !Thread.interrupted()) {
try {
sendRequestToService(requestQueue.take());
} catch (final InterruptedException ex) {
Ln.d("Interrupted while waiting for new request.");
// we receive an interrupted exception while waiting
// see java spec : http://stackoverflow.com/a/6699006/693752
break;
}
}
Ln.d("SpiceManager request runner terminated. Requests count: %d, stopped %b, interrupted %b", requestQueue.size(), isStopped, Thread.interrupted());
} catch (final InterruptedException e) {
Ln.d(e, "Interrupted while waiting for acquiring service.");
}
}
|
@return the number of current request that are currently pending and
being processed by the spice service.
|
run
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
private void sendRequestToService(final CachedSpiceRequest<?> spiceRequest) {
lockSendRequestsToService.lock();
try {
if (spiceRequest != null && spiceService != null) {
if (isStopped) {
Ln.d("Sending request to service without listeners : " + spiceRequest.getClass().getSimpleName());
spiceService.addRequest(spiceRequest, null);
} else {
final Set<RequestListener<?>> listRequestListener = mapRequestToLaunchToRequestListener.get(spiceRequest);
Ln.d("Sending request to service : " + spiceRequest.getClass().getSimpleName());
spiceService.addRequest(spiceRequest, listRequestListener);
}
} else {
Ln.d("Service or request was null");
}
} finally {
lockSendRequestsToService.unlock();
}
}
|
@return the number of current request that are currently pending and
being processed by the spice service.
|
sendRequestToService
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public synchronized void shouldStop() {
try {
shouldStopAndJoin(DELAY_WAIT_FOR_RUNNER_TO_STOP);
} catch (InterruptedException e) {
Ln.e(e, "Exception when joining the runner that was stopping.");
}
}
|
Stops the {@link SpiceManager}. It will unbind from {@link SpiceService}.
All request listeners that had been registered to listen to
{@link SpiceRequest}s sent from this {@link SpiceManager} will be
unregistered. None of them will be notified with the results of their
{@link SpiceRequest}s. Unbinding will occur asynchronously.
|
shouldStop
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public synchronized void shouldStopAndJoin(final long timeOut) throws InterruptedException {
if (!isStarted()) {
throw new IllegalStateException("Not started yet");
}
Ln.d("SpiceManager stopping. Joining");
this.isStopped = true;
dontNotifyAnyRequestListenersInternal();
if (requestQueue.isEmpty()) {
this.runner.interrupt();
}
long start = System.currentTimeMillis();
try {
this.runner.join(timeOut);
} catch (InterruptedException e) {
throw e;
} finally {
long end = System.currentTimeMillis();
Ln.d("Runner join time (ms) when should stop %d", end - start);
}
unbindFromService();
this.runner = null;
this.executorService.shutdown();
this.contextWeakReference.clear();
Ln.d("SpiceManager stopped.");
}
|
This is mostly a testing method. Stops the {@link SpiceManager}. It will
unbind from {@link SpiceService}. All request listeners that had been
registered to listen to {@link SpiceRequest}s sent from this
{@link SpiceManager} will be unregistered. None of them will be notified
with the results of their {@link SpiceRequest}s. Unbinding will occur
syncrhonously : the method returns when all events have been unregistered
and when main processing thread stops.
|
shouldStopAndJoin
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void getFromCache(final Class<T> clazz, final Object requestCacheKey, final long cacheExpiryDuration, final RequestListener<T> requestListener) {
final SpiceRequest<T> request = new SpiceRequest<T>(clazz) {
@Override
public T loadDataFromNetwork() throws Exception {
return null;
}
@Override
public boolean isAggregatable() {
return false;
}
};
final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, requestCacheKey, cacheExpiryDuration);
cachedSpiceRequest.setOffline(true);
execute(cachedSpiceRequest, requestListener);
}
|
Get some data previously saved in cache with key <i>requestCacheKey</i>
with maximum time in cache : <i>cacheDuration</i> millisecond and
register listeners to notify when request is finished. This method
executes a SpiceRequest with no network processing. It just checks
whatever is in the cache and return it, including null if there is no
such data found in cache.
@param clazz
the class of the result to retrieve from cache.
@param requestCacheKey
the key used to store and retrieve the result of the request
in the cache
@param cacheExpiryDuration
duration in milliseconds after which the content of the cache
will be considered to be expired.
{@link DurationInMillis#ALWAYS_RETURNED} means data in cache
is always returned if it exists.
{@link DurationInMillis#ALWAYS_EXPIRED} means data in cache is
never returned.(see {@link DurationInMillis})
@param requestListener
the listener to notify when the request will finish. If
nothing is found in cache, listeners will receive a null
result on their
{@link RequestListener#onRequestSuccess(Object)} method. If
something is found in cache, they will receive it in this
method. If an error occurs, they will be notified via their
{@link RequestListener#onRequestFailure(com.octo.android.robospice.persistence.exception.SpiceException)}
method.
|
getFromCache
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
@Override
public T loadDataFromNetwork() throws Exception {
return null;
}
|
Get some data previously saved in cache with key <i>requestCacheKey</i>
with maximum time in cache : <i>cacheDuration</i> millisecond and
register listeners to notify when request is finished. This method
executes a SpiceRequest with no network processing. It just checks
whatever is in the cache and return it, including null if there is no
such data found in cache.
@param clazz
the class of the result to retrieve from cache.
@param requestCacheKey
the key used to store and retrieve the result of the request
in the cache
@param cacheExpiryDuration
duration in milliseconds after which the content of the cache
will be considered to be expired.
{@link DurationInMillis#ALWAYS_RETURNED} means data in cache
is always returned if it exists.
{@link DurationInMillis#ALWAYS_EXPIRED} means data in cache is
never returned.(see {@link DurationInMillis})
@param requestListener
the listener to notify when the request will finish. If
nothing is found in cache, listeners will receive a null
result on their
{@link RequestListener#onRequestSuccess(Object)} method. If
something is found in cache, they will receive it in this
method. If an error occurs, they will be notified via their
{@link RequestListener#onRequestFailure(com.octo.android.robospice.persistence.exception.SpiceException)}
method.
|
loadDataFromNetwork
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
@Override
public boolean isAggregatable() {
return false;
}
|
Get some data previously saved in cache with key <i>requestCacheKey</i>
with maximum time in cache : <i>cacheDuration</i> millisecond and
register listeners to notify when request is finished. This method
executes a SpiceRequest with no network processing. It just checks
whatever is in the cache and return it, including null if there is no
such data found in cache.
@param clazz
the class of the result to retrieve from cache.
@param requestCacheKey
the key used to store and retrieve the result of the request
in the cache
@param cacheExpiryDuration
duration in milliseconds after which the content of the cache
will be considered to be expired.
{@link DurationInMillis#ALWAYS_RETURNED} means data in cache
is always returned if it exists.
{@link DurationInMillis#ALWAYS_EXPIRED} means data in cache is
never returned.(see {@link DurationInMillis})
@param requestListener
the listener to notify when the request will finish. If
nothing is found in cache, listeners will receive a null
result on their
{@link RequestListener#onRequestSuccess(Object)} method. If
something is found in cache, they will receive it in this
method. If an error occurs, they will be notified via their
{@link RequestListener#onRequestFailure(com.octo.android.robospice.persistence.exception.SpiceException)}
method.
|
isAggregatable
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void addListenerIfPending(final Class<T> clazz, final Object requestCacheKey, final PendingRequestListener<T> requestListener) {
addListenerIfPending(clazz, requestCacheKey, (RequestListener<T>) requestListener);
}
|
Add listener to a pending request if it exists. If no such request
exists, this method calls onRequestNotFound on the listener. If a request
identified by clazz and requestCacheKey, it will receive an additional
listener.
@param clazz
the class of the result of the pending request to look for.
@param requestCacheKey
the key used to store and retrieve the result of the request
in the cache
@param requestListener
the listener to notify when the request will finish.
|
addListenerIfPending
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void execute(final SpiceRequest<T> request, final RequestListener<T> requestListener) {
final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, null, DurationInMillis.ALWAYS_RETURNED);
execute(cachedSpiceRequest, requestListener);
}
|
Execute a request, without using cache. No result from cache will be
returned. The method {@link SpiceRequest#loadDataFromNetwork()} will
always be invoked. The result will not be stored in cache.
@param request
the request to execute.
@param requestListener
the listener to notify when the request will finish.
|
execute
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void execute(final SpiceRequest<T> request, final Object requestCacheKey, final long cacheExpiryDuration, final RequestListener<T> requestListener) {
final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, requestCacheKey, cacheExpiryDuration);
execute(cachedSpiceRequest, requestListener);
}
|
Execute a request. Before invoking the method
{@link SpiceRequest#loadDataFromNetwork()}, the cache will be checked :
if a result has been cached with the cache key <i>requestCacheKey</i>,
RoboSpice will consider the parameter <i>cacheExpiryDuration</i> to
determine whether the result in the cache is expired or not. If it is not
expired, then listeners will receive the data in cache. Otherwise, the
method {@link SpiceRequest#loadDataFromNetwork()} will be invoked and the
result will be stored in cache using the cache key
<i>requestCacheKey</i>.
@param request
the request to execute
@param requestCacheKey
the key used to store and retrieve the result of the request
in the cache
@param cacheExpiryDuration
duration in milliseconds after which the content of the cache
will be considered to be expired.
{@link DurationInMillis#ALWAYS_RETURNED} means data in cache
is always returned if it exists.
{@link DurationInMillis#ALWAYS_EXPIRED} means data in cache is
never returned.(see {@link DurationInMillis})
@param requestListener
the listener to notify when the request will finish
|
execute
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void execute(final CachedSpiceRequest<T> cachedSpiceRequest, final RequestListener<T> requestListener) {
addRequestListenerToListOfRequestListeners(cachedSpiceRequest, requestListener);
Ln.d("adding request to request queue");
this.requestQueue.add(cachedSpiceRequest);
}
|
Execute a request, put the result in cache and register listeners to
notify when request is finished.
@param cachedSpiceRequest
the request to execute. {@link CachedSpiceRequest} is a
wrapper of {@link SpiceRequest} that contains cache key and
cache duration
@param requestListener
the listener to notify when the request will finish
|
execute
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void getFromCacheAndLoadFromNetworkIfExpired(final SpiceRequest<T> request, final Object requestCacheKey, final long cacheExpiryDuration, final RequestListener<T> requestListener) {
final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, requestCacheKey, cacheExpiryDuration);
cachedSpiceRequest.setAcceptingDirtyCache(true);
execute(cachedSpiceRequest, requestListener);
}
|
Gets data from cache, expired or not, and executes a request normaly.
Before invoking the method {@link SpiceRequest#loadDataFromNetwork()},
the cache will be checked : if a result has been cached with the cache
key <i>requestCacheKey</i>, RoboSpice will consider the parameter
<i>cacheExpiryDuration</i> to determine whether the result in the cache
is expired or not. If it is not expired, then listeners will receive the
data in cache only. If the result is absent or expired, then
{@link SpiceRequest#loadDataFromNetwork()} will be invoked and the result
will be stored in cache using the cache key <i>requestCacheKey</i>.
@param request
the request to execute
@param requestCacheKey
the key used to store and retrieve the result of the request
in the cache
@param cacheExpiryDuration
duration in milliseconds after which the content of the cache
will be considered to be expired.
{@link DurationInMillis#ALWAYS_RETURNED} means data in cache
is always returned if it exists.
{@link DurationInMillis#ALWAYS_EXPIRED} doesn't make much
sense here.
@param requestListener
the listener to notify when the request will finish
|
getFromCacheAndLoadFromNetworkIfExpired
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <U, T extends U> void putInCache(final Class<U> clazz, final Object requestCacheKey, final T data, RequestListener<U> listener) {
@SuppressWarnings({ "unchecked", "rawtypes" })
final SpiceRequest<U> spiceRequest = new SpiceRequest(clazz) {
@Override
public U loadDataFromNetwork() throws Exception {
return data;
}
};
CachedSpiceRequest<U> cachedSpiceRequest = new CachedSpiceRequest<U>(spiceRequest, requestCacheKey, DurationInMillis.ALWAYS_EXPIRED);
cachedSpiceRequest.setOffline(true);
execute(cachedSpiceRequest, listener);
}
|
Adds some data to the cache, asynchronously.
@param clazz
a super class or the class of data.
@param requestCacheKey
the request cache key that data will be stored in.
@param data
the data to store. Maybe null if supported by underlying
ObjectPersister.
@param listener
a listener that will be notified of this request's success or
failure. May be null.
|
putInCache
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
@Override
public U loadDataFromNetwork() throws Exception {
return data;
}
|
Adds some data to the cache, asynchronously.
@param clazz
a super class or the class of data.
@param requestCacheKey
the request cache key that data will be stored in.
@param data
the data to store. Maybe null if supported by underlying
ObjectPersister.
@param listener
a listener that will be notified of this request's success or
failure. May be null.
|
loadDataFromNetwork
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void putInCache(final Class<? super T> clazz, final Object requestCacheKey, final T data) {
putInCache(clazz, requestCacheKey, data, null);
}
|
Adds some data to the cache, asynchronously. Same as
{@link #putInCache(Class, Object, Object, RequestListener)} with a null
listener. Operation will take place but you won't be notified.
@param clazz
a super class or the class of data.
@param requestCacheKey
the request cache key that data will be stored in.
@param data
the data to store. Maybe null if supported by underlying
ObjectPersister.
|
putInCache
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
@SuppressWarnings("unchecked")
public <T> void putInCache(final Object requestCacheKey, final T data, RequestListener<T> listener) {
putInCache((Class<T>) data.getClass(), requestCacheKey, data, listener);
}
|
Adds some data to the cache, asynchronously. Same as
{@link #putInCache(Class, Object, Object, RequestListener)} where the
class used to identify the request is data.getClass().
@param requestCacheKey
the request cache key that data will be stored in.
@param data
the data to store. Maybe null if supported by underlying
ObjectPersister.
@param listener
a listener that will be notified of this request's success or
failure. May be null.
|
putInCache
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
@SuppressWarnings("unchecked")
public <T> void putInCache(final Object requestCacheKey, final T data) {
putInCache((Class<T>) data.getClass(), requestCacheKey, data);
}
|
Adds some data to the cache, asynchronously. Same as
{@link #putInCache(Class, Object, Object, RequestListener)} where the
class used to identify the request is data.getClass() and with a null
listener. Operation will take place but you won't be notified.
@param requestCacheKey
the request cache key that data will be stored in.
@param data
the data to store. Maybe null if supported by underlying
ObjectPersister.
|
putInCache
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public <T> void cancel(final Class<T> clazz, final Object requestCacheKey) {
final SpiceRequest<T> request = new SpiceRequest<T>(clazz) {
@Override
public T loadDataFromNetwork() throws Exception {
return null;
}
};
final CachedSpiceRequest<T> cachedSpiceRequest = new CachedSpiceRequest<T>(request, requestCacheKey, DurationInMillis.ALWAYS_EXPIRED);
cachedSpiceRequest.setProcessable(false);
cachedSpiceRequest.setOffline(true);
cachedSpiceRequest.cancel();
execute(cachedSpiceRequest, null);
}
|
Cancel a pending request if it exists. If no such request exists, this
method does nothing. If a request identified by clazz and requestCacheKey
exists, it will be cancelled and its associated listeners will get
notified. This method is asynchronous.
@param clazz
the class of the result of the pending request to look for.
@param requestCacheKey
the cache key associated to the request's results.
|
cancel
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
@Override
public T loadDataFromNetwork() throws Exception {
return null;
}
|
Cancel a pending request if it exists. If no such request exists, this
method does nothing. If a request identified by clazz and requestCacheKey
exists, it will be cancelled and its associated listeners will get
notified. This method is asynchronous.
@param clazz
the class of the result of the pending request to look for.
@param requestCacheKey
the cache key associated to the request's results.
|
loadDataFromNetwork
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
public void dontNotifyRequestListenersForRequest(final SpiceRequest<?> request) {
executorService.execute(new Runnable() {
@Override
public void run() {
dontNotifyRequestListenersForRequestInternal(request);
}
});
}
|
Disable request listeners notifications for a specific request.<br/>
None of the listeners associated to this request will be called when
request will finish.<br/>
This method will ask (asynchronously) to the {@link SpiceService} to
remove listeners if requests have already been sent to the
{@link SpiceService} if the request has already been sent to the service.
Otherwise, it will just remove listeners before passing the request to
the {@link SpiceService}. Calling this method doesn't prevent request
from being executed (and put in cache) but will remove request's
listeners notification.
@param request
Request for which listeners are to unregistered.
|
dontNotifyRequestListenersForRequest
|
java
|
stephanenicolas/robospice
|
robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
https://github.com/stephanenicolas/robospice/blob/master/robospice-core-parent/robospice/src/main/java/com/octo/android/robospice/SpiceManager.java
|
Apache-2.0
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.