|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object android.content.Context android.content.ContextWrapper android.app.Service com.octo.android.robospice.SpiceService
public abstract class SpiceService
This is an abstract class used to manage the cache and provide web service
result to an activity.
Extends this class to provide a service able to load content from web service
or cache (if available and enabled). You will have to implement
createCacheManager(Application)
to configure the
CacheManager
used by all requests to persist their results in the
cache (and load them from cache if possible).
Nested Class Summary | |
---|---|
protected class |
SpiceService.SelfStopperRequestProcessorListener
|
static class |
SpiceService.SpiceServiceBinder
|
Field Summary | |
---|---|
protected static int |
DEFAULT_NOTIFICATION_ID
|
protected static int |
DEFAULT_THREAD_COUNT
|
protected static int |
DEFAULT_THREAD_KEEP_ALIVE_TIME
Default in TimeUnit.NANOSECONDS implies core threads are not disposed when idle. |
protected static int |
DEFAULT_THREAD_PRIORITY
|
Fields inherited from class android.app.Service |
---|
START_CONTINUATION_MASK, START_FLAG_REDELIVERY, START_FLAG_RETRY, START_NOT_STICKY, START_REDELIVER_INTENT, START_STICKY, START_STICKY_COMPATIBILITY |
Fields inherited from class android.content.Context |
---|
ACCESSIBILITY_SERVICE, ACCOUNT_SERVICE, ACTIVITY_SERVICE, ALARM_SERVICE, AUDIO_SERVICE, BIND_ABOVE_CLIENT, BIND_ADJUST_WITH_ACTIVITY, BIND_ALLOW_OOM_MANAGEMENT, BIND_AUTO_CREATE, BIND_DEBUG_UNBIND, BIND_IMPORTANT, BIND_NOT_FOREGROUND, BIND_WAIVE_PRIORITY, CLIPBOARD_SERVICE, CONNECTIVITY_SERVICE, CONTEXT_IGNORE_SECURITY, CONTEXT_INCLUDE_CODE, CONTEXT_RESTRICTED, DEVICE_POLICY_SERVICE, DOWNLOAD_SERVICE, DROPBOX_SERVICE, INPUT_METHOD_SERVICE, INPUT_SERVICE, KEYGUARD_SERVICE, LAYOUT_INFLATER_SERVICE, LOCATION_SERVICE, MEDIA_ROUTER_SERVICE, MODE_APPEND, MODE_ENABLE_WRITE_AHEAD_LOGGING, MODE_MULTI_PROCESS, MODE_PRIVATE, MODE_WORLD_READABLE, MODE_WORLD_WRITEABLE, NFC_SERVICE, NOTIFICATION_SERVICE, NSD_SERVICE, POWER_SERVICE, SEARCH_SERVICE, SENSOR_SERVICE, STORAGE_SERVICE, TELEPHONY_SERVICE, TEXT_SERVICES_MANAGER_SERVICE, UI_MODE_SERVICE, USB_SERVICE, VIBRATOR_SERVICE, WALLPAPER_SERVICE, WIFI_P2P_SERVICE, WIFI_SERVICE, WINDOW_SERVICE |
Fields inherited from interface android.content.ComponentCallbacks2 |
---|
TRIM_MEMORY_BACKGROUND, TRIM_MEMORY_COMPLETE, TRIM_MEMORY_MODERATE, TRIM_MEMORY_RUNNING_CRITICAL, TRIM_MEMORY_RUNNING_LOW, TRIM_MEMORY_RUNNING_MODERATE, TRIM_MEMORY_UI_HIDDEN |
Constructor Summary | |
---|---|
SpiceService()
Default constructor. |
Method Summary | ||
---|---|---|
void |
addRequest(CachedSpiceRequest<?> request,
Set<RequestListener<?>> listRequestListener)
|
|
void |
addSpiceServiceListener(SpiceServiceListener spiceServiceListener)
|
|
abstract CacheManager |
createCacheManager(android.app.Application application)
|
|
android.app.Notification |
createDefaultNotification()
This method can be overriden in order to create a foreground SpiceService. |
|
protected RequestProcessor |
createRequestProcessor(CacheManager cacheManager,
RequestProgressManager requestProgressManager,
RequestRunner requestRunner)
Factory method to create an entity responsible for processing requests send to the SpiceService. |
|
protected RequestProcessorListener |
createRequestProcessorListener()
Creates a SpiceService.SelfStopperRequestProcessorListener for the
RequestProcessor used by this service. |
|
protected RequestListenerNotifier |
createRequestRequestListenerNotifier()
Method to create a Request Progress Reporter object which is responsible for informing the listeners of the current state of each request. |
|
protected SpiceServiceListenerNotifier |
createSpiceServiceListenerNotifier()
Creates the SpiceServiceListenerNotifier. |
|
void |
dontNotifyRequestListenersForRequest(CachedSpiceRequest<?> request,
Collection<RequestListener<?>> listRequestListener)
|
|
void |
dumpState()
|
|
|
getAllCacheKeys(Class<T> clazz)
|
|
int |
getCoreThreadCount()
Override this method to increase the number of core threads used to process requests. |
|
|
getDataFromCache(Class<T> clazz,
Object cacheKey)
|
|
Date |
getDateOfDataInCache(Class<?> clazz,
Object cacheKey)
|
|
protected ExecutorService |
getExecutorService()
Factory method to create an ExecutorService that will be used to
execute requests. |
|
int |
getKeepAliveTime()
Override this method to set the keep alive time for core threads getExecutorService() . |
|
int |
getMaximumThreadCount()
Override this method to increase the number of maximum threads used to process requests. |
|
protected NetworkStateChecker |
getNetworkStateChecker()
Factory method to create an entity responsible to check for network state. |
|
protected int |
getNotificationId()
|
|
protected RequestProcessor |
getRequestProcessor()
For testing purposes only. |
|
int |
getThreadCount()
Override this method to increase the number of threads used to process requests. |
|
int |
getThreadPriority()
Override this method to change the priority of threads requests. |
|
boolean |
isCoreThreadDisposable()
Override this method to disable timeout on core threads. |
|
boolean |
isCreated()
|
|
boolean |
isDataInCache(Class<?> clazz,
Object cacheKey,
long cacheExpiryDuration)
|
|
boolean |
isFailOnCacheError()
|
|
|
loadAllDataFromCache(Class<T> clazz)
|
|
android.os.IBinder |
onBind(android.content.Intent intent)
|
|
void |
onCreate()
|
|
void |
onDestroy()
|
|
void |
onRebind(android.content.Intent intent)
|
|
int |
onStartCommand(android.content.Intent intent,
int flags,
int startId)
|
|
boolean |
onUnbind(android.content.Intent intent)
|
|
|
putDataInCache(Object cacheKey,
T data)
|
|
void |
removeAllDataFromCache()
|
|
void |
removeAllDataFromCache(Class<?> clazz)
|
|
boolean |
removeDataFromCache(Class<?> clazz,
Object cacheKey)
|
|
void |
removeSpiceServiceListener(SpiceServiceListener spiceServiceListener)
|
|
void |
setFailOnCacheError(boolean failOnCacheError)
|
|
static void |
setIsJunit(boolean b)
|
Methods inherited from class android.app.Service |
---|
dump, getApplication, onConfigurationChanged, onLowMemory, onStart, onTaskRemoved, onTrimMemory, startForeground, stopForeground, stopSelf, stopSelf, stopSelfResult |
Methods inherited from class android.content.ContextWrapper |
---|
attachBaseContext, bindService, checkCallingOrSelfPermission, checkCallingOrSelfUriPermission, checkCallingPermission, checkCallingUriPermission, checkPermission, checkUriPermission, checkUriPermission, clearWallpaper, createPackageContext, databaseList, deleteDatabase, deleteFile, enforceCallingOrSelfPermission, enforceCallingOrSelfUriPermission, enforceCallingPermission, enforceCallingUriPermission, enforcePermission, enforceUriPermission, enforceUriPermission, fileList, getApplicationContext, getApplicationInfo, getAssets, getBaseContext, getCacheDir, getClassLoader, getContentResolver, getDatabasePath, getDir, getExternalCacheDir, getExternalFilesDir, getFilesDir, getFileStreamPath, getMainLooper, getObbDir, getPackageCodePath, getPackageManager, getPackageName, getPackageResourcePath, getResources, getSharedPreferences, getSystemService, getTheme, getWallpaper, getWallpaperDesiredMinimumHeight, getWallpaperDesiredMinimumWidth, grantUriPermission, isRestricted, openFileInput, openFileOutput, openOrCreateDatabase, openOrCreateDatabase, peekWallpaper, registerReceiver, registerReceiver, removeStickyBroadcast, revokeUriPermission, sendBroadcast, sendBroadcast, sendOrderedBroadcast, sendOrderedBroadcast, sendStickyBroadcast, sendStickyOrderedBroadcast, setTheme, setWallpaper, setWallpaper, startActivities, startActivities, startActivity, startActivity, startInstrumentation, startIntentSender, startIntentSender, startService, stopService, unbindService, unregisterReceiver |
Methods inherited from class android.content.Context |
---|
getString, getString, getText, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, obtainStyledAttributes, registerComponentCallbacks, unregisterComponentCallbacks |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected static final int DEFAULT_NOTIFICATION_ID
protected static final int DEFAULT_THREAD_COUNT
protected static final int DEFAULT_THREAD_PRIORITY
protected static final int DEFAULT_THREAD_KEEP_ALIVE_TIME
Constructor Detail |
---|
public SpiceService()
Method Detail |
---|
public void onCreate()
onCreate
in class android.app.Service
public boolean isCreated()
public int onStartCommand(android.content.Intent intent, int flags, int startId)
onStartCommand
in class android.app.Service
protected RequestProcessor createRequestProcessor(CacheManager cacheManager, RequestProgressManager requestProgressManager, RequestRunner requestRunner)
RequestProcessor
. Override this method if you want to
inject a custom request processor. This feature has been implemented
following a request from Christopher Jenkins.
cacheManager
- the cache manager used by this service.requestProgressManager
- will notify of requests progress.requestRunner
- executes requests.
RequestProcessor
that will be used to process requests.protected RequestProcessorListener createRequestProcessorListener()
SpiceService.SelfStopperRequestProcessorListener
for the
RequestProcessor
used by this service. See a typical
implementation : @see SpiceService.SelfStopperRequestProcessorListener
.
SpiceService.SelfStopperRequestProcessorListener
for the
RequestProcessor
used by this service.protected RequestProcessor getRequestProcessor()
protected RequestListenerNotifier createRequestRequestListenerNotifier()
RequestListenerNotifier
protected NetworkStateChecker getNetworkStateChecker()
DefaultNetworkStateChecker
. Override this method if you want to
inject a custom network state for testing or to adapt to connectivity
changes on the Android. This method is also useful to create non-network
related requests. In that case create a NetworkStateChecker
that
always return true. This feature has been implemented following a request
from Pierre Durand.
NetworkStateChecker
that will be used to determine if
network state allows requests executions.protected ExecutorService getExecutorService()
ExecutorService
that will be used to
execute requests. The default implementation of this method will create a
single threaded or multi-threaded ExecutorService
depending on
the number of threads returned by getThreadCount()
and will
assign them the priority returned by getThreadPriority()
.
If you override this method in your service, you can supply a custom
ExecutorService
.
This feature has been implemented following a request from Riccardo
Ciovati.
ExecutorService
to be used to execute requests .protected SpiceServiceListenerNotifier createSpiceServiceListenerNotifier()
SpiceServiceListenerNotifier
public android.app.Notification createDefaultNotification()
protected int getNotificationId()
public void onDestroy()
onDestroy
in class android.app.Service
public abstract CacheManager createCacheManager(android.app.Application application) throws CacheCreationException
CacheCreationException
public int getThreadCount()
getExecutorService()
.
DEFAULT_THREAD_COUNT
.public int getCoreThreadCount()
getExecutorService()
.
DEFAULT_THREAD_COUNT
.public int getMaximumThreadCount()
getExecutorService()
.
DEFAULT_THREAD_COUNT
.public int getKeepAliveTime()
getExecutorService()
.
TimeUnit.NANOSECONDS
. Defaults to
DEFAULT_THREAD_KEEP_ALIVE_TIME
.public boolean isCoreThreadDisposable()
getExecutorService()
.
public int getThreadPriority()
getExecutorService()
.
DEFAULT_THREAD_PRIORITY
.public void addRequest(CachedSpiceRequest<?> request, Set<RequestListener<?>> listRequestListener)
public boolean removeDataFromCache(Class<?> clazz, Object cacheKey)
public void removeAllDataFromCache(Class<?> clazz)
public <T> List<Object> getAllCacheKeys(Class<T> clazz)
public <T> List<T> loadAllDataFromCache(Class<T> clazz) throws CacheLoadingException, CacheCreationException
CacheLoadingException
CacheCreationException
public <T> T getDataFromCache(Class<T> clazz, Object cacheKey) throws CacheLoadingException, CacheCreationException
CacheLoadingException
CacheCreationException
public <T> T putDataInCache(Object cacheKey, T data) throws CacheSavingException, CacheCreationException
CacheSavingException
CacheCreationException
public boolean isDataInCache(Class<?> clazz, Object cacheKey, long cacheExpiryDuration) throws CacheCreationException
CacheCreationException
public Date getDateOfDataInCache(Class<?> clazz, Object cacheKey) throws CacheLoadingException, CacheCreationException
CacheLoadingException
CacheCreationException
public void removeAllDataFromCache()
public boolean isFailOnCacheError()
public void setFailOnCacheError(boolean failOnCacheError)
public void dontNotifyRequestListenersForRequest(CachedSpiceRequest<?> request, Collection<RequestListener<?>> listRequestListener)
public android.os.IBinder onBind(android.content.Intent intent)
onBind
in class android.app.Service
public void onRebind(android.content.Intent intent)
onRebind
in class android.app.Service
public boolean onUnbind(android.content.Intent intent)
onUnbind
in class android.app.Service
public void dumpState()
public void addSpiceServiceListener(SpiceServiceListener spiceServiceListener)
public void removeSpiceServiceListener(SpiceServiceListener spiceServiceListener)
public static final void setIsJunit(boolean b)
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |